Use entity class attributes for automation (#52694)

* Use entity class attributes for automation

* tweak
This commit is contained in:
Robert Hillis 2021-07-13 09:01:43 -04:00 committed by GitHub
parent e563dc0d7b
commit 55b0d562ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -272,6 +272,8 @@ async def async_setup(hass, config):
class AutomationEntity(ToggleEntity, RestoreEntity): class AutomationEntity(ToggleEntity, RestoreEntity):
"""Entity to show status of entity.""" """Entity to show status of entity."""
_attr_should_poll = False
def __init__( def __init__(
self, self,
automation_id, automation_id,
@ -287,8 +289,7 @@ class AutomationEntity(ToggleEntity, RestoreEntity):
trace_config, trace_config,
): ):
"""Initialize an automation entity.""" """Initialize an automation entity."""
self._id = automation_id self._attr_name = name
self._name = name
self._trigger_config = trigger_config self._trigger_config = trigger_config
self._async_detach_triggers = None self._async_detach_triggers = None
self._cond_func = cond_func self._cond_func = cond_func
@ -304,21 +305,7 @@ class AutomationEntity(ToggleEntity, RestoreEntity):
self._raw_config = raw_config self._raw_config = raw_config
self._blueprint_inputs = blueprint_inputs self._blueprint_inputs = blueprint_inputs
self._trace_config = trace_config self._trace_config = trace_config
self._attr_unique_id = automation_id
@property
def name(self):
"""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."""
return False
@property @property
def extra_state_attributes(self): def extra_state_attributes(self):
@ -330,8 +317,8 @@ class AutomationEntity(ToggleEntity, RestoreEntity):
} }
if self.action_script.supports_max: if self.action_script.supports_max:
attrs[ATTR_MAX] = self.action_script.max_runs attrs[ATTR_MAX] = self.action_script.max_runs
if self._id is not None: if self.unique_id is not None:
attrs[CONF_ID] = self._id attrs[CONF_ID] = self.unique_id
return attrs return attrs
@property @property
@ -496,7 +483,7 @@ class AutomationEntity(ToggleEntity, RestoreEntity):
self.async_set_context(trigger_context) self.async_set_context(trigger_context)
event_data = { event_data = {
ATTR_NAME: self._name, ATTR_NAME: self.name,
ATTR_ENTITY_ID: self.entity_id, ATTR_ENTITY_ID: self.entity_id,
} }
if "trigger" in variables and "description" in variables["trigger"]: if "trigger" in variables and "description" in variables["trigger"]:
@ -580,7 +567,7 @@ class AutomationEntity(ToggleEntity, RestoreEntity):
"""Set up the triggers.""" """Set up the triggers."""
def log_cb(level, msg, **kwargs): def log_cb(level, msg, **kwargs):
self._logger.log(level, "%s %s", msg, self._name, **kwargs) self._logger.log(level, "%s %s", msg, self.name, **kwargs)
variables = None variables = None
if self._trigger_variables: if self._trigger_variables:
@ -597,7 +584,7 @@ class AutomationEntity(ToggleEntity, RestoreEntity):
self._trigger_config, self._trigger_config,
self.async_trigger, self.async_trigger,
DOMAIN, DOMAIN,
self._name, str(self.name),
log_cb, log_cb,
home_assistant_start, home_assistant_start,
variables, variables,