1
mirror of https://github.com/home-assistant/core synced 2024-08-02 23:40:32 +02:00

Use new enums in fritzbox (#61447)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-10 14:58:23 +01:00 committed by GitHub
parent 0d9d6d5727
commit 44b7c0e65c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 26 deletions

View File

@ -8,7 +8,7 @@ from typing import Final
from pyfritzhome.fritzhomedevice import FritzhomeDevice
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_WINDOW,
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
@ -40,7 +40,7 @@ BINARY_SENSOR_TYPES: Final[tuple[FritzBinarySensorEntityDescription, ...]] = (
FritzBinarySensorEntityDescription(
key="alarm",
name="Alarm",
device_class=DEVICE_CLASS_WINDOW,
device_class=BinarySensorDeviceClass.WINDOW,
suitable=lambda device: device.has_alarm, # type: ignore[no-any-return]
is_on=lambda device: device.alert_state, # type: ignore[no-any-return]
),

View File

@ -10,26 +10,20 @@ from pyfritzhome.fritzhomedevice import FritzhomeDevice
from homeassistant.components.climate.const import PRESET_COMFORT, PRESET_ECO
from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_HUMIDITY,
DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE,
DEVICE_CLASS_TIMESTAMP,
ENERGY_KILO_WATT_HOUR,
ENTITY_CATEGORY_DIAGNOSTIC,
PERCENTAGE,
POWER_WATT,
TEMP_CELSIUS,
)
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType
from homeassistant.util.dt import utc_from_timestamp
@ -58,9 +52,9 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
key="temperature",
name="Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
state_class=STATE_CLASS_MEASUREMENT,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
device_class=SensorDeviceClass.TEMPERATURE,
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
suitable=lambda device: (
device.has_temperature_sensor and not device.has_thermostat
),
@ -70,8 +64,8 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
key="humidity",
name="Humidity",
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_HUMIDITY,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.HUMIDITY,
state_class=SensorStateClass.MEASUREMENT,
suitable=lambda device: device.rel_humidity is not None,
native_value=lambda device: device.rel_humidity, # type: ignore[no-any-return]
),
@ -79,8 +73,8 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
key="battery",
name="Battery",
native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_BATTERY,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
device_class=SensorDeviceClass.BATTERY,
entity_category=EntityCategory.DIAGNOSTIC,
suitable=lambda device: device.battery_level is not None,
native_value=lambda device: device.battery_level, # type: ignore[no-any-return]
),
@ -88,8 +82,8 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
key="power_consumption",
name="Power Consumption",
native_unit_of_measurement=POWER_WATT,
device_class=DEVICE_CLASS_POWER,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
suitable=lambda device: device.has_powermeter, # type: ignore[no-any-return]
native_value=lambda device: device.power / 1000 if device.power else 0.0,
),
@ -97,8 +91,8 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
key="total_energy",
name="Total Energy",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
suitable=lambda device: device.has_powermeter, # type: ignore[no-any-return]
native_value=lambda device: device.energy / 1000 if device.energy else 0.0,
),
@ -107,7 +101,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
key="comfort_temperature",
name="Comfort Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
suitable=lambda device: device.has_thermostat
and device.comfort_temperature is not None,
native_value=lambda device: device.comfort_temperature, # type: ignore[no-any-return]
@ -116,7 +110,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
key="eco_temperature",
name="Eco Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
suitable=lambda device: device.has_thermostat
and device.eco_temperature is not None,
native_value=lambda device: device.eco_temperature, # type: ignore[no-any-return]
@ -125,7 +119,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
key="nextchange_temperature",
name="Next Scheduled Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
device_class=DEVICE_CLASS_TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
suitable=lambda device: device.has_thermostat
and device.nextchange_temperature is not None,
native_value=lambda device: device.nextchange_temperature, # type: ignore[no-any-return]
@ -133,7 +127,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
FritzSensorEntityDescription(
key="nextchange_time",
name="Next Scheduled Change Time",
device_class=DEVICE_CLASS_TIMESTAMP,
device_class=SensorDeviceClass.TIMESTAMP,
suitable=lambda device: device.has_thermostat
and device.nextchange_endperiod is not None,
native_value=lambda device: utc_from_timestamp(device.nextchange_endperiod),