Migrate Sonos to new entity naming style (#74909)
This commit is contained in:
parent
cdab725bf4
commit
5f728b955e
6 changed files with 15 additions and 20 deletions
|
@ -58,12 +58,12 @@ 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."""
|
||||
super().__init__(speaker)
|
||||
self._attr_unique_id = f"{self.soco.uid}-power"
|
||||
self._attr_name = f"{self.speaker.zone_name} Power"
|
||||
|
||||
async def _async_fallback_poll(self) -> None:
|
||||
"""Poll the device for the current state."""
|
||||
|
@ -92,12 +92,12 @@ class SonosMicrophoneSensorEntity(SonosEntity, BinarySensorEntity):
|
|||
|
||||
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
_attr_icon = "mdi:microphone"
|
||||
_attr_name = "Microphone"
|
||||
|
||||
def __init__(self, speaker: SonosSpeaker) -> None:
|
||||
"""Initialize the microphone binary sensor entity."""
|
||||
super().__init__(speaker)
|
||||
self._attr_unique_id = f"{self.soco.uid}-microphone"
|
||||
self._attr_name = f"{self.speaker.zone_name} Microphone"
|
||||
|
||||
async def _async_fallback_poll(self) -> None:
|
||||
"""Handle polling when subscription fails."""
|
||||
|
|
|
@ -26,6 +26,7 @@ class SonosEntity(Entity):
|
|||
"""Representation of a Sonos entity."""
|
||||
|
||||
_attr_should_poll = False
|
||||
_attr_has_entity_name = True
|
||||
|
||||
def __init__(self, speaker: SonosSpeaker) -> None:
|
||||
"""Initialize a SonosEntity."""
|
||||
|
|
|
@ -216,7 +216,6 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
|
|||
"""Initialize the media player entity."""
|
||||
super().__init__(speaker)
|
||||
self._attr_unique_id = self.soco.uid
|
||||
self._attr_name = self.speaker.zone_name
|
||||
|
||||
async def async_added_to_hass(self) -> None:
|
||||
"""Handle common setup when added to hass."""
|
||||
|
|
|
@ -72,8 +72,7 @@ class SonosLevelEntity(SonosEntity, NumberEntity):
|
|||
"""Initialize the level entity."""
|
||||
super().__init__(speaker)
|
||||
self._attr_unique_id = f"{self.soco.uid}-{level_type}"
|
||||
name_suffix = level_type.replace("_", " ").title()
|
||||
self._attr_name = f"{self.speaker.zone_name} {name_suffix}"
|
||||
self._attr_name = level_type.replace("_", " ").capitalize()
|
||||
self.level_type = level_type
|
||||
self._attr_native_min_value, self._attr_native_max_value = valid_range
|
||||
|
||||
|
|
|
@ -80,13 +80,13 @@ 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:
|
||||
"""Initialize the battery sensor."""
|
||||
super().__init__(speaker)
|
||||
self._attr_unique_id = f"{self.soco.uid}-battery"
|
||||
self._attr_name = f"{self.speaker.zone_name} Battery"
|
||||
|
||||
async def _async_fallback_poll(self) -> None:
|
||||
"""Poll the device for the current state."""
|
||||
|
@ -108,13 +108,13 @@ class SonosAudioInputFormatSensorEntity(SonosPollingEntity, SensorEntity):
|
|||
|
||||
_attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
_attr_icon = "mdi:import"
|
||||
_attr_name = "Audio input format"
|
||||
_attr_should_poll = True
|
||||
|
||||
def __init__(self, speaker: SonosSpeaker, audio_format: str) -> None:
|
||||
"""Initialize the audio input format sensor."""
|
||||
super().__init__(speaker)
|
||||
self._attr_unique_id = f"{self.soco.uid}-audio-format"
|
||||
self._attr_name = f"{self.speaker.zone_name} Audio Input Format"
|
||||
self._attr_native_value = audio_format
|
||||
|
||||
def poll_state(self) -> None:
|
||||
|
@ -137,7 +137,7 @@ class SonosFavoritesEntity(SensorEntity):
|
|||
|
||||
_attr_entity_registry_enabled_default = False
|
||||
_attr_icon = "mdi:star"
|
||||
_attr_name = "Sonos Favorites"
|
||||
_attr_name = "Sonos favorites"
|
||||
_attr_native_unit_of_measurement = "items"
|
||||
_attr_should_poll = False
|
||||
|
||||
|
|
|
@ -69,13 +69,13 @@ POLL_REQUIRED = (
|
|||
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_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",
|
||||
ATTR_SUB_ENABLED: "Subwoofer enabled",
|
||||
ATTR_SURROUND_ENABLED: "Surround enabled",
|
||||
ATTR_TOUCH_CONTROLS: "Touch controls",
|
||||
}
|
||||
|
||||
FEATURE_ICONS = {
|
||||
|
@ -160,7 +160,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 = f"{speaker.zone_name} {FRIENDLY_NAMES[feature_type]}"
|
||||
self._attr_name = FRIENDLY_NAMES[feature_type]
|
||||
self._attr_unique_id = f"{speaker.soco.uid}-{feature_type}"
|
||||
self._attr_icon = FEATURE_ICONS.get(feature_type)
|
||||
|
||||
|
@ -240,11 +240,7 @@ class SonosAlarmEntity(SonosEntity, SwitchEntity):
|
|||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the sensor."""
|
||||
return "{} {} Alarm {}".format(
|
||||
self.speaker.zone_name,
|
||||
self.alarm.recurrence.title(),
|
||||
str(self.alarm.start_time)[0:5],
|
||||
)
|
||||
return f"{self.alarm.recurrence.capitalize()} alarm {str(self.alarm.start_time)[:5]}"
|
||||
|
||||
async def _async_fallback_poll(self) -> None:
|
||||
"""Call the central alarm polling method."""
|
||||
|
|
Loading…
Add table
Reference in a new issue