mirror of
https://github.com/home-assistant/core.git
synced 2025-04-25 09:47:52 +00:00
Use new enums in sonos (#62202)
This commit is contained in:
parent
a0cd29bbcf
commit
c59ae54dc8
@ -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."""
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user