diff --git a/homeassistant/components/smappee/binary_sensor.py b/homeassistant/components/smappee/binary_sensor.py index 7e46a1021e5..35aa103bd03 100644 --- a/homeassistant/components/smappee/binary_sensor.py +++ b/homeassistant/components/smappee/binary_sensor.py @@ -1,6 +1,6 @@ """Support for monitoring a Smappee appliance binary sensor.""" from homeassistant.components.binary_sensor import ( - DEVICE_CLASS_PRESENCE, + BinarySensorDeviceClass, BinarySensorEntity, ) from homeassistant.helpers.entity import DeviceInfo @@ -58,7 +58,7 @@ class SmappeePresence(BinarySensorEntity): @property def device_class(self): """Return the class of this device, from component DEVICE_CLASSES.""" - return DEVICE_CLASS_PRESENCE + return BinarySensorDeviceClass.PRESENCE @property def unique_id( @@ -68,7 +68,7 @@ class SmappeePresence(BinarySensorEntity): return ( f"{self._service_location.device_serial_number}-" f"{self._service_location.service_location_id}-" - f"{DEVICE_CLASS_PRESENCE}" + f"{BinarySensorDeviceClass.PRESENCE}" ) @property diff --git a/homeassistant/components/smappee/sensor.py b/homeassistant/components/smappee/sensor.py index 595cc4da02d..e2eef5d06cf 100644 --- a/homeassistant/components/smappee/sensor.py +++ b/homeassistant/components/smappee/sensor.py @@ -4,15 +4,12 @@ from __future__ import annotations from dataclasses import dataclass, field from homeassistant.components.sensor import ( - STATE_CLASS_MEASUREMENT, - STATE_CLASS_TOTAL_INCREASING, + SensorDeviceClass, SensorEntity, SensorEntityDescription, + SensorStateClass, ) from homeassistant.const import ( - DEVICE_CLASS_ENERGY, - DEVICE_CLASS_POWER, - DEVICE_CLASS_VOLTAGE, ELECTRIC_POTENTIAL_VOLT, ENERGY_KILO_WATT_HOUR, ENERGY_WATT_HOUR, @@ -55,8 +52,8 @@ TREND_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = ( name="Total consumption - Active power", native_unit_of_measurement=POWER_WATT, sensor_id="total_power", - device_class=DEVICE_CLASS_POWER, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.POWER, + state_class=SensorStateClass.MEASUREMENT, local_polling=True, # both cloud and local ), SmappeePollingSensorEntityDescription( @@ -64,40 +61,40 @@ TREND_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = ( name="Always on - Active power", native_unit_of_measurement=POWER_WATT, sensor_id="alwayson", - device_class=DEVICE_CLASS_POWER, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.POWER, + state_class=SensorStateClass.MEASUREMENT, ), SmappeePollingSensorEntityDescription( key="power_today", name="Total consumption - Today", native_unit_of_measurement=ENERGY_WATT_HOUR, sensor_id="power_today", - device_class=DEVICE_CLASS_ENERGY, - state_class=STATE_CLASS_TOTAL_INCREASING, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, ), SmappeePollingSensorEntityDescription( key="power_current_hour", name="Total consumption - Current hour", native_unit_of_measurement=ENERGY_WATT_HOUR, sensor_id="power_current_hour", - device_class=DEVICE_CLASS_ENERGY, - state_class=STATE_CLASS_TOTAL_INCREASING, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, ), SmappeePollingSensorEntityDescription( key="power_last_5_minutes", name="Total consumption - Last 5 minutes", native_unit_of_measurement=ENERGY_WATT_HOUR, sensor_id="power_last_5_minutes", - device_class=DEVICE_CLASS_ENERGY, - state_class=STATE_CLASS_TOTAL_INCREASING, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, ), SmappeePollingSensorEntityDescription( key="alwayson_today", name="Always on - Today", native_unit_of_measurement=ENERGY_WATT_HOUR, sensor_id="alwayson_today", - device_class=DEVICE_CLASS_ENERGY, - state_class=STATE_CLASS_TOTAL_INCREASING, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, ), ) REACTIVE_SENSORS: tuple[SmappeeSensorEntityDescription, ...] = ( @@ -106,8 +103,8 @@ REACTIVE_SENSORS: tuple[SmappeeSensorEntityDescription, ...] = ( name="Total consumption - Reactive power", native_unit_of_measurement=POWER_WATT, sensor_id="total_reactive_power", - device_class=DEVICE_CLASS_POWER, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.POWER, + state_class=SensorStateClass.MEASUREMENT, ), ) SOLAR_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = ( @@ -116,8 +113,8 @@ SOLAR_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = ( name="Total production - Active power", native_unit_of_measurement=POWER_WATT, sensor_id="solar_power", - device_class=DEVICE_CLASS_POWER, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.POWER, + state_class=SensorStateClass.MEASUREMENT, local_polling=True, # both cloud and local ), SmappeePollingSensorEntityDescription( @@ -125,16 +122,16 @@ SOLAR_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = ( name="Total production - Today", native_unit_of_measurement=ENERGY_WATT_HOUR, sensor_id="solar_today", - device_class=DEVICE_CLASS_ENERGY, - state_class=STATE_CLASS_TOTAL_INCREASING, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, ), SmappeePollingSensorEntityDescription( key="solar_current_hour", name="Total production - Current hour", native_unit_of_measurement=ENERGY_WATT_HOUR, sensor_id="solar_current_hour", - device_class=DEVICE_CLASS_ENERGY, - state_class=STATE_CLASS_TOTAL_INCREASING, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, ), ) VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = ( @@ -143,8 +140,8 @@ VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = ( name="Phase voltages - A", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, sensor_id="phase_voltage_a", - device_class=DEVICE_CLASS_VOLTAGE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.VOLTAGE, + state_class=SensorStateClass.MEASUREMENT, phase_types={"ONE", "TWO", "THREE_STAR", "THREE_DELTA"}, ), SmappeeVoltageSensorEntityDescription( @@ -152,8 +149,8 @@ VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = ( name="Phase voltages - B", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, sensor_id="phase_voltage_b", - device_class=DEVICE_CLASS_VOLTAGE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.VOLTAGE, + state_class=SensorStateClass.MEASUREMENT, phase_types={"TWO", "THREE_STAR", "THREE_DELTA"}, ), SmappeeVoltageSensorEntityDescription( @@ -161,8 +158,8 @@ VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = ( name="Phase voltages - C", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, sensor_id="phase_voltage_c", - device_class=DEVICE_CLASS_VOLTAGE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.VOLTAGE, + state_class=SensorStateClass.MEASUREMENT, phase_types={"THREE_STAR"}, ), SmappeeVoltageSensorEntityDescription( @@ -170,8 +167,8 @@ VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = ( name="Line voltages - A", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, sensor_id="line_voltage_a", - device_class=DEVICE_CLASS_VOLTAGE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.VOLTAGE, + state_class=SensorStateClass.MEASUREMENT, phase_types={"ONE", "TWO", "THREE_STAR", "THREE_DELTA"}, ), SmappeeVoltageSensorEntityDescription( @@ -179,8 +176,8 @@ VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = ( name="Line voltages - B", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, sensor_id="line_voltage_b", - device_class=DEVICE_CLASS_VOLTAGE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.VOLTAGE, + state_class=SensorStateClass.MEASUREMENT, phase_types={"TWO", "THREE_STAR", "THREE_DELTA"}, ), SmappeeVoltageSensorEntityDescription( @@ -188,8 +185,8 @@ VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = ( name="Line voltages - C", native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, sensor_id="line_voltage_c", - device_class=DEVICE_CLASS_VOLTAGE, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.VOLTAGE, + state_class=SensorStateClass.MEASUREMENT, phase_types={"THREE_STAR", "THREE_DELTA"}, ), ) @@ -252,8 +249,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): name=measurement.name, native_unit_of_measurement=POWER_WATT, sensor_id=measurement_id, - device_class=DEVICE_CLASS_POWER, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.POWER, + state_class=SensorStateClass.MEASUREMENT, ), ) for measurement_id, measurement in service_location.measurements.items() @@ -296,7 +293,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): ), native_unit_of_measurement=channel.get("uom"), sensor_id=f"{sensor_id}-{channel.get('channel')}", - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, ), ) for sensor_id, sensor in service_location.sensors.items() @@ -315,8 +312,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): name=f"{actuator.name} - energy today", native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, sensor_id=actuator_id, - device_class=DEVICE_CLASS_ENERGY, - state_class=STATE_CLASS_TOTAL_INCREASING, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, ), ) for actuator_id, actuator in service_location.actuators.items()