Skip to content

Commit

Permalink
Fix restore after restart for 2023.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
slashback100 committed Apr 7, 2023
1 parent 4db23d0 commit 881615a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
8 changes: 4 additions & 4 deletions custom_components/presence_simulation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import homeassistant.util.dt as dt_util
from homeassistant.const import EVENT_HOMEASSISTANT_START
try:
from homeassistant.components.recorder.db_schema import States, StateAttributes
from homeassistant.components.recorder.db_schema import States, StateAttributes, StatesMeta
except ImportError:
from homeassistant.components.recorder.models import States, StateAttributes
from homeassistant.components.recorder.const import DATA_INSTANCE
Expand Down Expand Up @@ -191,7 +191,7 @@ async def handle_presence_simulation(call, restart=False, entities_after_restart
# as running, but the necessary attributes aren't set correctly.
entity.internal_turn_on()
_LOGGER.debug("Presence simulation started")

if not restart:
#set attribute on the switch
try:
Expand Down Expand Up @@ -418,8 +418,8 @@ def _restore_state_sync(previous_attribute):
_LOGGER.debug("In restore State Sync")

session = hass.data[DATA_INSTANCE].get_session()
result = session.query(States.state, StateAttributes.shared_attrs).filter(States.attributes_id == StateAttributes.attributes_id).filter(States.entity_id == SWITCH_PLATFORM+"."+SWITCH).order_by(States.last_updated_ts.desc()).limit(1)
result = session.query(States.state, StateAttributes.shared_attrs).join(StatesMeta).filter(States.attributes_id == StateAttributes.attributes_id).filter(States.metadata_id == StatesMeta.metadata_id).filter(StatesMeta.entity_id == SWITCH_PLATFORM+"."+SWITCH).order_by(States.last_updated_ts.desc()).limit(1)

# result[0] is a tuple of (state, attributes-json)
if result.count() > 0 and result[0][0] == "on":
previous_attribute["was_running"] = True
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": "2.5"
"version": "3.0"
}
3 changes: 2 additions & 1 deletion hacs.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "Presence Simulation",
"render_readme": true
"render_readme": true,
"homeassistant": "2023.4.0"
}

0 comments on commit 881615a

Please sign in to comment.