diff --git a/custom_components/oasis_mini/button.py b/custom_components/oasis_mini/button.py index 8b0850d..66e370a 100644 --- a/custom_components/oasis_mini/button.py +++ b/custom_components/oasis_mini/button.py @@ -58,7 +58,7 @@ DESCRIPTORS = ( ), OasisMiniButtonEntityDescription( key="random_track", - name="Play random track", + translation_key="random_track", press_fn=play_random_track, ), ) diff --git a/custom_components/oasis_mini/icons.json b/custom_components/oasis_mini/icons.json new file mode 100644 index 0000000..086749f --- /dev/null +++ b/custom_components/oasis_mini/icons.json @@ -0,0 +1,45 @@ +{ + "entity": { + "binary_sensor": { + "wifi_status": { + "default": "mdi:wifi", + "state": { + "off": "mdi:wifi-off" + } + } + }, + "sensor": { + "download_progress": { + "default": "mdi:progress-download" + }, + "drawing_progress": { + "default": "mdi:progress-pencil" + }, + "error": { + "default": "mdi:alert-circle-outline", + "state": { + "0": "mdi:circle-outline" + } + }, + "status": { + "state": { + "booting": "mdi:loading", + "centering": "mdi:record-circle-outline", + "downloading": "mdi:progress-download", + "error": "mdi:alert-circle-outline", + "live": "mdi:pencil-circle-outline", + "paused": "mdi:motion-pause-outline", + "playing": "mdi:motion-play-outline", + "stopped": "mdi:stop-circle-outline", + "updating": "mdi:update" + } + }, + "wifi_connected": { + "default": "mdi:wifi", + "state": { + "off": "mdi:wifi-off" + } + } + } + } +} diff --git a/custom_components/oasis_mini/light.py b/custom_components/oasis_mini/light.py index f984af5..e2b7759 100644 --- a/custom_components/oasis_mini/light.py +++ b/custom_components/oasis_mini/light.py @@ -106,7 +106,7 @@ class OasisMiniLightEntity(OasisMiniEntity, LightEntity): await self.coordinator.async_request_refresh() -DESCRIPTOR = LightEntityDescription(key="led", name="LED") +DESCRIPTOR = LightEntityDescription(key="led", translation_key="led") async def async_setup_entry( diff --git a/custom_components/oasis_mini/media_player.py b/custom_components/oasis_mini/media_player.py index f3a5437..cc9628b 100644 --- a/custom_components/oasis_mini/media_player.py +++ b/custom_components/oasis_mini/media_player.py @@ -165,11 +165,17 @@ class OasisMiniMediaPlayerEntity(OasisMiniEntity, MediaPlayerEntity): """Play a piece of media.""" self.abort_if_busy() if media_type == MediaType.PLAYLIST: - raise ServiceValidationError("Playlists are not currently supported") + raise ServiceValidationError( + translation_domain=DOMAIN, translation_key="playlists_unsupported" + ) else: track = list(filter(None, map(get_track_id, media_id.split(",")))) if not track: - raise ServiceValidationError(f"Invalid media: {media_id}") + raise ServiceValidationError( + translation_domain=DOMAIN, + translation_key="invalid_media", + translation_placeholders={"media": media_id}, + ) device = self.device enqueue = MediaPlayerEnqueue.NEXT if not enqueue else enqueue diff --git a/custom_components/oasis_mini/number.py b/custom_components/oasis_mini/number.py index 7c60b3c..96ab3af 100644 --- a/custom_components/oasis_mini/number.py +++ b/custom_components/oasis_mini/number.py @@ -35,14 +35,14 @@ class OasisMiniNumberEntity(OasisMiniEntity, NumberEntity): DESCRIPTORS = { NumberEntityDescription( key="ball_speed", - name="Ball speed", + translation_key="ball_speed", mode=NumberMode.SLIDER, native_max_value=BALL_SPEED_MAX, native_min_value=BALL_SPEED_MIN, ), NumberEntityDescription( key="led_speed", - name="LED speed", + translation_key="led_speed", mode=NumberMode.SLIDER, native_max_value=LED_SPEED_MAX, native_min_value=LED_SPEED_MIN, diff --git a/custom_components/oasis_mini/select.py b/custom_components/oasis_mini/select.py index b760089..5ca59e8 100644 --- a/custom_components/oasis_mini/select.py +++ b/custom_components/oasis_mini/select.py @@ -85,20 +85,20 @@ def playlist_update_handler(entity: OasisMiniSelectEntity) -> None: DESCRIPTORS = ( - OasisMiniSelectEntityDescription( - key="playlist", - name="Playlist", - current_value=lambda device: (device.playlist.copy(), device.playlist_index), - select_fn=lambda device, option: device.async_change_track(option), - update_handler=playlist_update_handler, - ), OasisMiniSelectEntityDescription( key="autoplay", - name="Autoplay", + translation_key="autoplay", options=list(AUTOPLAY_MAP.values()), current_value=lambda device: device.autoplay, select_fn=lambda device, option: device.async_set_autoplay(option), ), + OasisMiniSelectEntityDescription( + key="playlist", + translation_key="playlist", + current_value=lambda device: (device.playlist.copy(), device.playlist_index), + select_fn=lambda device, option: device.async_change_track(option), + update_handler=playlist_update_handler, + ), ) diff --git a/custom_components/oasis_mini/sensor.py b/custom_components/oasis_mini/sensor.py index 9dd43a2..62f3183 100644 --- a/custom_components/oasis_mini/sensor.py +++ b/custom_components/oasis_mini/sensor.py @@ -39,16 +39,15 @@ async def async_setup_entry( DESCRIPTORS = { SensorEntityDescription( key="download_progress", + translation_key="download_progress", entity_category=EntityCategory.DIAGNOSTIC, entity_registry_enabled_default=False, - name="Download progress", native_unit_of_measurement=PERCENTAGE, state_class=SensorStateClass.MEASUREMENT, ), } | { SensorEntityDescription( key=key, - name=key.replace("_", " ").capitalize(), translation_key=key, entity_category=EntityCategory.DIAGNOSTIC, entity_registry_enabled_default=False, @@ -65,8 +64,8 @@ DESCRIPTORS = { CLOUD_DESCRIPTORS = ( SensorEntityDescription( key="drawing_progress", + translation_key="drawing_progress", entity_category=EntityCategory.DIAGNOSTIC, - name="Drawing progress", native_unit_of_measurement=PERCENTAGE, state_class=SensorStateClass.MEASUREMENT, suggested_display_precision=1, diff --git a/custom_components/oasis_mini/strings.json b/custom_components/oasis_mini/strings.json index 73576f6..72bec6e 100755 --- a/custom_components/oasis_mini/strings.json +++ b/custom_components/oasis_mini/strings.json @@ -38,7 +38,53 @@ } }, "entity": { + "button": { + "random_track": { + "name": "Play random track" + } + }, + "binary_sensor": { + "busy": { + "name": "Busy" + }, + "wifi_status": { + "name": "Wi-Fi status" + } + }, + "light": { + "led": { + "name": "LED" + } + }, + "number": { + "ball_speed": { + "name": "Ball speed" + }, + "led_speed": { + "name": "LED speed" + } + }, + "select": { + "autoplay": { + "name": "Autoplay" + }, + "playlist": { + "name": "Playlist" + } + }, "sensor": { + "download_progress": { + "name": "Download progress" + }, + "drawing_progress": { + "name": "Drawing progress" + }, + "error": { + "name": "Error" + }, + "led_color_id": { + "name": "LED color ID" + }, "status": { "name": "Status", "state": { @@ -54,5 +100,16 @@ } } } + }, + "exceptions": { + "device_busy": { + "message": "{name} is currently busy and cannot be modified" + }, + "invalid_media": { + "message": "Invalid media: {media}" + }, + "playlists_unsupported": { + "message": "Playlists are not currently supported" + } } } diff --git a/custom_components/oasis_mini/translations/en.json b/custom_components/oasis_mini/translations/en.json index a233920..b5bdd2c 100755 --- a/custom_components/oasis_mini/translations/en.json +++ b/custom_components/oasis_mini/translations/en.json @@ -38,7 +38,53 @@ } }, "entity": { + "button": { + "random_track": { + "name": "Play random track" + } + }, + "binary_sensor": { + "busy": { + "name": "Busy" + }, + "wifi_status": { + "name": "Wi-Fi status" + } + }, + "light": { + "led": { + "name": "LED" + } + }, + "number": { + "ball_speed": { + "name": "Ball speed" + }, + "led_speed": { + "name": "LED speed" + } + }, + "select": { + "autoplay": { + "name": "Autoplay" + }, + "playlist": { + "name": "Playlist" + } + }, "sensor": { + "download_progress": { + "name": "Download progress" + }, + "drawing_progress": { + "name": "Drawing progress" + }, + "error": { + "name": "Error" + }, + "led_color_id": { + "name": "LED color ID" + }, "status": { "name": "Status", "state": { @@ -54,5 +100,16 @@ } } } + }, + "exceptions": { + "device_busy": { + "message": "{name} is currently busy and cannot be modified" + }, + "invalid_media": { + "message": "Invalid media: {media}" + }, + "playlists_unsupported": { + "message": "Playlists are not currently supported" + } } }