Skip to content

Commit

Permalink
fix: resolve defect #316
Browse files Browse the repository at this point in the history
  • Loading branch information
danobot authored Jan 13, 2024
1 parent 7c0058f commit 8f291cd
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions custom_components/entity_controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"""
Entity controller component for Home Assistant.
Maintainer: Daniel Mason
Version: v9.6.1
Version: v9.6.0
Project Page: https://danielbkr.net/projects/entity-controller/
Documentation: https://github.com/danobot/entity-controller
"""
Expand All @@ -39,6 +39,7 @@
from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.sun import get_astral_event_date
from homeassistant.util import dt
import homeassistant.util.yaml.objects as YamlObjects
import homeassistant.util.uuid as uuid_util
from transitions import Machine
from transitions.extensions import HierarchicalMachine as Machine
Expand Down Expand Up @@ -106,7 +107,7 @@



VERSION = '9.6.1'
VERSION = '9.6.0'


_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -399,6 +400,7 @@ def __init__(self, hass, config, machine):
self.attributes = {}
self.may_update = False
self.model = None
self.context_id = None
self.friendly_name = config.get(CONF_NAME, "Motion Light")
if "friendly_name" in config:
self.friendly_name = config.get("friendly_name")
Expand Down Expand Up @@ -1578,9 +1580,12 @@ def set_context(self, parent: Optional[Context] = None) -> None:
# Unique name per EC instance, but short enough to fit within id length
name_hash = hashlib.sha1(self.name.encode("UTF-8")).hexdigest()[:6]
unique_id = uuid_util.random_uuid_hex()
# ec_324a1b_7b6ca2a12ce2ff21ae4c06ab55
context_id = f"{DOMAIN_SHORT}_{name_hash}_{unique_id}"
# Restrict id length to database field size
context_id = context_id[:CONTEXT_ID_CHARACTER_LIMIT]
self.context_id = context_id
assert len(context_id) == CONTEXT_ID_CHARACTER_LIMIT
# parent_id only exists for a non-None parent
parent_id = parent.id if parent else None
self.context = Context(parent_id=parent_id, id=context_id)
Expand Down Expand Up @@ -1633,21 +1638,32 @@ def add(self, list, config, key=None):
self.add(self.controlEntities, config, CONF_CONTROL_ENTITIES)
"""
if config is not None:
v = []
if key is not None:
if key in config: # must be in separate if statement
v = config[key]
else:
v = config
if type(v) == str:
self.log.debug("add :: Adding config key `%s` to the config list", key)
if config is None:
self.log.debug("Tried to configure %s but supplied config was None" % (key))
return False

list.append(v)
else:
list.extend(v)
v = None
if key is not None:
if key in config: # must be in separate if statement
v = config[key]
else:
self.log.debug("Tried to configure %s but supplied config was None" % (key))
return len(v) > 0
v = config

if type(v) is YamlObjects.NodeStrClass:
self.log.debug("Found string value %s for key %s, now adding to exiting list %s. (Type: %s)", v, key, list, type(v))
list.append(v)
return len(v) > 0
elif type(v) is YamlObjects.NodeListClass:
self.log.debug("Found list value %s for key %s, now adding to exiting list %s. (Type: %s)", v, key, list, type(v))
list.extend(v)
return len(v) > 0
elif v == None:
self.log.debug(f'Config key {key} not provided by user. Skipping.')
return False
else:
self.log.error(f'Cannot determine type of provided config value. Key: {key}, Type: {type(v)}, Value: {str(v)}')
return False

def futurize(self, timet):
""" Returns tomorrows time if time is in the past.
Expand Down

0 comments on commit 8f291cd

Please sign in to comment.