Skip to content

Commit

Permalink
fix: swap "async_write_ha_state" with "schedule_update_ha_state" (#2280)
Browse files Browse the repository at this point in the history
closes #2256
  • Loading branch information
tb-killa authored Jun 8, 2024
1 parent f191c54 commit 88d3871
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion custom_components/alexa_media/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ async def _set_state(self, power_on, brightness=None, kelvin=None, hs_color=None
self._requested_state_at = datetime.datetime.now(
datetime.timezone.utc
) # must be set last so that previous getters work properly
self.async_write_ha_state()
self.schedule_update_ha_state()

async def async_turn_on(self, **kwargs):
"""Turn on."""
Expand Down
28 changes: 14 additions & 14 deletions custom_components/alexa_media/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ async def _refresh_if_no_audiopush(already_refreshed=False):
return
if event_serial == self.device_serial_number:
self._available = True
self.async_write_ha_state()
self.schedule_update_ha_state()
if "last_called_change" in event:
if (
event_serial == self.device_serial_number
Expand All @@ -409,8 +409,8 @@ async def _refresh_if_no_audiopush(already_refreshed=False):
self._last_called = True
self._last_called_timestamp = event["last_called_change"]["timestamp"]
self._last_called_summary = event["last_called_change"].get("summary")
if self.hass and self.async_write_ha_state:
self.async_write_ha_state()
if self.hass and self.schedule_update_ha_state:
self.schedule_update_ha_state()
await self._update_notify_targets()
else:
self._last_called = False
Expand All @@ -437,8 +437,8 @@ async def _refresh_if_no_audiopush(already_refreshed=False):
self._source_list = self._get_source_list()
self._connected_bluetooth = self._get_connected_bluetooth()
self._bluetooth_list = self._get_bluetooth_list()
if self.hass and self.async_write_ha_state:
self.async_write_ha_state()
if self.hass and self.schedule_update_ha_state:
self.schedule_update_ha_state()
elif "player_state" in event:
player_state = event["player_state"]
if event_serial == self.device_serial_number:
Expand Down Expand Up @@ -470,12 +470,12 @@ async def _refresh_if_no_audiopush(already_refreshed=False):
player_state["volumeSetting"],
)
self._media_vol_level = player_state["volumeSetting"] / 100
if self.hass and self.async_write_ha_state:
self.async_write_ha_state()
if self.hass and self.schedule_update_ha_state:
self.schedule_update_ha_state()
elif "dopplerConnectionState" in player_state:
self.available = player_state["dopplerConnectionState"] == "ONLINE"
if self.hass and self.async_write_ha_state:
self.async_write_ha_state()
if self.hass and self.schedule_update_ha_state:
self.schedule_update_ha_state()
await _refresh_if_no_audiopush(already_refreshed)
elif "push_activity" in event:
if self.state in {MediaPlayerState.IDLE, MediaPlayerState.PAUSED, MediaPlayerState.PLAYING}:
Expand Down Expand Up @@ -592,7 +592,7 @@ async def refresh(self, device=None, skip_api: bool = False):
]["last_called"].get("summary")
await self._update_notify_targets()
if skip_api and self.hass:
self.async_write_ha_state()
self.schedule_update_ha_state()
return
if "MUSIC_SKILL" in self._capabilities:
if self._parent_clusters and self.hass:
Expand Down Expand Up @@ -734,7 +734,7 @@ async def refresh(self, device=None, skip_api: bool = False):
)
)
if self.hass:
self.async_write_ha_state()
self.schedule_update_ha_state()

@property
def source(self):
Expand Down Expand Up @@ -989,7 +989,7 @@ async def async_update(self):
self.name,
)
self._last_update = util.utcnow()
self.async_write_ha_state()
self.schedule_update_ha_state()

@property
def media_content_type(self):
Expand Down Expand Up @@ -1074,7 +1074,7 @@ def shuffle(self):
def shuffle(self, state):
"""Set the Shuffle state."""
self._shuffle = state
self.async_write_ha_state()
self.schedule_update_ha_state()

@property
def repeat_state(self):
Expand All @@ -1085,7 +1085,7 @@ def repeat_state(self):
def repeat_state(self, state):
"""Set the Repeat state."""
self._repeat = state
self.async_write_ha_state()
self.schedule_update_ha_state()

@property
def supported_features(self):
Expand Down
2 changes: 1 addition & 1 deletion custom_components/alexa_media/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ async def async_update(self):
self._n_dict = None
self._process_raw_notifications()
try:
self.async_write_ha_state()
self.schedule_update_ha_state()
except NoEntitySpecifiedError:
pass # we ignore this due to a harmless startup race condition

Expand Down
12 changes: 6 additions & 6 deletions custom_components/alexa_media/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _handle_event(self, event):
if "queue_state" in event:
queue_state = event["queue_state"]
if queue_state["dopplerId"]["deviceSerialNumber"] == self._client.unique_id:
self.async_write_ha_state()
self.schedule_update_ha_state()

@_catch_login_errors
async def _set_switch(self, state, **kwargs):
Expand All @@ -233,7 +233,7 @@ async def _set_switch(self, state, **kwargs):
self.name,
getattr(self._client, self._switch_property),
)
self.async_write_ha_state()
self.schedule_update_ha_state()
elif self.should_poll:
# if we need to poll, refresh media_client
_LOGGER.debug(
Expand Down Expand Up @@ -304,7 +304,7 @@ async def async_update(self):
except AttributeError:
pass
try:
self.async_write_ha_state()
self.schedule_update_ha_state()
except NoEntitySpecifiedError:
pass # we ignore this due to a harmless startup race condition

Expand Down Expand Up @@ -368,7 +368,7 @@ def _handle_event(self, event):
if state != self.is_on:
_LOGGER.debug("Detected %s changed to %s", self, state)
setattr(self._client, self._switch_property, state)
self.async_write_ha_state()
self.schedule_update_ha_state()


class ShuffleSwitch(AlexaMediaSwitch):
Expand Down Expand Up @@ -467,12 +467,12 @@ async def _set_state(self, power_on):
self._requested_state_at = datetime.datetime.now(
datetime.timezone.utc
) # must be set last so that previous getters work properly
self.async_write_ha_state()
self.schedule_update_ha_state()

async def async_turn_on(self, **kwargs):
"""Turn on."""
await self._set_state(True)

async def async_turn_off(self, **kwargs): # pylint:disable=unused-argument
"""Turn off."""
await self._set_state(False)
await self._set_state(False)

0 comments on commit 88d3871

Please sign in to comment.