mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 00:37:13 +00:00
Add entity translations to Sonos (#96167)
* Add entity translations to Sonos * Add entity translations to Sonos * Add entity translations to Sonos * Add entity translations to Sonos
This commit is contained in:
parent
b77de2abaf
commit
81ce6e4797
@ -58,7 +58,6 @@ class SonosPowerEntity(SonosEntity, BinarySensorEntity):
|
||||
|
||||
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
_attr_device_class = BinarySensorDeviceClass.BATTERY_CHARGING
|
||||
_attr_name = "Power"
|
||||
|
||||
def __init__(self, speaker: SonosSpeaker) -> None:
|
||||
"""Initialize the power entity binary sensor."""
|
||||
@ -92,7 +91,7 @@ class SonosMicrophoneSensorEntity(SonosEntity, BinarySensorEntity):
|
||||
|
||||
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
_attr_icon = "mdi:microphone"
|
||||
_attr_name = "Microphone"
|
||||
_attr_translation_key = "microphone"
|
||||
|
||||
def __init__(self, speaker: SonosSpeaker) -> None:
|
||||
"""Initialize the microphone binary sensor entity."""
|
||||
|
@ -110,7 +110,7 @@ class SonosLevelEntity(SonosEntity, NumberEntity):
|
||||
"""Initialize the level entity."""
|
||||
super().__init__(speaker)
|
||||
self._attr_unique_id = f"{self.soco.uid}-{level_type}"
|
||||
self._attr_name = level_type.replace("_", " ").capitalize()
|
||||
self._attr_translation_key = level_type
|
||||
self.level_type = level_type
|
||||
self._attr_native_min_value, self._attr_native_max_value = valid_range
|
||||
|
||||
|
@ -79,7 +79,6 @@ class SonosBatteryEntity(SonosEntity, SensorEntity):
|
||||
|
||||
_attr_device_class = SensorDeviceClass.BATTERY
|
||||
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
_attr_name = "Battery"
|
||||
_attr_native_unit_of_measurement = PERCENTAGE
|
||||
|
||||
def __init__(self, speaker: SonosSpeaker) -> None:
|
||||
@ -107,7 +106,7 @@ class SonosAudioInputFormatSensorEntity(SonosPollingEntity, SensorEntity):
|
||||
|
||||
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
_attr_icon = "mdi:import"
|
||||
_attr_name = "Audio input format"
|
||||
_attr_translation_key = "audio_input_format"
|
||||
_attr_should_poll = True
|
||||
|
||||
def __init__(self, speaker: SonosSpeaker, audio_format: str) -> None:
|
||||
|
@ -17,6 +17,70 @@
|
||||
"description": "Falling back to polling, functionality may be limited.\n\nSonos device at {device_ip} cannot reach Home Assistant at {listener_address}.\n\nSee our [documentation]({sub_fail_url}) for more information on how to solve this issue."
|
||||
}
|
||||
},
|
||||
"entity": {
|
||||
"binary_sensor": {
|
||||
"microphone": {
|
||||
"name": "Microphone"
|
||||
}
|
||||
},
|
||||
"number": {
|
||||
"audio_delay": {
|
||||
"name": "Audio delay"
|
||||
},
|
||||
"bass": {
|
||||
"name": "Bass"
|
||||
},
|
||||
"balance": {
|
||||
"name": "Balance"
|
||||
},
|
||||
"treble": {
|
||||
"name": "Treble"
|
||||
},
|
||||
"sub_gain": {
|
||||
"name": "Sub gain"
|
||||
},
|
||||
"surround_level": {
|
||||
"name": "Surround level"
|
||||
},
|
||||
"music_surround_level": {
|
||||
"name": "Music surround level"
|
||||
}
|
||||
},
|
||||
"sensor": {
|
||||
"audio_input_format": {
|
||||
"name": "Audio input format"
|
||||
}
|
||||
},
|
||||
"switch": {
|
||||
"cross_fade": {
|
||||
"name": "Crossfade"
|
||||
},
|
||||
"loudness": {
|
||||
"name": "Loudness"
|
||||
},
|
||||
"surround_mode": {
|
||||
"name": "Surround music full volume"
|
||||
},
|
||||
"night_mode": {
|
||||
"name": "Night sound"
|
||||
},
|
||||
"dialog_level": {
|
||||
"name": "Speech enhancement"
|
||||
},
|
||||
"status_light": {
|
||||
"name": "Status light"
|
||||
},
|
||||
"sub_enabled": {
|
||||
"name": "Subwoofer enabled"
|
||||
},
|
||||
"surround_enabled": {
|
||||
"name": "Surround enabled"
|
||||
},
|
||||
"buttons_enabled": {
|
||||
"name": "Touch controls"
|
||||
}
|
||||
}
|
||||
},
|
||||
"services": {
|
||||
"snapshot": {
|
||||
"name": "Snapshot",
|
||||
|
@ -67,18 +67,6 @@ POLL_REQUIRED = (
|
||||
ATTR_STATUS_LIGHT,
|
||||
)
|
||||
|
||||
FRIENDLY_NAMES = {
|
||||
ATTR_CROSSFADE: "Crossfade",
|
||||
ATTR_LOUDNESS: "Loudness",
|
||||
ATTR_MUSIC_PLAYBACK_FULL_VOLUME: "Surround music full volume",
|
||||
ATTR_NIGHT_SOUND: "Night sound",
|
||||
ATTR_SPEECH_ENHANCEMENT: "Speech enhancement",
|
||||
ATTR_STATUS_LIGHT: "Status light",
|
||||
ATTR_SUB_ENABLED: "Subwoofer enabled",
|
||||
ATTR_SURROUND_ENABLED: "Surround enabled",
|
||||
ATTR_TOUCH_CONTROLS: "Touch controls",
|
||||
}
|
||||
|
||||
FEATURE_ICONS = {
|
||||
ATTR_LOUDNESS: "mdi:bullhorn-variant",
|
||||
ATTR_MUSIC_PLAYBACK_FULL_VOLUME: "mdi:music-note-plus",
|
||||
@ -140,7 +128,7 @@ async def async_setup_entry(
|
||||
)
|
||||
_LOGGER.debug(
|
||||
"Creating %s switch on %s",
|
||||
FRIENDLY_NAMES[feature_type],
|
||||
feature_type,
|
||||
speaker.zone_name,
|
||||
)
|
||||
entities.append(SonosSwitchEntity(feature_type, speaker))
|
||||
@ -163,7 +151,7 @@ class SonosSwitchEntity(SonosPollingEntity, SwitchEntity):
|
||||
self.feature_type = feature_type
|
||||
self.needs_coordinator = feature_type in COORDINATOR_FEATURES
|
||||
self._attr_entity_category = EntityCategory.CONFIG
|
||||
self._attr_name = FRIENDLY_NAMES[feature_type]
|
||||
self._attr_translation_key = feature_type
|
||||
self._attr_unique_id = f"{speaker.soco.uid}-{feature_type}"
|
||||
self._attr_icon = FEATURE_ICONS.get(feature_type)
|
||||
|
||||
|
@ -28,7 +28,7 @@ async def test_entity_registry_unsupported(
|
||||
|
||||
assert "media_player.zone_a" in entity_registry.entities
|
||||
assert "sensor.zone_a_battery" not in entity_registry.entities
|
||||
assert "binary_sensor.zone_a_power" not in entity_registry.entities
|
||||
assert "binary_sensor.zone_a_charging" not in entity_registry.entities
|
||||
|
||||
|
||||
async def test_entity_registry_supported(
|
||||
@ -37,7 +37,7 @@ async def test_entity_registry_supported(
|
||||
"""Test sonos device with battery registered in the device registry."""
|
||||
assert "media_player.zone_a" in entity_registry.entities
|
||||
assert "sensor.zone_a_battery" in entity_registry.entities
|
||||
assert "binary_sensor.zone_a_power" in entity_registry.entities
|
||||
assert "binary_sensor.zone_a_charging" in entity_registry.entities
|
||||
|
||||
|
||||
async def test_battery_attributes(
|
||||
@ -49,7 +49,7 @@ async def test_battery_attributes(
|
||||
assert battery_state.state == "100"
|
||||
assert battery_state.attributes.get("unit_of_measurement") == "%"
|
||||
|
||||
power = entity_registry.entities["binary_sensor.zone_a_power"]
|
||||
power = entity_registry.entities["binary_sensor.zone_a_charging"]
|
||||
power_state = hass.states.get(power.entity_id)
|
||||
assert power_state.state == STATE_ON
|
||||
assert (
|
||||
@ -73,7 +73,7 @@ async def test_battery_on_s1(
|
||||
sub_callback = subscription.callback
|
||||
|
||||
assert "sensor.zone_a_battery" not in entity_registry.entities
|
||||
assert "binary_sensor.zone_a_power" not in entity_registry.entities
|
||||
assert "binary_sensor.zone_a_charging" not in entity_registry.entities
|
||||
|
||||
# Update the speaker with a callback event
|
||||
sub_callback(device_properties_event)
|
||||
@ -83,7 +83,7 @@ async def test_battery_on_s1(
|
||||
battery_state = hass.states.get(battery.entity_id)
|
||||
assert battery_state.state == "100"
|
||||
|
||||
power = entity_registry.entities["binary_sensor.zone_a_power"]
|
||||
power = entity_registry.entities["binary_sensor.zone_a_charging"]
|
||||
power_state = hass.states.get(power.entity_id)
|
||||
assert power_state.state == STATE_OFF
|
||||
assert power_state.attributes.get(ATTR_BATTERY_POWER_SOURCE) == "BATTERY"
|
||||
|
Loading…
x
Reference in New Issue
Block a user