Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

Commit be74ee5

Browse files
authored
Fix for Queuing Delay value reset on reboot
Fix for Queuing Delay value reset on reboot
1 parent 8bf8cac commit be74ee5

File tree

1 file changed

+15
-2
lines changed
  • custom_components/music_assistant_jukebox

1 file changed

+15
-2
lines changed

custom_components/music_assistant_jukebox/number.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from homeassistant.config_entries import ConfigEntry
99
from homeassistant.core import HomeAssistant
1010
from homeassistant.helpers.entity_platform import AddEntitiesCallback
11+
from homeassistant.helpers import state as state_helper
12+
from homeassistant.helpers.restore_state import RestoreEntity
1113

1214
from .const import DOMAIN, LOGGER
1315
from .switch import JukeboxBaseMixin
@@ -47,7 +49,7 @@ async def async_set_native_value(self, value: float) -> None:
4749
self._attr_native_value = int(value)
4850
self.async_write_ha_state()
4951

50-
class QueueDelayNumber(JukeboxBaseMixin, NumberEntity):
52+
class QueueDelayNumber(JukeboxBaseMixin, RestoreEntity, NumberEntity):
5153
"""Number entity for queueing delay in seconds."""
5254

5355
_attr_has_entity_name = True
@@ -66,7 +68,18 @@ def __init__(self, hass: HomeAssistant, entry: ConfigEntry) -> None:
6668
self.entry = entry
6769
self._attr_native_value = 0
6870

71+
async def async_added_to_hass(self):
72+
"""Restore last known value from state history."""
73+
await super().async_added_to_hass()
74+
last_state = await self.async_get_last_state()
75+
if last_state and last_state.state not in (None, "unknown", "unavailable"):
76+
try:
77+
self._attr_native_value = int(float(last_state.state))
78+
self.async_write_ha_state()
79+
except Exception:
80+
pass
81+
6982
async def async_set_native_value(self, value: float) -> None:
7083
"""Update the current value."""
7184
self._attr_native_value = int(value)
72-
self.async_write_ha_state()
85+
self.async_write_ha_state()

0 commit comments

Comments
 (0)