From de027609d8696a15ff57ee3f13b3868ec63f058e Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 28 Oct 2015 12:27:58 +0100 Subject: [PATCH 1/3] Fixed entity_id for the script component. Alias now does not override the entity_id Fixed issue: #561 --- homeassistant/components/script.py | 5 +++-- homeassistant/helpers/entity_component.py | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/script.py b/homeassistant/components/script.py index 3f892fdfa80..e5bfe61bfa5 100644 --- a/homeassistant/components/script.py +++ b/homeassistant/components/script.py @@ -75,7 +75,7 @@ def setup(hass, config): _LOGGER.warn("Missing key 'sequence' for script %s", name) continue alias = cfg.get(CONF_ALIAS, name) - script = Script(hass, alias, cfg[CONF_SEQUENCE]) + script = Script(hass, alias, name, cfg[CONF_SEQUENCE]) component.add_entities((script,)) _, object_id = split_entity_id(script.entity_id) hass.services.register(DOMAIN, object_id, service_handler) @@ -100,9 +100,10 @@ def setup(hass, config): class Script(ToggleEntity): """ Represents a script. """ - def __init__(self, hass, name, sequence): + def __init__(self, hass, name, entity_id, sequence): self.hass = hass self._name = name + self.entity_id = entity_id self.sequence = sequence self._lock = threading.Lock() self._cur = -1 diff --git a/homeassistant/helpers/entity_component.py b/homeassistant/helpers/entity_component.py index 708bf6e93a9..5223b7f0ca3 100644 --- a/homeassistant/helpers/entity_component.py +++ b/homeassistant/helpers/entity_component.py @@ -65,8 +65,10 @@ class EntityComponent(object): if entity is not None and entity not in self.entities.values(): entity.hass = self.hass - entity.entity_id = generate_entity_id( - self.entity_id_format, entity.name, self.entities.keys()) + if entity.entity_id is None: + entity.entity_id = generate_entity_id( + self.entity_id_format, entity.name, + self.entities.keys()) self.entities[entity.entity_id] = entity From 48bfc98acb45b0114ad7c004fc1aaa69ad823ab4 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 28 Oct 2015 19:52:09 +0100 Subject: [PATCH 2/3] Fixed entity name --- homeassistant/components/script.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/script.py b/homeassistant/components/script.py index e5bfe61bfa5..9849a243a41 100644 --- a/homeassistant/components/script.py +++ b/homeassistant/components/script.py @@ -75,7 +75,8 @@ def setup(hass, config): _LOGGER.warn("Missing key 'sequence' for script %s", name) continue alias = cfg.get(CONF_ALIAS, name) - script = Script(hass, alias, name, cfg[CONF_SEQUENCE]) + entity_id = "{}.{}".format(DOMAIN, name) + script = Script(hass, alias, entity_id, cfg[CONF_SEQUENCE]) component.add_entities((script,)) _, object_id = split_entity_id(script.entity_id) hass.services.register(DOMAIN, object_id, service_handler) From 10c95b435250ccc7b754aa726153413238026ad7 Mon Sep 17 00:00:00 2001 From: Stefan Jonasson Date: Wed, 28 Oct 2015 20:17:17 +0100 Subject: [PATCH 3/3] Added pylint hint --- homeassistant/components/script.py | 1 + 1 file changed, 1 insertion(+) diff --git a/homeassistant/components/script.py b/homeassistant/components/script.py index 9849a243a41..084f5502426 100644 --- a/homeassistant/components/script.py +++ b/homeassistant/components/script.py @@ -99,6 +99,7 @@ def setup(hass, config): return True +# pylint: disable=too-many-instance-attributes class Script(ToggleEntity): """ Represents a script. """ def __init__(self, hass, name, entity_id, sequence):