Refactor reproduce_state for scene component
* Add tests to reach full coverage for helpers/state.py. * Refactor reproduce_state function in helpers/state.py. Add two dicts, as global constants, service_attributes and service_to_state. Use these in combination with the dict of services per domain from ServiceRegistry, to find the correct service to use in a scene state change. * Use break statement in for loop, to break if service was selected to update state, in preference to update state attributes, ie state update takes precedence. * Add ATTR_CODE and ATTR_CODE_FORMAT in const. Import these in alarm_control_panel and lock platforms instead of making duplicate constants in multiple modules. * Use ATTR_MEDIA_CONTENT_TYPE and ATTR_MEDIA_CONTENT_ID in media_player platform in SERVICE_PLAY_MEDIA and play_media methods, instead of 'media_type' and 'media_id'. * Fix PEP257 in modified files.
This commit is contained in:
parent
f22a40c3e8
commit
c56701baaf
10 changed files with 247 additions and 97 deletions
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Allows users to set and activate scenes.
|
||||
Allow users to set and activate scenes.
|
||||
|
||||
For more details about this component, please refer to the documentation at
|
||||
https://home-assistant.io/components/scene/
|
||||
|
@ -20,7 +20,6 @@ CONF_ENTITIES = "entities"
|
|||
SceneConfig = namedtuple('SceneConfig', ['name', 'states'])
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Setup home assistant scene entries."""
|
||||
scene_config = config.get("states")
|
||||
|
@ -83,5 +82,5 @@ class HomeAssistantScene(Scene):
|
|||
}
|
||||
|
||||
def activate(self):
|
||||
"""Activate scene. Tries to get entities into requested state."""
|
||||
"""Activate scene. Try to get entities into requested state."""
|
||||
reproduce_state(self.hass, self.scene_config.states.values(), True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue