Use enums in vicare (#61994)

This commit is contained in:
Robert Hillis 2021-12-16 03:27:53 -05:00 committed by GitHub
parent b1117c17f1
commit b03ead1c9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 47 deletions

View File

@ -13,7 +13,7 @@ from PyViCare.PyViCareUtils import (
import requests
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_POWER,
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
@ -40,7 +40,7 @@ CIRCUIT_SENSORS: tuple[ViCareBinarySensorEntityDescription, ...] = (
ViCareBinarySensorEntityDescription(
key=SENSOR_CIRCULATION_PUMP_ACTIVE,
name="Circulation pump active",
device_class=DEVICE_CLASS_POWER,
device_class=BinarySensorDeviceClass.POWER,
value_getter=lambda api: api.getCirculationPumpActive(),
),
)
@ -49,7 +49,7 @@ BURNER_SENSORS: tuple[ViCareBinarySensorEntityDescription, ...] = (
ViCareBinarySensorEntityDescription(
key=SENSOR_BURNER_ACTIVE,
name="Burner active",
device_class=DEVICE_CLASS_POWER,
device_class=BinarySensorDeviceClass.POWER,
value_getter=lambda api: api.getActive(),
),
)
@ -58,7 +58,7 @@ COMPRESSOR_SENSORS: tuple[ViCareBinarySensorEntityDescription, ...] = (
ViCareBinarySensorEntityDescription(
key=SENSOR_COMPRESSOR_ACTIVE,
name="Compressor active",
device_class=DEVICE_CLASS_POWER,
device_class=BinarySensorDeviceClass.POWER,
value_getter=lambda api: api.getActive(),
),
)

View File

@ -1,13 +1,8 @@
"""Constants for the ViCare integration."""
import enum
from homeassistant.const import (
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_GAS,
ENERGY_KILO_WATT_HOUR,
VOLUME_CUBIC_METERS,
Platform,
)
from homeassistant.components.sensor import SensorDeviceClass
from homeassistant.const import ENERGY_KILO_WATT_HOUR, VOLUME_CUBIC_METERS, Platform
DOMAIN = "vicare"
@ -31,8 +26,8 @@ VICARE_CUBIC_METER = "cubicMeter"
VICARE_KWH = "kilowattHour"
VICARE_UNIT_TO_DEVICE_CLASS = {
VICARE_KWH: DEVICE_CLASS_ENERGY,
VICARE_CUBIC_METER: DEVICE_CLASS_GAS,
VICARE_KWH: SensorDeviceClass.ENERGY,
VICARE_CUBIC_METER: SensorDeviceClass.GAS,
}
VICARE_UNIT_TO_UNIT_OF_MEASUREMENT = {

View File

@ -15,16 +15,13 @@ from PyViCare.PyViCareUtils import (
import requests
from homeassistant.components.sensor import (
STATE_CLASS_MEASUREMENT,
STATE_CLASS_TOTAL_INCREASING,
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
SensorStateClass,
)
from homeassistant.const import (
CONF_NAME,
DEVICE_CLASS_ENERGY,
DEVICE_CLASS_POWER,
DEVICE_CLASS_TEMPERATURE,
ENERGY_KILO_WATT_HOUR,
PERCENTAGE,
POWER_WATT,
@ -94,21 +91,21 @@ GLOBAL_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
name="Outside Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
value_getter=lambda api: api.getOutsideTemperature(),
device_class=DEVICE_CLASS_TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
),
ViCareSensorEntityDescription(
key=SENSOR_RETURN_TEMPERATURE,
name="Return Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
value_getter=lambda api: api.getReturnTemperature(),
device_class=DEVICE_CLASS_TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
),
ViCareSensorEntityDescription(
key=SENSOR_BOILER_TEMPERATURE,
name="Boiler Temperature",
native_unit_of_measurement=TEMP_CELSIUS,
value_getter=lambda api: api.getBoilerTemperature(),
device_class=DEVICE_CLASS_TEMPERATURE,
device_class=SensorDeviceClass.TEMPERATURE,
),
ViCareSensorEntityDescription(
key=SENSOR_DHW_GAS_CONSUMPTION_TODAY,
@ -116,8 +113,8 @@ GLOBAL_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
value_getter=lambda api: api.getGasConsumptionDomesticHotWaterToday(),
unit_getter=lambda api: api.getGasConsumptionDomesticHotWaterUnit(),
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
ViCareSensorEntityDescription(
key=SENSOR_DHW_GAS_CONSUMPTION_THIS_WEEK,
@ -125,8 +122,8 @@ GLOBAL_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
value_getter=lambda api: api.getGasConsumptionDomesticHotWaterThisWeek(),
unit_getter=lambda api: api.getGasConsumptionDomesticHotWaterUnit(),
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
ViCareSensorEntityDescription(
key=SENSOR_DHW_GAS_CONSUMPTION_THIS_MONTH,
@ -134,8 +131,8 @@ GLOBAL_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
value_getter=lambda api: api.getGasConsumptionDomesticHotWaterThisMonth(),
unit_getter=lambda api: api.getGasConsumptionDomesticHotWaterUnit(),
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
ViCareSensorEntityDescription(
key=SENSOR_DHW_GAS_CONSUMPTION_THIS_YEAR,
@ -143,8 +140,8 @@ GLOBAL_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
value_getter=lambda api: api.getGasConsumptionDomesticHotWaterThisYear(),
unit_getter=lambda api: api.getGasConsumptionDomesticHotWaterUnit(),
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
ViCareSensorEntityDescription(
key=SENSOR_GAS_CONSUMPTION_TODAY,
@ -152,8 +149,8 @@ GLOBAL_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
value_getter=lambda api: api.getGasConsumptionHeatingToday(),
unit_getter=lambda api: api.getGasConsumptionHeatingUnit(),
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
ViCareSensorEntityDescription(
key=SENSOR_GAS_CONSUMPTION_THIS_WEEK,
@ -161,8 +158,8 @@ GLOBAL_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
value_getter=lambda api: api.getGasConsumptionHeatingThisWeek(),
unit_getter=lambda api: api.getGasConsumptionHeatingUnit(),
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
ViCareSensorEntityDescription(
key=SENSOR_GAS_CONSUMPTION_THIS_MONTH,
@ -170,8 +167,8 @@ GLOBAL_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
value_getter=lambda api: api.getGasConsumptionHeatingThisMonth(),
unit_getter=lambda api: api.getGasConsumptionHeatingUnit(),
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
ViCareSensorEntityDescription(
key=SENSOR_GAS_CONSUMPTION_THIS_YEAR,
@ -179,48 +176,48 @@ GLOBAL_SENSORS: tuple[ViCareSensorEntityDescription, ...] = (
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
value_getter=lambda api: api.getGasConsumptionHeatingThisYear(),
unit_getter=lambda api: api.getGasConsumptionHeatingUnit(),
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
ViCareSensorEntityDescription(
key=SENSOR_POWER_PRODUCTION_CURRENT,
name="Power production current",
native_unit_of_measurement=POWER_WATT,
value_getter=lambda api: api.getPowerProductionCurrent(),
device_class=DEVICE_CLASS_POWER,
state_class=STATE_CLASS_MEASUREMENT,
device_class=SensorDeviceClass.POWER,
state_class=SensorStateClass.MEASUREMENT,
),
ViCareSensorEntityDescription(
key=SENSOR_POWER_PRODUCTION_TODAY,
name="Power production today",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
value_getter=lambda api: api.getPowerProductionToday(),
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
ViCareSensorEntityDescription(
key=SENSOR_POWER_PRODUCTION_THIS_WEEK,
name="Power production this week",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
value_getter=lambda api: api.getPowerProductionThisWeek(),
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
ViCareSensorEntityDescription(
key=SENSOR_POWER_PRODUCTION_THIS_MONTH,
name="Power production this month",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
value_getter=lambda api: api.getPowerProductionThisMonth(),
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
ViCareSensorEntityDescription(
key=SENSOR_POWER_PRODUCTION_THIS_YEAR,
name="Power production this year",
native_unit_of_measurement=ENERGY_KILO_WATT_HOUR,
value_getter=lambda api: api.getPowerProductionThisYear(),
device_class=DEVICE_CLASS_ENERGY,
state_class=STATE_CLASS_TOTAL_INCREASING,
device_class=SensorDeviceClass.ENERGY,
state_class=SensorStateClass.TOTAL_INCREASING,
),
)