@@ -31,21 +31,21 @@ def register_platform(cls, platform, adder, entity_class):
31
31
cls .registered_entities [platform ] = {}
32
32
33
33
@classmethod
34
- async def get (cls , ast_ctx , platform , name ):
34
+ async def get (cls , ast_ctx , platform , unique_id ):
35
35
"""Get an Entity from pyscript"""
36
36
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 )
39
39
40
- return cls .registered_entities [platform ][name ]
40
+ return cls .registered_entities [platform ][unique_id ]
41
41
42
42
@classmethod
43
- async def create (cls , ast_ctx , platform , name ):
43
+ async def create (cls , ast_ctx , platform , unique_id ):
44
44
"""Create entity from pyscript."""
45
45
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 )
47
47
cls .platform_adders [platform ]([new_entity ])
48
- cls .registered_entities [platform ][name ] = new_entity
48
+ cls .registered_entities [platform ][unique_id ] = new_entity
49
49
50
50
@classmethod
51
51
async def wait_platform_registered (cls , platform ):
@@ -76,6 +76,9 @@ def __init__(self, hass, ast_ctx, unique_id):
76
76
self ._unique_id ,
77
77
)
78
78
79
+ # USED BY HOME ASSISTANT
80
+ ####################################
81
+
79
82
@property
80
83
def state (self ):
81
84
"""Return the state of the sensor."""
@@ -110,6 +113,14 @@ async def async_added_to_hass(self):
110
113
"""Called when Home Assistant adds the entity to the registry"""
111
114
self ._added = True
112
115
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
+ #####################################
113
124
114
125
async def async_update (self ):
115
126
"""Request an entity update from Home Assistant"""
@@ -148,8 +159,9 @@ async def set(self, state=None, new_attributes=None, **kwargs):
148
159
self .set_attribute (attribute_name , kwargs [attribute_name ])
149
160
150
161
_LOGGER .debug (
151
- "%s state is now %s (%s)" ,
162
+ "%s (%s) state is now %s (%s)" ,
152
163
self ._unique_id ,
164
+ self .entity_id ,
153
165
self ._state ,
154
166
self ._attributes ,
155
167
)
0 commit comments