Skip to content

Commit b01c009

Browse files
committed
better argument names
1 parent 3ddb4f4 commit b01c009

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

custom_components/pyscript/entity_manager.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ def register_platform(cls, platform, adder, entity_class):
3131
cls.registered_entities[platform] = {}
3232

3333
@classmethod
34-
async def get(cls, ast_ctx, platform, name):
34+
async def get(cls, ast_ctx, platform, unique_id):
3535
"""Get an Entity from pyscript"""
3636
await cls.wait_platform_registered(platform)
37-
if platform not in cls.registered_entities or name not in cls.registered_entities[platform]:
38-
await cls.create(ast_ctx, platform, name)
37+
if platform not in cls.registered_entities or unique_id not in cls.registered_entities[platform]:
38+
await cls.create(ast_ctx, platform, unique_id)
3939

40-
return cls.registered_entities[platform][name]
40+
return cls.registered_entities[platform][unique_id]
4141

4242
@classmethod
43-
async def create(cls, ast_ctx, platform, name):
43+
async def create(cls, ast_ctx, platform, unique_id):
4444
"""Create entity from pyscript."""
4545
await cls.wait_platform_registered(platform)
46-
new_entity = cls.platform_classes[platform](cls.hass, ast_ctx, name)
46+
new_entity = cls.platform_classes[platform](cls.hass, ast_ctx, unique_id)
4747
cls.platform_adders[platform]([new_entity])
48-
cls.registered_entities[platform][name] = new_entity
48+
cls.registered_entities[platform][unique_id] = new_entity
4949

5050
@classmethod
5151
async def wait_platform_registered(cls, platform):
@@ -76,6 +76,9 @@ def __init__(self, hass, ast_ctx, unique_id):
7676
self._unique_id,
7777
)
7878

79+
# USED BY HOME ASSISTANT
80+
####################################
81+
7982
@property
8083
def state(self):
8184
"""Return the state of the sensor."""
@@ -110,6 +113,14 @@ async def async_added_to_hass(self):
110113
"""Called when Home Assistant adds the entity to the registry"""
111114
self._added = True
112115
await self.async_update()
116+
_LOGGER.debug(
117+
"Entity %s Added to Hass as %s",
118+
self._unique_id,
119+
self.entity_id,
120+
)
121+
122+
# USED INTERNALLY
123+
#####################################
113124

114125
async def async_update(self):
115126
"""Request an entity update from Home Assistant"""
@@ -148,8 +159,9 @@ async def set(self, state=None, new_attributes=None, **kwargs):
148159
self.set_attribute(attribute_name, kwargs[attribute_name])
149160

150161
_LOGGER.debug(
151-
"%s state is now %s (%s)",
162+
"%s (%s) state is now %s (%s)",
152163
self._unique_id,
164+
self.entity_id,
153165
self._state,
154166
self._attributes,
155167
)

0 commit comments

Comments
 (0)