Skip to content

Commit

Permalink
style: auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Oct 2, 2024
1 parent 7025624 commit 1e9bedb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
24 changes: 19 additions & 5 deletions custom_components/alexa_media/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,34 @@ def report_relogin_required(hass, login, email) -> bool:
def _existing_serials(hass, login_obj) -> list:
"""Retrieve existing serial numbers for a given login object."""
email: str = login_obj.email
if DATA_ALEXAMEDIA in hass.data and "accounts" in hass.data[DATA_ALEXAMEDIA] and email in hass.data[DATA_ALEXAMEDIA]["accounts"]:
if (
DATA_ALEXAMEDIA in hass.data
and "accounts" in hass.data[DATA_ALEXAMEDIA]
and email in hass.data[DATA_ALEXAMEDIA]["accounts"]
):
existing_serials = list(
hass.data[DATA_ALEXAMEDIA]["accounts"][email]["entities"]["media_player"].keys()
hass.data[DATA_ALEXAMEDIA]["accounts"][email]["entities"][
"media_player"
].keys()
)
device_data = (
hass.data[DATA_ALEXAMEDIA]["accounts"][email]
.get("devices", {})
.get("media_player", {})
)
device_data = hass.data[DATA_ALEXAMEDIA]["accounts"][email].get("devices", {}).get("media_player", {})
for serial in existing_serials:
device = device_data.get(serial, {})
if "appDeviceList" in device and device["appDeviceList"]:
apps = [
x["serialNumber"] for x in device["appDeviceList"] if "serialNumber" in x
x["serialNumber"]
for x in device["appDeviceList"]
if "serialNumber" in x
]
existing_serials.extend(apps)
else:
_LOGGER.warning("No accounts data found for %s. Skipping serials retrieval.", email)
_LOGGER.warning(
"No accounts data found for %s. Skipping serials retrieval.", email
)
existing_serials = []
return existing_serials

Expand Down
16 changes: 9 additions & 7 deletions custom_components/alexa_media/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ async def async_update(self):
except AttributeError:
pass
email = self._login.email

# Check if DATA_ALEXAMEDIA and 'accounts' exist
accounts_data = self.hass.data.get(DATA_ALEXAMEDIA, {}).get("accounts", {})
if (
Expand All @@ -937,9 +937,11 @@ async def async_update(self):
self._assumed_state = True
self.available = False
return

# Safely access the device
device = accounts_data[email]["devices"]["media_player"].get(self.device_serial_number)
device = accounts_data[email]["devices"]["media_player"].get(
self.device_serial_number
)
if not device:
_LOGGER.warning(
"Device serial number %s not found for account %s. Skipping update.",
Expand All @@ -948,19 +950,19 @@ async def async_update(self):
)
self.available = False
return

# Safely access websocket_commands
seen_commands = (
accounts_data[email]["websocket_commands"].keys()
if "websocket_commands" in accounts_data[email]
else None
)

await self.refresh(device, no_throttle=True)

# Safely access 'http2' setting
push_enabled = accounts_data[email].get("http2")

if (
self.state in [MediaPlayerState.PLAYING]
and
Expand Down

0 comments on commit 1e9bedb

Please sign in to comment.