Skip to content

Commit

Permalink
Merge pull request #100 from hchris1/fix-qobuz-album-art
Browse files Browse the repository at this point in the history
Fix qobuz album art
  • Loading branch information
hchris1 authored Nov 9, 2024
2 parents 49a3ea2 + 5cd134e commit 7ed0beb
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 49 deletions.
60 changes: 30 additions & 30 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
# The contents of this file is based on https://github.com/home-assistant/core/blob/dev/pyproject.toml

target-version = "py311"
target-version = "py312"

lint.select = [
"B007", # Loop control variable {name} not used within loop body
"B014", # Exception handler with duplicate exception
"C", # complexity
"D", # docstrings
"E", # pycodestyle
"F", # pyflakes/autoflake
"ICN001", # import concentions; {name} should be imported as {asname}
"B007", # Loop control variable {name} not used within loop body
"B014", # Exception handler with duplicate exception
"C", # complexity
"D", # docstrings
"E", # pycodestyle
"F", # pyflakes/autoflake
"ICN001", # import concentions; {name} should be imported as {asname}
"PGH004", # Use specific rule codes when using noqa
"PLC0414", # Useless import alias. Import alias does not rename original package.
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
"SIM117", # Merge with-statements that use the same scope
"SIM118", # Use {key} in {dict} instead of {key} in {dict}.keys()
"SIM201", # Use {left} != {right} instead of not {left} == {right}
"SIM212", # Use {a} if {a} else {b} instead of {b} if not {a} else {a}
"SIM300", # Yoda conditions. Use 'age == 42' instead of '42 == age'.
"SIM401", # Use get from dict with default instead of an if block
"T20", # flake8-print
"TRY004", # Prefer TypeError exception for invalid type
"RUF006", # Store a reference to the return value of asyncio.create_task
"UP", # pyupgrade
"W", # pycodestyle
"SIM105", # Use contextlib.suppress({exception}) instead of try-except-pass
"SIM117", # Merge with-statements that use the same scope
"SIM118", # Use {key} in {dict} instead of {key} in {dict}.keys()
"SIM201", # Use {left} != {right} instead of not {left} == {right}
"SIM212", # Use {a} if {a} else {b} instead of {b} if not {a} else {a}
"SIM300", # Yoda conditions. Use 'age == 42' instead of '42 == age'.
"SIM401", # Use get from dict with default instead of an if block
"T20", # flake8-print
"TRY004", # Prefer TypeError exception for invalid type
"RUF006", # Store a reference to the return value of asyncio.create_task
"UP", # pyupgrade
"W", # pycodestyle
]

lint.ignore = [
"D202", # No blank lines allowed after function docstring
"D203", # 1 blank line required before class docstring
"D213", # Multi-line docstring summary should start at the second line
"D404", # First word of the docstring should not be This
"D406", # Section name should end with a newline
"D407", # Section name underlining
"D411", # Missing blank line before section
"E501", # line too long
"E731", # do not assign a lambda expression, use a def
"D202", # No blank lines allowed after function docstring
"D203", # 1 blank line required before class docstring
"D213", # Multi-line docstring summary should start at the second line
"D404", # First word of the docstring should not be This
"D406", # Section name should end with a newline
"D407", # Section name underlining
"D411", # Missing blank line before section
"E501", # line too long
"E731", # do not assign a lambda expression, use a def
]

[lint.flake8-pytest-style]
Expand All @@ -45,4 +45,4 @@ fixture-parentheses = false
keep-runtime-typing = true

[lint.mccabe]
max-complexity = 25
max-complexity = 25
2 changes: 1 addition & 1 deletion custom_components/eversolo/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

NAME = "Eversolo"
DOMAIN = "eversolo"
VERSION = "0.1.0"
VERSION = "0.4.1"
ATTRIBUTION = ""

DEFAULT_PORT = 9529
Expand Down
54 changes: 38 additions & 16 deletions custom_components/eversolo/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def __init__(self, coordinator: EversoloDataUpdateCoordinator, config_entry):
super().__init__(coordinator)
self._attr_device_class = MediaPlayerDeviceClass.RECEIVER
self._attr_supported_features = SUPPORT_FEATURES
self._attr_unique_id = f"{coordinator.config_entry.entry_id}_media_player"
self._attr_unique_id = f"{
coordinator.config_entry.entry_id}_media_player"
self._config_entry = config_entry
self._name = "Eversolo"
self._state = None
Expand All @@ -56,7 +57,8 @@ def name(self):
@property
def state(self):
"""Return Media Player state."""
music_control_state = self.coordinator.data.get("music_control_state", None)
music_control_state = self.coordinator.data.get(
"music_control_state", None)

