Skip to content

Commit

Permalink
Fix #115
Browse files Browse the repository at this point in the history
  • Loading branch information
slashback100 committed Mar 8, 2024
1 parent 868ee70 commit bcd4b73
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
8 changes: 5 additions & 3 deletions custom_components/presence_simulation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ async def async_expand_entities(entities):

async def handle_presence_simulation(call, restart=False, switch_id=None):
"""Start the presence simulation"""
if call is not None: #if we are here, it is a call of the service, or a restart at the end of a cycle
after_ha_restart=False
if call is not None: #if we are here, it is a call of the service, or a restart at the end of a cycle, or a restore after a HA restart
#get the switch entity
switch_id = call.data.get("switch_id")
#internal = ("internal" in call.data) and call.data.get("internal")
Expand All @@ -121,8 +122,9 @@ async def handle_presence_simulation(call, restart=False, switch_id=None):
await entity.set_restore(call.data.get("restore_states", False))
if "random" in call.data:
await entity.set_random(call.data.get("random", 0))
if "after_ha_restart" in call.data:
after_ha_restart = call.data.get("after_ha_restart", False)
else: #if we are it is a call from the toggle service or from the turn_on action of the switch entity
# or this is a restart and the simulation was launched after a restart of HA
#get the switch entity
entity = hass.data[DOMAIN][SWITCH_PLATFORM][switch_id]
#make sure the initial config of the simulation is used
Expand Down Expand Up @@ -166,7 +168,7 @@ async def handle_presence_simulation(call, restart=False, switch_id=None):
except Exception as e:
_LOGGER.warning("Start datetime could not be set to HA timezone: ", e)
await entity.set_start_datetime(datetime.now())
if entity.restore:
if entity.restore and not after_ha_restart:
service_data = {}
service_data["scene_id"] = switch_id.replace(".", "_")+"_"+RESTORE_SCENE
service_data["snapshot_entities"] = expanded_entities
Expand Down
2 changes: 1 addition & 1 deletion custom_components/presence_simulation/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"documentation": "https://github.com/slashback100/presence_simulation",
"iot_class": "local_polling",
"issue_tracker": "https://github.com/slashback100/presence_simulation/issues",
"version": "4.3"
"version": "4.4"
}
4 changes: 2 additions & 2 deletions custom_components/presence_simulation/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ def internal_turn_off(self, **kwargs):
self._next_events = []
self.async_write_ha_state()

async def turn_on_async(self, **kwargs):
async def turn_on_async(self, after_ha_restart=False, **kwargs):
"""Turn on the presence simulation"""
_LOGGER.debug("Turn on of the presence simulation through the switch")
await self.hass.services.async_call(DOMAIN, "start", {"switch_id": self.id, "internal": True})
await self.hass.services.async_call(DOMAIN, "start", {"switch_id": self.id, "internal": True, "after_ha_restart": after_ha_restart})

def turn_on(self, **kwargs):
"""Turn on the presence simulation"""
Expand Down

0 comments on commit bcd4b73

Please sign in to comment.