Skip to content

Commit

Permalink
Merge branch 'alandtse:dev' into add-restore_volume-service
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbrunt57 authored Dec 26, 2024
2 parents 4d9755c + c107046 commit bef2492
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
6 changes: 4 additions & 2 deletions custom_components/alexa_media/alexa_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ def is_alexa_guard(appliance: dict[str, Any]) -> bool:

def is_temperature_sensor(appliance: dict[str, Any]) -> bool:
"""Is the given appliance the temperature sensor of an Echo."""
return is_local(appliance) and has_capability(
appliance, "Alexa.TemperatureSensor", "temperature"
return (
is_local(appliance)
and has_capability(appliance, "Alexa.TemperatureSensor", "temperature")
and appliance["friendlyDescription"] != "Amazon Indoor Air Quality Monitor"
)


Expand Down
9 changes: 9 additions & 0 deletions custom_components/alexa_media/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,15 @@ async def async_step_init(
if CONF_PUBLIC_URL in self._config_entry.data:
if not user_input[CONF_PUBLIC_URL].endswith("/"):
user_input[CONF_PUBLIC_URL] = user_input[CONF_PUBLIC_URL] + "/"
"""Remove leading/trailing spaces in device strings"""
if CONF_INCLUDE_DEVICES in self._config_entry.data:
user_input[CONF_INCLUDE_DEVICES] = user_input[
CONF_INCLUDE_DEVICES
].strip()
if CONF_EXCLUDE_DEVICES in self._config_entry.data:
user_input[CONF_EXCLUDE_DEVICES] = user_input[
CONF_EXCLUDE_DEVICES
].strip()

self.hass.config_entries.async_update_entry(
self._config_entry, data=user_input, options=self._config_entry.options
Expand Down
2 changes: 1 addition & 1 deletion custom_components/alexa_media/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
PERCENTAGE,
)

__version__ = "5.1.0"
__version__ = "5.2.0"
PROJECT_URL = "https://github.com/alandtse/alexa_media_player/"
ISSUE_URL = f"{PROJECT_URL}issues"
NOTIFY_URL = f"{PROJECT_URL}wiki/Configuration%3A-Notification-Component#use-the-notifyalexa_media-service"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/alexa_media/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"issue_tracker": "https://github.com/alandtse/alexa_media_player/issues",
"loggers": ["alexapy", "authcaptureproxy"],
"requirements": ["alexapy==1.29.5", "packaging>=20.3", "wrapt>=1.14.0"],
"version": "5.1.0"
"version": "5.2.0"
}
19 changes: 15 additions & 4 deletions custom_components/alexa_media/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def __init__(self, device, login, second_account_index=0):
self._media_is_muted = None
self._media_vol_level = None
self._previous_volume = None
self._saved_volume = None
self._source = None
self._source_list = []
self._connected_bluetooth = None
Expand Down Expand Up @@ -1129,14 +1130,23 @@ async def async_set_volume_level(self, volume):
"""Set volume level, range 0..1."""
if not self.available:
return

# Save the current volume level before we change it
_LOGGER.debug("Saving previous volume level: %s", self.volume_level)
self._previous_volume = self.volume_level

# Change the volume level on the device
if self.hass:
self.hass.async_create_task(self.alexa_api.set_volume(volume))
else:
await self.alexa_api.set_volume(volume)
self._media_vol_level = volume

# Let http2push update the new volume level
if not (
self.hass.data[DATA_ALEXAMEDIA]["accounts"][self._login.email]["http2"]
):
# Otherwise we do it ourselves
await self.async_update()

@property
Expand Down Expand Up @@ -1164,19 +1174,19 @@ async def async_mute_volume(self, mute):

self._media_is_muted = mute
if mute:
self._previous_volume = self.volume_level
self._saved_volume = self.volume_level
if self.hass:
self.hass.async_create_task(self.alexa_api.set_volume(0))
else:
await self.alexa_api.set_volume(0)
else:
if self._previous_volume is not None:
if self._saved_volume is not None:
if self.hass:
self.hass.async_create_task(
self.alexa_api.set_volume(self._previous_volume)
self.alexa_api.set_volume(self._saved_volume)
)
else:
await self.alexa_api.set_volume(self._previous_volume)
await self.alexa_api.set_volume(self._saved_volume)
else:
if self.hass:
self.hass.async_create_task(self.alexa_api.set_volume(50))
Expand Down Expand Up @@ -1620,6 +1630,7 @@ def extra_state_attributes(self):
"last_called_summary": self._last_called_summary,
"connected_bluetooth": self._connected_bluetooth,
"bluetooth_list": self._bluetooth_list,
"previous_volume": self._previous_volume,
}
return attr

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "alexa_media_player"
version = "5.1.0"
version = "5.2.0"
description = "This is a custom component to allow control of Amazon Alexa devices in [Homeassistant](https://home-assistant.io) using the unofficial Alexa API."
authors = [
"Keaton Taylor <keatonstaylor@gmail.com>",
Expand Down

0 comments on commit bef2492

Please sign in to comment.