From c59ae54dc8c4ca44c07d2d64451ee333aa7a0884 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 17 Dec 2021 20:35:21 +0100 Subject: [PATCH] Use new enums in sonos (#62202) --- homeassistant/components/sonos/binary_sensor.py | 8 ++++---- homeassistant/components/sonos/number.py | 4 ++-- homeassistant/components/sonos/sensor.py | 15 ++++++--------- homeassistant/components/sonos/switch.py | 7 ++++--- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/sonos/binary_sensor.py b/homeassistant/components/sonos/binary_sensor.py index 615ad24e655..bab153175e8 100644 --- a/homeassistant/components/sonos/binary_sensor.py +++ b/homeassistant/components/sonos/binary_sensor.py @@ -4,11 +4,11 @@ from __future__ import annotations from typing import Any from homeassistant.components.binary_sensor import ( - DEVICE_CLASS_BATTERY_CHARGING, + BinarySensorDeviceClass, BinarySensorEntity, ) -from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import EntityCategory from .const import SONOS_CREATE_BATTERY from .entity import SonosEntity @@ -32,8 +32,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): class SonosPowerEntity(SonosEntity, BinarySensorEntity): """Representation of a Sonos power entity.""" - _attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC - _attr_device_class = DEVICE_CLASS_BATTERY_CHARGING + _attr_entity_category = EntityCategory.DIAGNOSTIC + _attr_device_class = BinarySensorDeviceClass.BATTERY_CHARGING def __init__(self, speaker: SonosSpeaker) -> None: """Initialize the power entity binary sensor.""" diff --git a/homeassistant/components/sonos/number.py b/homeassistant/components/sonos/number.py index 2bcfe5cd5ec..c1b0ffcfd3b 100644 --- a/homeassistant/components/sonos/number.py +++ b/homeassistant/components/sonos/number.py @@ -2,9 +2,9 @@ from __future__ import annotations from homeassistant.components.number import NumberEntity -from homeassistant.const import ENTITY_CATEGORY_CONFIG from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import EntityCategory from .const import SONOS_CREATE_LEVELS from .entity import SonosEntity @@ -32,7 +32,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): class SonosLevelEntity(SonosEntity, NumberEntity): """Representation of a Sonos level entity.""" - _attr_entity_category = ENTITY_CATEGORY_CONFIG + _attr_entity_category = EntityCategory.CONFIG _attr_min_value = -10 _attr_max_value = 10 diff --git a/homeassistant/components/sonos/sensor.py b/homeassistant/components/sonos/sensor.py index 62017f4d541..6a1162a6aa6 100644 --- a/homeassistant/components/sonos/sensor.py +++ b/homeassistant/components/sonos/sensor.py @@ -1,14 +1,11 @@ """Entity representing a Sonos battery level.""" from __future__ import annotations -from homeassistant.components.sensor import SensorEntity -from homeassistant.const import ( - DEVICE_CLASS_BATTERY, - ENTITY_CATEGORY_DIAGNOSTIC, - PERCENTAGE, -) +from homeassistant.components.sensor import SensorDeviceClass, SensorEntity +from homeassistant.const import PERCENTAGE from homeassistant.core import callback from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import EntityCategory from .const import SONOS_CREATE_AUDIO_FORMAT_SENSOR, SONOS_CREATE_BATTERY from .entity import SonosEntity @@ -45,8 +42,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): class SonosBatteryEntity(SonosEntity, SensorEntity): """Representation of a Sonos Battery entity.""" - _attr_device_class = DEVICE_CLASS_BATTERY - _attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC + _attr_device_class = SensorDeviceClass.BATTERY + _attr_entity_category = EntityCategory.DIAGNOSTIC _attr_native_unit_of_measurement = PERCENTAGE def __init__(self, speaker: SonosSpeaker) -> None: @@ -73,7 +70,7 @@ class SonosBatteryEntity(SonosEntity, SensorEntity): class SonosAudioInputFormatSensorEntity(SonosEntity, SensorEntity): """Representation of a Sonos audio import format sensor entity.""" - _attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC + _attr_entity_category = EntityCategory.DIAGNOSTIC _attr_icon = "mdi:import" _attr_should_poll = True diff --git a/homeassistant/components/sonos/switch.py b/homeassistant/components/sonos/switch.py index e92263991ab..a94df01fdc9 100644 --- a/homeassistant/components/sonos/switch.py +++ b/homeassistant/components/sonos/switch.py @@ -7,10 +7,11 @@ import logging from soco.exceptions import SoCoException, SoCoSlaveException, SoCoUPnPException from homeassistant.components.switch import ENTITY_ID_FORMAT, SwitchEntity -from homeassistant.const import ATTR_TIME, ENTITY_CATEGORY_CONFIG +from homeassistant.const import ATTR_TIME from homeassistant.core import callback from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers.dispatcher import async_dispatcher_connect +from homeassistant.helpers.entity import EntityCategory from .const import ( DATA_SONOS, @@ -140,7 +141,7 @@ class SonosSwitchEntity(SonosEntity, SwitchEntity): f"sonos_{speaker.zone_name}_{FRIENDLY_NAMES[feature_type]}" ) self.needs_coordinator = feature_type in COORDINATOR_FEATURES - self._attr_entity_category = ENTITY_CATEGORY_CONFIG + self._attr_entity_category = EntityCategory.CONFIG self._attr_name = f"{speaker.zone_name} {FRIENDLY_NAMES[feature_type]}" self._attr_unique_id = f"{speaker.soco.uid}-{feature_type}" self._attr_icon = FEATURE_ICONS.get(feature_type) @@ -194,7 +195,7 @@ class SonosSwitchEntity(SonosEntity, SwitchEntity): class SonosAlarmEntity(SonosEntity, SwitchEntity): """Representation of a Sonos Alarm entity.""" - _attr_entity_category = ENTITY_CATEGORY_CONFIG + _attr_entity_category = EntityCategory.CONFIG _attr_icon = "mdi:alarm" def __init__(self, alarm_id: str, speaker: SonosSpeaker) -> None: