Use new enums in smappee (#62209)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-18 14:56:13 +01:00 committed by GitHub
parent af631b90e5
commit 93cba53860
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 45 deletions

View file

@ -1,6 +1,6 @@
"""Support for monitoring a Smappee appliance binary sensor.""" """Support for monitoring a Smappee appliance binary sensor."""
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
DEVICE_CLASS_PRESENCE, BinarySensorDeviceClass,
BinarySensorEntity, BinarySensorEntity,
) )
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
@ -58,7 +58,7 @@ class SmappeePresence(BinarySensorEntity):
@property @property
def device_class(self): def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES.""" """Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_PRESENCE return BinarySensorDeviceClass.PRESENCE
@property @property
def unique_id( def unique_id(
@ -68,7 +68,7 @@ class SmappeePresence(BinarySensorEntity):
return ( return (
f"{self._service_location.device_serial_number}-" f"{self._service_location.device_serial_number}-"
f"{self._service_location.service_location_id}-" f"{self._service_location.service_location_id}-"
f"{DEVICE_CLASS_PRESENCE}" f"{BinarySensorDeviceClass.PRESENCE}"
) )
@property @property

View file

@ -4,15 +4,12 @@ from __future__ import annotations
from dataclasses import dataclass, field from dataclasses import dataclass, field
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT, SensorDeviceClass,
STATE_CLASS_TOTAL_INCREASING,
SensorEntity, SensorEntity,
SensorEntityDescription, SensorEntityDescription,
SensorStateClass,
) )
from homeassistant.const import ( from homeassistant.const import (
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
DEVICE_CLASS_VOLTAGE,
ELECTRIC_POTENTIAL_VOLT, ELECTRIC_POTENTIAL_VOLT,
ENERGY_KILO_WATT_HOUR, ENERGY_KILO_WATT_HOUR,
ENERGY_WATT_HOUR, ENERGY_WATT_HOUR,
@ -55,8 +52,8 @@ TREND_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = (
name="Total consumption - Active power", name="Total consumption - Active power",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=POWER_WATT,
sensor_id="total_power", sensor_id="total_power",
device_class=DEVICE_CLASS_POWER, device_class=SensorDeviceClass.POWER,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
local_polling=True, # both cloud and local local_polling=True, # both cloud and local
), ),
SmappeePollingSensorEntityDescription( SmappeePollingSensorEntityDescription(
@ -64,40 +61,40 @@ TREND_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = (
name="Always on - Active power", name="Always on - Active power",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=POWER_WATT,
sensor_id="alwayson", sensor_id="alwayson",
device_class=DEVICE_CLASS_POWER, device_class=SensorDeviceClass.POWER,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
SmappeePollingSensorEntityDescription( SmappeePollingSensorEntityDescription(
key="power_today", key="power_today",
name="Total consumption - Today", name="Total consumption - Today",
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
sensor_id="power_today", sensor_id="power_today",
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
), ),
SmappeePollingSensorEntityDescription( SmappeePollingSensorEntityDescription(
key="power_current_hour", key="power_current_hour",
name="Total consumption - Current hour", name="Total consumption - Current hour",
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
sensor_id="power_current_hour", sensor_id="power_current_hour",
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
), ),
SmappeePollingSensorEntityDescription( SmappeePollingSensorEntityDescription(
key="power_last_5_minutes", key="power_last_5_minutes",
name="Total consumption - Last 5 minutes", name="Total consumption - Last 5 minutes",
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
sensor_id="power_last_5_minutes", sensor_id="power_last_5_minutes",
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
), ),
SmappeePollingSensorEntityDescription( SmappeePollingSensorEntityDescription(
key="alwayson_today", key="alwayson_today",
name="Always on - Today", name="Always on - Today",
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
sensor_id="alwayson_today", sensor_id="alwayson_today",
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
), ),
) )
REACTIVE_SENSORS: tuple[SmappeeSensorEntityDescription, ...] = ( REACTIVE_SENSORS: tuple[SmappeeSensorEntityDescription, ...] = (
@ -106,8 +103,8 @@ REACTIVE_SENSORS: tuple[SmappeeSensorEntityDescription, ...] = (
name="Total consumption - Reactive power", name="Total consumption - Reactive power",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=POWER_WATT,
sensor_id="total_reactive_power", sensor_id="total_reactive_power",
device_class=DEVICE_CLASS_POWER, device_class=SensorDeviceClass.POWER,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
) )
SOLAR_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = ( SOLAR_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = (
@ -116,8 +113,8 @@ SOLAR_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = (
name="Total production - Active power", name="Total production - Active power",
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=POWER_WATT,
sensor_id="solar_power", sensor_id="solar_power",
device_class=DEVICE_CLASS_POWER, device_class=SensorDeviceClass.POWER,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
local_polling=True, # both cloud and local local_polling=True, # both cloud and local
), ),
SmappeePollingSensorEntityDescription( SmappeePollingSensorEntityDescription(
@ -125,16 +122,16 @@ SOLAR_SENSORS: tuple[SmappeePollingSensorEntityDescription, ...] = (
name="Total production - Today", name="Total production - Today",
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
sensor_id="solar_today", sensor_id="solar_today",
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
), ),
SmappeePollingSensorEntityDescription( SmappeePollingSensorEntityDescription(
key="solar_current_hour", key="solar_current_hour",
name="Total production - Current hour", name="Total production - Current hour",
native_unit_of_measurement=ENERGY_WATT_HOUR, native_unit_of_measurement=ENERGY_WATT_HOUR,
sensor_id="solar_current_hour", sensor_id="solar_current_hour",
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
), ),
) )
VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = ( VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = (
@ -143,8 +140,8 @@ VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = (
name="Phase voltages - A", name="Phase voltages - A",
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
sensor_id="phase_voltage_a", sensor_id="phase_voltage_a",
device_class=DEVICE_CLASS_VOLTAGE, device_class=SensorDeviceClass.VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
phase_types={"ONE", "TWO", "THREE_STAR", "THREE_DELTA"}, phase_types={"ONE", "TWO", "THREE_STAR", "THREE_DELTA"},
), ),
SmappeeVoltageSensorEntityDescription( SmappeeVoltageSensorEntityDescription(
@ -152,8 +149,8 @@ VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = (
name="Phase voltages - B", name="Phase voltages - B",
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
sensor_id="phase_voltage_b", sensor_id="phase_voltage_b",
device_class=DEVICE_CLASS_VOLTAGE, device_class=SensorDeviceClass.VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
phase_types={"TWO", "THREE_STAR", "THREE_DELTA"}, phase_types={"TWO", "THREE_STAR", "THREE_DELTA"},
), ),
SmappeeVoltageSensorEntityDescription( SmappeeVoltageSensorEntityDescription(
@ -161,8 +158,8 @@ VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = (
name="Phase voltages - C", name="Phase voltages - C",
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
sensor_id="phase_voltage_c", sensor_id="phase_voltage_c",
device_class=DEVICE_CLASS_VOLTAGE, device_class=SensorDeviceClass.VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
phase_types={"THREE_STAR"}, phase_types={"THREE_STAR"},
), ),
SmappeeVoltageSensorEntityDescription( SmappeeVoltageSensorEntityDescription(
@ -170,8 +167,8 @@ VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = (
name="Line voltages - A", name="Line voltages - A",
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
sensor_id="line_voltage_a", sensor_id="line_voltage_a",
device_class=DEVICE_CLASS_VOLTAGE, device_class=SensorDeviceClass.VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
phase_types={"ONE", "TWO", "THREE_STAR", "THREE_DELTA"}, phase_types={"ONE", "TWO", "THREE_STAR", "THREE_DELTA"},
), ),
SmappeeVoltageSensorEntityDescription( SmappeeVoltageSensorEntityDescription(
@ -179,8 +176,8 @@ VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = (
name="Line voltages - B", name="Line voltages - B",
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
sensor_id="line_voltage_b", sensor_id="line_voltage_b",
device_class=DEVICE_CLASS_VOLTAGE, device_class=SensorDeviceClass.VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
phase_types={"TWO", "THREE_STAR", "THREE_DELTA"}, phase_types={"TWO", "THREE_STAR", "THREE_DELTA"},
), ),
SmappeeVoltageSensorEntityDescription( SmappeeVoltageSensorEntityDescription(
@ -188,8 +185,8 @@ VOLTAGE_SENSORS: tuple[SmappeeVoltageSensorEntityDescription, ...] = (
name="Line voltages - C", name="Line voltages - C",
native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT, native_unit_of_measurement=ELECTRIC_POTENTIAL_VOLT,
sensor_id="line_voltage_c", sensor_id="line_voltage_c",
device_class=DEVICE_CLASS_VOLTAGE, device_class=SensorDeviceClass.VOLTAGE,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
phase_types={"THREE_STAR", "THREE_DELTA"}, phase_types={"THREE_STAR", "THREE_DELTA"},
), ),
) )
@ -252,8 +249,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
name=measurement.name, name=measurement.name,
native_unit_of_measurement=POWER_WATT, native_unit_of_measurement=POWER_WATT,
sensor_id=measurement_id, sensor_id=measurement_id,
device_class=DEVICE_CLASS_POWER, device_class=SensorDeviceClass.POWER,
state_class=STATE_CLASS_MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
), ),
) )
for measurement_id, measurement in service_location.measurements.items() 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"), native_unit_of_measurement=channel.get("uom"),
sensor_id=f"{sensor_id}-{channel.get('channel')}", 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() 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", name=f"{actuator.name} - energy today",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
sensor_id=actuator_id, sensor_id=actuator_id,
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
), ),
) )
for actuator_id, actuator in service_location.actuators.items() for actuator_id, actuator in service_location.actuators.items()