Add unique IDs to automation/scenes (#31150)

* Add unique IDs to automation and scenes

* Fix typo
This commit is contained in:
Paulus Schoutsen authored and GitHub committed 2020-01-26 23:01:35 -08:00
1 parent 8fff6462a1
commit 1f0f62de7f
14 files changed
+123 -27

No files matched your search

@@ -189,6 +189,11 @@ class AutomationEntity(ToggleEntity, RestoreEntity):
"""Name of the automation."""
return self._name
@property
def unique_id(self):
"""Return unique ID."""
return self._id
@property
def should_poll(self):
"""No polling needed for automation entities."""
+6 -2
View File
@@ -28,6 +28,8 @@ SECTIONS = (
"scene",
)
ON_DEMAND = ("zwave",)
ACTION_CREATE_UPDATE = "create_update"
ACTION_DELETE = "delete"
async def async_setup(hass, config):
@@ -152,7 +154,9 @@ class BaseEditConfigView(HomeAssistantView):
await hass.async_add_executor_job(_write, path, current)
if self.post_write_hook is not None:
hass.async_create_task(self.post_write_hook(hass))
hass.async_create_task(
self.post_write_hook(ACTION_CREATE_UPDATE, config_key)
)
return self.json({"result": "ok"})
@@ -170,7 +174,7 @@ class BaseEditConfigView(HomeAssistantView):
await hass.async_add_executor_job(_write, path, current)
if self.post_write_hook is not None:
hass.async_create_task(self.post_write_hook(hass))
hass.async_create_task(self.post_write_hook(ACTION_DELETE, config_key))
return self.json({"result": "ok"})
+15 -3
View File
@@ -6,18 +6,30 @@ from homeassistant.components.automation import DOMAIN, PLATFORM_SCHEMA
from homeassistant.components.automation.config import async_validate_config_item
from homeassistant.config import AUTOMATION_CONFIG_PATH
from homeassistant.const import CONF_ID, SERVICE_RELOAD
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers import config_validation as cv, entity_registry
from . import EditIdBasedConfigView
from . import ACTION_DELETE, EditIdBasedConfigView
async def async_setup(hass):
"""Set up the Automation config API."""
async def hook(hass):
async def hook(action, config_key):
"""post_write_hook for Config View that reloads automations."""
await hass.services.async_call(DOMAIN, SERVICE_RELOAD)
if action != ACTION_DELETE:
return
ent_reg = await entity_registry.async_get_registry(hass)
entity_id = ent_reg.async_get_entity_id(DOMAIN, DOMAIN, config_key)
if entity_id is None:
return
ent_reg.async_remove(entity_id)
hass.http.register_view(
EditAutomationConfigView(
DOMAIN,
+1 -1
View File
@@ -12,7 +12,7 @@ CONFIG_PATH = "customize.yaml"
async def async_setup(hass):
"""Set up the Customize config API."""
async def hook(hass):
async def hook(action, config_key):
"""post_write_hook for Config View that reloads groups."""
await hass.services.async_call(DOMAIN, SERVICE_RELOAD_CORE_CONFIG)
+1 -1
View File
@@ -10,7 +10,7 @@ from . import EditKeyBasedConfigView
async def async_setup(hass):
"""Set up the Group config API."""
async def hook(hass):
async def hook(action, config_key):
"""post_write_hook for Config View that reloads groups."""
await hass.services.async_call(DOMAIN, SERVICE_RELOAD)
+16 -3
View File
@@ -5,18 +5,31 @@ import uuid
from homeassistant.components.scene import DOMAIN, PLATFORM_SCHEMA
from homeassistant.config import SCENE_CONFIG_PATH
from homeassistant.const import CONF_ID, SERVICE_RELOAD
import homeassistant.helpers.config_validation as cv
from homeassistant.core import DOMAIN as HA_DOMAIN
from homeassistant.helpers import config_validation as cv, entity_registry
from . import EditIdBasedConfigView
from . import ACTION_DELETE, EditIdBasedConfigView
async def async_setup(hass):
"""Set up the Scene config API."""
async def hook(hass):
async def hook(action, config_key):
"""post_write_hook for Config View that reloads scenes."""
await hass.services.async_call(DOMAIN, SERVICE_RELOAD)
if action != ACTION_DELETE:
return
ent_reg = await entity_registry.async_get_registry(hass)
entity_id = ent_reg.async_get_entity_id(DOMAIN, HA_DOMAIN, config_key)
if entity_id is None:
return
ent_reg.async_remove(entity_id)
hass.http.register_view(
EditSceneConfigView(
DOMAIN,
+1 -1
View File
@@ -10,7 +10,7 @@ from . import EditKeyBasedConfigView
async def async_setup(hass):
"""Set up the script config API."""
async def hook(hass):
async def hook(action, config_key):
"""post_write_hook for Config View that reloads scripts."""
await hass.services.async_call(DOMAIN, SERVICE_RELOAD)
@@ -261,6 +261,11 @@ class HomeAssistantScene(Scene):
"""Return the name of the scene."""
return self.scene_config.name
@property
def unique_id(self):
"""Return unique ID."""
return self._id
@property
def device_state_attributes(self):
"""Return the scene state attributes."""
+1 -4
View File
@@ -61,10 +61,7 @@ async def async_setup(hass, config):
await component.async_setup(config)
# Ensure Home Assistant platform always loaded.
await component.async_setup_platform(
HA_DOMAIN, {"platform": "homeasistant", STATES: []}
)
await component.async_setup_platform(HA_DOMAIN, {"platform": HA_DOMAIN, STATES: []})
component.async_register_entity_service(SERVICE_TURN_ON, {}, "async_activate")
return True