mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use DeviceClass and StateClass enums in broadlink (#61326)
Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
6d61a4678d
commit
d7756efe55
@ -6,18 +6,11 @@ import logging
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
DEVICE_CLASS_CURRENT,
|
|
||||||
DEVICE_CLASS_ENERGY,
|
|
||||||
DEVICE_CLASS_HUMIDITY,
|
|
||||||
DEVICE_CLASS_ILLUMINANCE,
|
|
||||||
DEVICE_CLASS_POWER,
|
|
||||||
DEVICE_CLASS_TEMPERATURE,
|
|
||||||
DEVICE_CLASS_VOLTAGE,
|
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
STATE_CLASS_MEASUREMENT,
|
SensorDeviceClass,
|
||||||
STATE_CLASS_TOTAL_INCREASING,
|
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
@ -41,8 +34,8 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||||||
key="temperature",
|
key="temperature",
|
||||||
name="Temperature",
|
name="Temperature",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=TEMP_CELSIUS,
|
||||||
device_class=DEVICE_CLASS_TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="air_quality",
|
key="air_quality",
|
||||||
@ -52,13 +45,13 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||||||
key="humidity",
|
key="humidity",
|
||||||
name="Humidity",
|
name="Humidity",
|
||||||
native_unit_of_measurement=PERCENTAGE,
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
device_class=DEVICE_CLASS_HUMIDITY,
|
device_class=SensorDeviceClass.HUMIDITY,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="light",
|
key="light",
|
||||||
name="Light",
|
name="Light",
|
||||||
device_class=DEVICE_CLASS_ILLUMINANCE,
|
device_class=SensorDeviceClass.ILLUMINANCE,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="noise",
|
key="noise",
|
||||||
@ -68,36 +61,36 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||||||
key="power",
|
key="power",
|
||||||
name="Current power",
|
name="Current power",
|
||||||
native_unit_of_measurement=POWER_WATT,
|
native_unit_of_measurement=POWER_WATT,
|
||||||
device_class=DEVICE_CLASS_POWER,
|
device_class=SensorDeviceClass.POWER,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="volt",
|
key="volt",
|
||||||
name="Voltage",
|
name="Voltage",
|
||||||
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
|
||||||
device_class=DEVICE_CLASS_VOLTAGE,
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="current",
|
key="current",
|
||||||
name="Current",
|
name="Current",
|
||||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||||
device_class=DEVICE_CLASS_CURRENT,
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="overload",
|
key="overload",
|
||||||
name="Overload",
|
name="Overload",
|
||||||
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE,
|
||||||
device_class=DEVICE_CLASS_CURRENT,
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
state_class=STATE_CLASS_MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="totalconsum",
|
key="totalconsum",
|
||||||
name="Total consumption",
|
name="Total consumption",
|
||||||
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
|
||||||
device_class=DEVICE_CLASS_ENERGY,
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
state_class=STATE_CLASS_TOTAL_INCREASING,
|
state_class=SensorStateClass.TOTAL_INCREASING,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -6,9 +6,8 @@ from broadlink.exceptions import BroadlinkException
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.switch import (
|
from homeassistant.components.switch import (
|
||||||
DEVICE_CLASS_OUTLET,
|
|
||||||
DEVICE_CLASS_SWITCH,
|
|
||||||
PLATFORM_SCHEMA,
|
PLATFORM_SCHEMA,
|
||||||
|
SwitchDeviceClass,
|
||||||
SwitchEntity,
|
SwitchEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -136,7 +135,7 @@ class BroadlinkSwitch(BroadlinkEntity, SwitchEntity, RestoreEntity, ABC):
|
|||||||
"""Representation of a Broadlink switch."""
|
"""Representation of a Broadlink switch."""
|
||||||
|
|
||||||
_attr_assumed_state = True
|
_attr_assumed_state = True
|
||||||
_attr_device_class = DEVICE_CLASS_SWITCH
|
_attr_device_class = SwitchDeviceClass.SWITCH
|
||||||
|
|
||||||
def __init__(self, device, command_on, command_off):
|
def __init__(self, device, command_on, command_off):
|
||||||
"""Initialize the switch."""
|
"""Initialize the switch."""
|
||||||
@ -269,7 +268,7 @@ class BroadlinkBG1Slot(BroadlinkSwitch):
|
|||||||
self._attr_is_on = self._coordinator.data[f"pwr{slot}"]
|
self._attr_is_on = self._coordinator.data[f"pwr{slot}"]
|
||||||
|
|
||||||
self._attr_name = f"{device.name} S{slot}"
|
self._attr_name = f"{device.name} S{slot}"
|
||||||
self._attr_device_class = DEVICE_CLASS_OUTLET
|
self._attr_device_class = SwitchDeviceClass.OUTLET
|
||||||
self._attr_unique_id = f"{device.unique_id}-s{slot}"
|
self._attr_unique_id = f"{device.unique_id}-s{slot}"
|
||||||
|
|
||||||
def _update_state(self, data):
|
def _update_state(self, data):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user