SmartObject now create its linked entity with create_entity
This commit is contained in:
1 parent
97501875b8
commit
bf72dbb223
1 file changed
+11
-10
+11
-10
@@ -113,12 +113,11 @@ class SmartObject(hass.Hass,LoggerInterface):
|
||||
if device_class is not None: attributes['device_class'] = device_class
|
||||
if state_class is not None: attributes['state_class'] = state_class
|
||||
|
||||
if state is not None:
|
||||
entity.set_state(state=state, attributes=attributes, check_existence=False)
|
||||
else:
|
||||
if not entity.exists():
|
||||
entity.set_state(state='unknown', check_existence=False)
|
||||
entity.set_state(attributes=attributes)
|
||||
if state is None:
|
||||
state = entity.get_state() if entity.exists() else None
|
||||
if state is None:
|
||||
state = 'unknown'
|
||||
entity.set_state(state=state, attributes=attributes, check_existence=False)
|
||||
|
||||
return entity
|
||||
|
||||
@@ -219,14 +218,16 @@ class SmartObject(hass.Hass,LoggerInterface):
|
||||
# entity: <entity_id> → link app to a HA entity
|
||||
if "entity" in self.args:
|
||||
self.entity_id = self.args["entity"]
|
||||
self.entity = self.get_entity(self.entity_id)
|
||||
self.entity = self.get_entity(self.entity_id, check_existence=False)
|
||||
initial_state = None
|
||||
if self.entity.exists():
|
||||
self.log_info(f"Linked to {self.entity_id}")
|
||||
elif 'default_entity_state' in self.args:
|
||||
self.entity.set_state(state = self.args["default_entity_state"])
|
||||
self.log_info(f"Creating {self.entity_id}, default_state = {self.args['default_entity_state']}")
|
||||
initial_state = self.args["default_entity_state"]
|
||||
self.log_info(f"Creating {self.entity_id}, default_state = {initial_state}")
|
||||
else:
|
||||
self.entity.set_state(state = self.get_default_entity_state())
|
||||
initial_state = self.get_default_entity_state()
|
||||
self.entity = self.create_entity(self.entity_id, state=initial_state)
|
||||
|
||||
self.constants['self'] = self.entity_id
|
||||
else:
|
||||
|
||||
Reference in new issue
Block a user