diff --git a/custom_components/casatunes/__init__.py b/custom_components/casatunes/__init__.py index 6b7d015..b76ae11 100644 --- a/custom_components/casatunes/__init__.py +++ b/custom_components/casatunes/__init__.py @@ -130,7 +130,10 @@ class CasaTunesDeviceEntity(CasaTunesEntity): @property def device_info(self) -> DeviceInfo: - """Return device information about this CasaTunes instance.""" + """Return device information about this CasaTunes device.""" + if self._device_id is None: + return None + return { "identifiers": {(DOMAIN, self._device_id)}, "manufacturer": "CasaTunes", diff --git a/custom_components/casatunes/const.py b/custom_components/casatunes/const.py index 9a395e8..3e17706 100644 --- a/custom_components/casatunes/const.py +++ b/custom_components/casatunes/const.py @@ -1,2 +1,8 @@ """Constants for the CasaTunes integration.""" DOMAIN = "casatunes" + +# Attributes +ATTR_KEYWORD = "keyword" + +# Services +SERVICE_SEARCH = "search" \ No newline at end of file diff --git a/custom_components/casatunes/manifest.json b/custom_components/casatunes/manifest.json index 254bf3f..d890cf3 100644 --- a/custom_components/casatunes/manifest.json +++ b/custom_components/casatunes/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://github.com/jonkristian/casatunes", "issue_tracker": "https://github.com/jonkristian/casatunes/issues", - "version": "0.1.1", + "version": "0.1.2", "requirements": [ "pycasatunes==0.1.1" ], diff --git a/custom_components/casatunes/media_player.py b/custom_components/casatunes/media_player.py index 3816463..646e129 100644 --- a/custom_components/casatunes/media_player.py +++ b/custom_components/casatunes/media_player.py @@ -3,6 +3,8 @@ import logging +import voluptuous as vol + from homeassistant.util.dt import utcnow from homeassistant.helpers.update_coordinator import DataUpdateCoordinator @@ -43,8 +45,9 @@ STATE_PLAYING, ) from homeassistant.helpers.entity import Entity +from homeassistant.helpers import entity_platform -from .const import DOMAIN +from .const import ATTR_KEYWORD, DOMAIN, SERVICE_SEARCH from .browse_media import build_item_response from . import CasaTunesDataUpdateCoordinator, CasaTunesDeviceEntity @@ -69,6 +72,8 @@ STATUS_TO_STATES = {0: STATE_IDLE, 1: STATE_PAUSED, 2: STATE_PLAYING, 3: STATE_ON} +SEARCH_SCHEMA = {vol.Required(ATTR_KEYWORD): str} + _LOGGER = logging.getLogger(__name__) @@ -85,6 +90,13 @@ async def async_setup_entry(hass, entry, async_add_entities): async_add_entities(media_players) + platform = entity_platform.async_get_current_platform() + platform.async_register_entity_service( + SERVICE_SEARCH, + SEARCH_SCHEMA, + "search", + ) + class CasaTunesMediaPlayer(CasaTunesDeviceEntity, MediaPlayerEntity): """Representation of a CasaTunes media player on the network.""" @@ -168,7 +180,7 @@ def name(self) -> str | None: @property def state(self) -> str | None: """Return the state of the device.""" - if self.zone and self.zone.Power is not False: + if self.zone.Power is True: state = self.coordinator.data.nowplaying[self.zone.SourceID].Status return STATUS_TO_STATES.get(state, None) else: @@ -420,4 +432,8 @@ async def async_play_media(self, media_type, media_id, **kwargs): async def async_clear_playlist(self): """Send the media player the command for clear playlist.""" - await self._player.async_clear_playlist() \ No newline at end of file + await self._player.async_clear_playlist() + + async def search(self, keyword): + """Emulate opening the search screen and entering the search keyword.""" + await self.coordinator.data.search_media(self.zone_id, keyword) \ No newline at end of file diff --git a/custom_components/casatunes/services.yaml b/custom_components/casatunes/services.yaml new file mode 100644 index 0000000..d6dd720 --- /dev/null +++ b/custom_components/casatunes/services.yaml @@ -0,0 +1,15 @@ +search: + name: Search + description: Emulates opening the search screen and entering the search keyword. + target: + entity: + integration: casatunes + domain: media_player + fields: + keyword: + name: Keyword + description: The keyword to search for. + required: true + example: "Pearl Jam" + selector: + text: