|
39 | 39 | from homeassistant.helpers.entity_component import EntityComponent
|
40 | 40 | from homeassistant.helpers.sun import get_astral_event_date
|
41 | 41 | from homeassistant.util import dt
|
| 42 | +import homeassistant.util.yaml.objects as YamlObjects |
42 | 43 | import homeassistant.util.uuid as uuid_util
|
43 | 44 | from transitions import Machine
|
44 | 45 | from transitions.extensions import HierarchicalMachine as Machine
|
@@ -399,6 +400,7 @@ def __init__(self, hass, config, machine):
|
399 | 400 | self.attributes = {}
|
400 | 401 | self.may_update = False
|
401 | 402 | self.model = None
|
| 403 | + self.context_id = None |
402 | 404 | self.friendly_name = config.get(CONF_NAME, "Motion Light")
|
403 | 405 | if "friendly_name" in config:
|
404 | 406 | self.friendly_name = config.get("friendly_name")
|
@@ -1577,10 +1579,13 @@ def set_context(self, parent: Optional[Context] = None) -> None:
|
1577 | 1579 | """
|
1578 | 1580 | # Unique name per EC instance, but short enough to fit within id length
|
1579 | 1581 | name_hash = hashlib.sha1(self.name.encode("UTF-8")).hexdigest()[:6]
|
| 1582 | + self.log.debug("set_context :: name_hash: %s", name_hash) |
1580 | 1583 | unique_id = uuid_util.random_uuid_hex()
|
1581 |
| - context_id = f"{DOMAIN_SHORT}_{name_hash}_{unique_id}" |
| 1584 | + |
1582 | 1585 | # Restrict id length to database field size
|
1583 |
| - context_id = context_id[:CONTEXT_ID_CHARACTER_LIMIT] |
| 1586 | + context_id = f"{DOMAIN_SHORT}_{name_hash}_{unique_id}"[:CONTEXT_ID_CHARACTER_LIMIT] |
| 1587 | + self.log.debug("set_context :: context_id: %s", context_id) |
| 1588 | + self.context_id = context_id |
1584 | 1589 | # parent_id only exists for a non-None parent
|
1585 | 1590 | parent_id = parent.id if parent else None
|
1586 | 1591 | self.context = Context(parent_id=parent_id, id=context_id)
|
@@ -1633,21 +1638,32 @@ def add(self, list, config, key=None):
|
1633 | 1638 | self.add(self.controlEntities, config, CONF_CONTROL_ENTITIES)
|
1634 | 1639 |
|
1635 | 1640 | """
|
1636 |
| - if config is not None: |
1637 |
| - v = [] |
1638 |
| - if key is not None: |
1639 |
| - if key in config: # must be in separate if statement |
1640 |
| - v = config[key] |
1641 |
| - else: |
1642 |
| - v = config |
1643 |
| - if type(v) == str: |
| 1641 | + self.log.debug("add :: Adding config key `%s` to the config list", key) |
| 1642 | + if config is None: |
| 1643 | + self.log.debug("Tried to configure %s but supplied config was None" % (key)) |
| 1644 | + return False |
1644 | 1645 |
|
1645 |
| - list.append(v) |
1646 |
| - else: |
1647 |
| - list.extend(v) |
| 1646 | + v = None |
| 1647 | + if key is not None: |
| 1648 | + if key in config: # must be in separate if statement |
| 1649 | + v = config[key] |
1648 | 1650 | else:
|
1649 |
| - self.log.debug("Tried to configure %s but supplied config was None" % (key)) |
1650 |
| - return len(v) > 0 |
| 1651 | + v = config |
| 1652 | + |
| 1653 | + if type(v) is YamlObjects.NodeStrClass: |
| 1654 | + self.log.debug("Found string value %s for key %s, now adding to exiting list %s. (Type: %s)", v, key, list, type(v)) |
| 1655 | + list.append(v) |
| 1656 | + return len(v) > 0 |
| 1657 | + elif type(v) is YamlObjects.NodeListClass: |
| 1658 | + self.log.debug("Found list value %s for key %s, now adding to exiting list %s. (Type: %s)", v, key, list, type(v)) |
| 1659 | + list.extend(v) |
| 1660 | + return len(v) > 0 |
| 1661 | + elif v == None: |
| 1662 | + self.log.debug(f'Config key {key} not provided by user. Skipping.') |
| 1663 | + return False |
| 1664 | + else: |
| 1665 | + self.log.error(f'Cannot determine type of provided config value. Key: {key}, Type: {type(v)}, Value: {str(v)}') |
| 1666 | + return False |
1651 | 1667 |
|
1652 | 1668 | def futurize(self, timet):
|
1653 | 1669 | """ Returns tomorrows time if time is in the past.
|
|
0 commit comments