Use enums in ovo_energy (#62087)

This commit is contained in:
Robert Hillis 2021-12-16 09:30:59 -05:00 committed by GitHub
parent 6083b56139
commit 0ce985ee7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10,17 +10,13 @@ from ovoenergy import OVODailyUsage
from ovoenergy.ovoenergy import OVOEnergy from ovoenergy.ovoenergy import OVOEnergy
from homeassistant.components.sensor import ( from homeassistant.components.sensor import (
STATE_CLASS_TOTAL_INCREASING, SensorDeviceClass,
SensorEntity, SensorEntity,
SensorEntityDescription, SensorEntityDescription,
SensorStateClass,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import ENERGY_KILO_WATT_HOUR
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_MONETARY,
DEVICE_CLASS_TIMESTAMP,
ENERGY_KILO_WATT_HOUR,
)
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.typing import StateType from homeassistant.helpers.typing import StateType
@ -48,30 +44,30 @@ SENSOR_TYPES_ELECTRICITY: tuple[OVOEnergySensorEntityDescription, ...] = (
OVOEnergySensorEntityDescription( OVOEnergySensorEntityDescription(
key="last_electricity_reading", key="last_electricity_reading",
name="OVO Last Electricity Reading", name="OVO Last Electricity Reading",
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
value=lambda usage: usage.electricity[-1].consumption, value=lambda usage: usage.electricity[-1].consumption,
), ),
OVOEnergySensorEntityDescription( OVOEnergySensorEntityDescription(
key=KEY_LAST_ELECTRICITY_COST, key=KEY_LAST_ELECTRICITY_COST,
name="OVO Last Electricity Cost", name="OVO Last Electricity Cost",
device_class=DEVICE_CLASS_MONETARY, device_class=SensorDeviceClass.MONETARY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
value=lambda usage: usage.electricity[-1].cost.amount, value=lambda usage: usage.electricity[-1].cost.amount,
), ),
OVOEnergySensorEntityDescription( OVOEnergySensorEntityDescription(
key="last_electricity_start_time", key="last_electricity_start_time",
name="OVO Last Electricity Start Time", name="OVO Last Electricity Start Time",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
device_class=DEVICE_CLASS_TIMESTAMP, device_class=SensorDeviceClass.TIMESTAMP,
value=lambda usage: dt_util.as_utc(usage.electricity[-1].interval.start), value=lambda usage: dt_util.as_utc(usage.electricity[-1].interval.start),
), ),
OVOEnergySensorEntityDescription( OVOEnergySensorEntityDescription(
key="last_electricity_end_time", key="last_electricity_end_time",
name="OVO Last Electricity End Time", name="OVO Last Electricity End Time",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
device_class=DEVICE_CLASS_TIMESTAMP, device_class=SensorDeviceClass.TIMESTAMP,
value=lambda usage: dt_util.as_utc(usage.electricity[-1].interval.end), value=lambda usage: dt_util.as_utc(usage.electricity[-1].interval.end),
), ),
) )
@ -80,8 +76,8 @@ SENSOR_TYPES_GAS: tuple[OVOEnergySensorEntityDescription, ...] = (
OVOEnergySensorEntityDescription( OVOEnergySensorEntityDescription(
key="last_gas_reading", key="last_gas_reading",
name="OVO Last Gas Reading", name="OVO Last Gas Reading",
device_class=DEVICE_CLASS_ENERGY, device_class=SensorDeviceClass.ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
icon="mdi:gas-cylinder", icon="mdi:gas-cylinder",
value=lambda usage: usage.gas[-1].consumption, value=lambda usage: usage.gas[-1].consumption,
@ -89,8 +85,8 @@ SENSOR_TYPES_GAS: tuple[OVOEnergySensorEntityDescription, ...] = (
OVOEnergySensorEntityDescription( OVOEnergySensorEntityDescription(
key=KEY_LAST_GAS_COST, key=KEY_LAST_GAS_COST,
name="OVO Last Gas Cost", name="OVO Last Gas Cost",
device_class=DEVICE_CLASS_MONETARY, device_class=SensorDeviceClass.MONETARY,
state_class=STATE_CLASS_TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
icon="mdi:cash-multiple", icon="mdi:cash-multiple",
value=lambda usage: usage.gas[-1].cost.amount, value=lambda usage: usage.gas[-1].cost.amount,
), ),
@ -98,14 +94,14 @@ SENSOR_TYPES_GAS: tuple[OVOEnergySensorEntityDescription, ...] = (
key="last_gas_start_time", key="last_gas_start_time",
name="OVO Last Gas Start Time", name="OVO Last Gas Start Time",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
device_class=DEVICE_CLASS_TIMESTAMP, device_class=SensorDeviceClass.TIMESTAMP,
value=lambda usage: dt_util.as_utc(usage.gas[-1].interval.start), value=lambda usage: dt_util.as_utc(usage.gas[-1].interval.start),
), ),
OVOEnergySensorEntityDescription( OVOEnergySensorEntityDescription(
key="last_gas_end_time", key="last_gas_end_time",
name="OVO Last Gas End Time", name="OVO Last Gas End Time",
entity_registry_enabled_default=False, entity_registry_enabled_default=False,
device_class=DEVICE_CLASS_TIMESTAMP, device_class=SensorDeviceClass.TIMESTAMP,
value=lambda usage: dt_util.as_utc(usage.gas[-1].interval.end), value=lambda usage: dt_util.as_utc(usage.gas[-1].interval.end),
), ),
) )