Add mode info attributes to script and automation (#37815)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
1 parent
ac0dbb17af
commit
7d77fa92c2
8 files changed
+53
-80
No files matched your search
@@ -24,6 +24,9 @@ from homeassistant.helpers.config_validation import make_entity_service_schema
|
||||
from homeassistant.helpers.entity import ToggleEntity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.script import (
|
||||
ATTR_CUR,
|
||||
ATTR_MAX,
|
||||
ATTR_MODE,
|
||||
CONF_MAX,
|
||||
SCRIPT_MODE_SINGLE,
|
||||
Script,
|
||||
@@ -35,7 +38,7 @@ from homeassistant.loader import bind_hass
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DOMAIN = "script"
|
||||
ATTR_CAN_CANCEL = "can_cancel"
|
||||
|
||||
ATTR_LAST_ACTION = "last_action"
|
||||
ATTR_LAST_TRIGGERED = "last_triggered"
|
||||
ATTR_VARIABLES = "variables"
|
||||
@@ -272,9 +275,14 @@ class ScriptEntity(ToggleEntity):
|
||||
@property
|
||||
def state_attributes(self):
|
||||
"""Return the state attributes."""
|
||||
attrs = {ATTR_LAST_TRIGGERED: self.script.last_triggered}
|
||||
if self.script.can_cancel:
|
||||
attrs[ATTR_CAN_CANCEL] = self.script.can_cancel
|
||||
attrs = {
|
||||
ATTR_LAST_TRIGGERED: self.script.last_triggered,
|
||||
ATTR_MODE: self.script.script_mode,
|
||||
}
|
||||
if self.script.supports_max:
|
||||
attrs[ATTR_MAX] = self.script.max_runs
|
||||
if self.is_on:
|
||||
attrs[ATTR_CUR] = self.script.runs
|
||||
if self.script.last_action:
|
||||
attrs[ATTR_LAST_ACTION] = self.script.last_action
|
||||
return attrs
|
||||
|
||||
Reference in new issue
Block a user