if music_control_state is None:
self._state = None
Expand Down Expand Up @@ -85,15 +87,17 @@ def device_info(self):
@property
def volume_level(self):
"""Volume level of the Media Player in range 0..1."""
music_control_state = self.coordinator.data.get("music_control_state", None)
music_control_state = self.coordinator.data.get(
"music_control_state", None)

if music_control_state is None:
return None

current_volume = music_control_state.get("volumeData", {}).get(
"currenttVolume", None
)
max_volume = music_control_state.get("volumeData", {}).get("maxVolume", None)
max_volume = music_control_state.get(
"volumeData", {}).get("maxVolume", None)

if current_volume is None or max_volume is None:
LOGGER.debug(
Expand All @@ -107,7 +111,8 @@ def volume_level(self):
@property
def is_volume_muted(self):
"""Return muted state."""
music_control_state = self.coordinator.data.get("music_control_state", None)
music_control_state = self.coordinator.data.get(
"music_control_state", None)

if music_control_state is None:
return None
Expand All @@ -117,7 +122,8 @@ def is_volume_muted(self):
@property
def source(self):
"""Return the current input source."""
input_output_state = self.coordinator.data.get("input_output_state", None)
input_output_state = self.coordinator.data.get(
"input_output_state", None)

if input_output_state is None:
return None
Expand Down Expand Up @@ -152,7 +158,8 @@ def source_list(self):
@property
def media_title(self):
"""Title of current playing media."""
music_control_state = self.coordinator.data.get("music_control_state", None)
music_control_state = self.coordinator.data.get(
"music_control_state", None)

if music_control_state is None:
return None
Expand All @@ -176,7 +183,8 @@ def media_title(self):
@property
def media_artist(self):
"""Artist of current playing media."""
music_control_state = self.coordinator.data.get("music_control_state", None)
music_control_state = self.coordinator.data.get(
"music_control_state", None)

if music_control_state is None:
return None
Expand All @@ -200,7 +208,8 @@ def media_artist(self):
@property
def media_album_name(self):
"""Album of current playing media."""
music_control_state = self.coordinator.data.get("music_control_state", None)
music_control_state = self.coordinator.data.get(
"music_control_state", None)

if music_control_state is None:
return None
Expand All @@ -224,7 +233,8 @@ def media_album_name(self):
@property
def media_image_url(self):
"""Image url of current playing media."""
music_control_state = self.coordinator.data.get("music_control_state", None)
music_control_state = self.coordinator.data.get(
"music_control_state", None)

if music_control_state is None:
return None
Expand All @@ -241,13 +251,21 @@ def media_image_url(self):
return None

if not album_url.startswith("http"):
album_url = self.coordinator.client.create_image_url_by_path(album_url)
album_url = self.coordinator.client.create_image_url_by_path(
album_url)

return album_url

# Internal Player
if play_type == 5:
song_id = music_control_state.get("playingMusic", {}).get("id", None)
album_art = music_control_state.get(
"playingMusic", {}).get("albumArt", None)

if album_art:
return album_art

song_id = music_control_state.get(
"playingMusic", {}).get("id", None)
if song_id is not None:
return self.coordinator.client.create_image_url_by_song_id(song_id)

Expand All @@ -256,7 +274,8 @@ def media_image_url(self):
@property
def media_duration(self):
"""Duration of current playing media in seconds."""
music_control_state = self.coordinator.data.get("music_control_state", None)
music_control_state = self.coordinator.data.get(
"music_control_state", None)

if music_control_state is None:
return None
Expand All @@ -271,7 +290,8 @@ def media_duration(self):
@property
def media_position(self):
"""Position of current playing media in seconds."""
music_control_state = self.coordinator.data.get("music_control_state", None)
music_control_state = self.coordinator.data.get(
"music_control_state", None)

if music_control_state is None:
return None
Expand All @@ -295,13 +315,15 @@ async def async_turn_off(self):

async def async_set_volume_level(self, volume: float) -> None:
"""Set volume level, range 0..1."""
music_control_state = self.coordinator.data.get("music_control_state", None)
music_control_state = self.coordinator.data.get(
"music_control_state", None)

if music_control_state is None:
return

converted_volume = round(
volume * int(music_control_state.get("volumeData", {}).get("maxVolume", 0))
volume * int(music_control_state.get("volumeData",
{}).get("maxVolume", 0))
)
await self.coordinator.client.async_set_volume(converted_volume)
await self.coordinator.async_request_refresh()
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Eversolo Integration",
"filename": "eversolo.zip",
"hide_default_branch": true,
"homeassistant": "2023.12.3",
"homeassistant": "2024.11.1",
"render_readme": true,
"zip_release": true
}
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
colorlog==6.9.0
homeassistant==2024.2.5
homeassistant==2024.11.1
pip>=21.0,<24.4
ruff==0.7.2

0 comments on commit 7ed0beb

Please sign in to comment.