-
-
Notifications
You must be signed in to change notification settings - Fork 36.3k
Config flow for ONVIF #34520
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Config flow for ONVIF #34520
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
be84d90
config flow for ONVIF
hunterjm fa43c1a
add tests folder
hunterjm aef54b0
initial tests for onvif config flow
hunterjm 94ba42d
finish tests
hunterjm af84724
address pr comments
hunterjm 8349101
fix lint
hunterjm dcb306a
Fix logging
balloob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,86 @@ | ||
| """The onvif component.""" | ||
| """The ONVIF integration.""" | ||
| import asyncio | ||
|
|
||
| import voluptuous as vol | ||
|
|
||
| from homeassistant.components.ffmpeg import CONF_EXTRA_ARGUMENTS | ||
| from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry | ||
| from homeassistant.const import CONF_HOST | ||
| from homeassistant.core import HomeAssistant | ||
| from homeassistant.helpers import config_per_platform | ||
|
|
||
| from .const import ( | ||
| CONF_PROFILE, | ||
| CONF_RTSP_TRANSPORT, | ||
| DEFAULT_ARGUMENTS, | ||
| DEFAULT_PROFILE, | ||
| DOMAIN, | ||
| RTSP_TRANS_PROTOCOLS, | ||
| ) | ||
|
|
||
| CONFIG_SCHEMA = vol.Schema({DOMAIN: vol.Schema({})}, extra=vol.ALLOW_EXTRA) | ||
|
|
||
| PLATFORMS = ["camera"] | ||
|
|
||
|
|
||
| async def async_setup(hass: HomeAssistant, config: dict): | ||
| """Set up the ONVIF component.""" | ||
| # Import from yaml | ||
| configs = {} | ||
| for p_type, p_config in config_per_platform(config, "camera"): | ||
| if p_type != DOMAIN: | ||
| continue | ||
|
|
||
| config = p_config.copy() | ||
| profile = config.get(CONF_PROFILE, DEFAULT_PROFILE) | ||
| if config[CONF_HOST] not in configs.keys(): | ||
| configs[config[CONF_HOST]] = config | ||
| configs[config[CONF_HOST]][CONF_PROFILE] = [profile] | ||
| else: | ||
| configs[config[CONF_HOST]][CONF_PROFILE].append(profile) | ||
|
|
||
| for conf in configs.values(): | ||
| hass.async_create_task( | ||
| hass.config_entries.flow.async_init( | ||
| DOMAIN, context={"source": SOURCE_IMPORT}, data=conf | ||
| ) | ||
| ) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): | ||
| """Set up ONVIF from a config entry.""" | ||
| if not entry.options: | ||
| await async_populate_options(hass, entry) | ||
|
|
||
| for component in PLATFORMS: | ||
| hass.async_create_task( | ||
| hass.config_entries.async_forward_entry_setup(entry, component) | ||
| ) | ||
|
|
||
| return True | ||
|
|
||
|
|
||
| async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): | ||
| """Unload a config entry.""" | ||
| unload_ok = all( | ||
| await asyncio.gather( | ||
| *[ | ||
| hass.config_entries.async_forward_entry_unload(entry, component) | ||
| for component in PLATFORMS | ||
| ] | ||
| ) | ||
| ) | ||
|
|
||
| return unload_ok | ||
|
|
||
|
|
||
| async def async_populate_options(hass, entry): | ||
| """Populate default options for device.""" | ||
| options = { | ||
| CONF_EXTRA_ARGUMENTS: DEFAULT_ARGUMENTS, | ||
| CONF_RTSP_TRANSPORT: RTSP_TRANS_PROTOCOLS[0], | ||
| } | ||
|
|
||
| hass.config_entries.async_update_entry(entry, options=options) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.