Use unit enums in demo (#83130)

This commit is contained in:
epenet 2022-12-04 10:21:44 +01:00 committed by GitHub
parent 90f2a54165
commit aace084931
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 33 deletions

View File

@ -16,14 +16,12 @@ from homeassistant.components.recorder.statistics import (
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
ATTR_ENTITY_ID, ATTR_ENTITY_ID,
ENERGY_KILO_WATT_HOUR,
ENERGY_MEGA_WATT_HOUR,
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_START,
SOUND_PRESSURE_DB, SOUND_PRESSURE_DB,
TEMP_CELSIUS,
VOLUME_CUBIC_FEET,
VOLUME_CUBIC_METERS,
Platform, Platform,
UnitOfEnergy,
UnitOfTemperature,
UnitOfVolume,
) )
import homeassistant.core as ha import homeassistant.core as ha
from homeassistant.core import Event, HomeAssistant from homeassistant.core import Event, HomeAssistant
@ -306,7 +304,7 @@ async def _insert_statistics(hass: HomeAssistant) -> None:
"source": DOMAIN, "source": DOMAIN,
"name": "Outdoor temperature", "name": "Outdoor temperature",
"statistic_id": f"{DOMAIN}:temperature_outdoor", "statistic_id": f"{DOMAIN}:temperature_outdoor",
"unit_of_measurement": TEMP_CELSIUS, "unit_of_measurement": UnitOfTemperature.CELSIUS,
"has_mean": True, "has_mean": True,
"has_sum": False, "has_sum": False,
} }
@ -319,7 +317,7 @@ async def _insert_statistics(hass: HomeAssistant) -> None:
"source": DOMAIN, "source": DOMAIN,
"name": "Energy consumption 1", "name": "Energy consumption 1",
"statistic_id": f"{DOMAIN}:energy_consumption_kwh", "statistic_id": f"{DOMAIN}:energy_consumption_kwh",
"unit_of_measurement": ENERGY_KILO_WATT_HOUR, "unit_of_measurement": UnitOfEnergy.KILO_WATT_HOUR,
"has_mean": False, "has_mean": False,
"has_sum": True, "has_sum": True,
} }
@ -331,7 +329,7 @@ async def _insert_statistics(hass: HomeAssistant) -> None:
"source": DOMAIN, "source": DOMAIN,
"name": "Energy consumption 2", "name": "Energy consumption 2",
"statistic_id": f"{DOMAIN}:energy_consumption_mwh", "statistic_id": f"{DOMAIN}:energy_consumption_mwh",
"unit_of_measurement": ENERGY_MEGA_WATT_HOUR, "unit_of_measurement": UnitOfEnergy.MEGA_WATT_HOUR,
"has_mean": False, "has_mean": False,
"has_sum": True, "has_sum": True,
} }
@ -345,7 +343,7 @@ async def _insert_statistics(hass: HomeAssistant) -> None:
"source": DOMAIN, "source": DOMAIN,
"name": "Gas consumption 1", "name": "Gas consumption 1",
"statistic_id": f"{DOMAIN}:gas_consumption_m3", "statistic_id": f"{DOMAIN}:gas_consumption_m3",
"unit_of_measurement": VOLUME_CUBIC_METERS, "unit_of_measurement": UnitOfVolume.CUBIC_METERS,
"has_mean": False, "has_mean": False,
"has_sum": True, "has_sum": True,
} }
@ -359,7 +357,7 @@ async def _insert_statistics(hass: HomeAssistant) -> None:
"source": DOMAIN, "source": DOMAIN,
"name": "Gas consumption 2", "name": "Gas consumption 2",
"statistic_id": f"{DOMAIN}:gas_consumption_ft3", "statistic_id": f"{DOMAIN}:gas_consumption_ft3",
"unit_of_measurement": VOLUME_CUBIC_FEET, "unit_of_measurement": UnitOfVolume.CUBIC_FEET,
"has_mean": False, "has_mean": False,
"has_sum": True, "has_sum": True,
} }

View File

@ -12,7 +12,7 @@ from homeassistant.components.climate import (
HVACMode, HVACMode,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -36,7 +36,7 @@ async def async_setup_platform(
unique_id="climate_1", unique_id="climate_1",
name="HeatPump", name="HeatPump",
target_temperature=68, target_temperature=68,
unit_of_measurement=TEMP_FAHRENHEIT, unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
preset=None, preset=None,
current_temperature=77, current_temperature=77,
fan_mode=None, fan_mode=None,
@ -54,7 +54,7 @@ async def async_setup_platform(
unique_id="climate_2", unique_id="climate_2",
name="Hvac", name="Hvac",
target_temperature=21, target_temperature=21,
unit_of_measurement=TEMP_CELSIUS, unit_of_measurement=UnitOfTemperature.CELSIUS,
preset=None, preset=None,
current_temperature=22, current_temperature=22,
fan_mode="On High", fan_mode="On High",
@ -72,7 +72,7 @@ async def async_setup_platform(
unique_id="climate_3", unique_id="climate_3",
name="Ecobee", name="Ecobee",
target_temperature=None, target_temperature=None,
unit_of_measurement=TEMP_CELSIUS, unit_of_measurement=UnitOfTemperature.CELSIUS,
preset="home", preset="home",
preset_modes=["home", "eco"], preset_modes=["home", "eco"],
current_temperature=23, current_temperature=23,

View File

@ -7,7 +7,7 @@ from math import cos, pi, radians, sin
import random import random
from homeassistant.components.geo_location import GeolocationEvent from homeassistant.components.geo_location import GeolocationEvent
from homeassistant.const import LENGTH_KILOMETERS from homeassistant.const import UnitOfLength
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.event import track_time_interval from homeassistant.helpers.event import track_time_interval
@ -80,7 +80,7 @@ class DemoManager:
event_name = random.choice(EVENT_NAMES) event_name = random.choice(EVENT_NAMES)
return DemoGeolocationEvent( return DemoGeolocationEvent(
event_name, radius_in_km, latitude, longitude, LENGTH_KILOMETERS event_name, radius_in_km, latitude, longitude, UnitOfLength.KILOMETERS
) )
def _init_regular_updates(self) -> None: def _init_regular_updates(self) -> None:

View File

@ -3,7 +3,7 @@ from __future__ import annotations
from homeassistant.components.number import NumberDeviceClass, NumberEntity, NumberMode from homeassistant.components.number import NumberDeviceClass, NumberEntity, NumberMode
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DEVICE_DEFAULT_NAME, TEMP_CELSIUS from homeassistant.const import DEVICE_DEFAULT_NAME, UnitOfTemperature
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -71,7 +71,7 @@ async def async_setup_platform(
native_max_value=35.0, native_max_value=35.0,
native_step=1, native_step=1,
mode=NumberMode.BOX, mode=NumberMode.BOX,
unit_of_measurement=TEMP_CELSIUS, unit_of_measurement=UnitOfTemperature.CELSIUS,
), ),
] ]
) )

View File

@ -15,13 +15,11 @@ from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
ATTR_BATTERY_LEVEL, ATTR_BATTERY_LEVEL,
CONCENTRATION_PARTS_PER_MILLION, CONCENTRATION_PARTS_PER_MILLION,
ENERGY_KILO_WATT_HOUR,
ENERGY_MEGA_WATT_HOUR,
PERCENTAGE, PERCENTAGE,
POWER_WATT, UnitOfEnergy,
TEMP_CELSIUS, UnitOfPower,
VOLUME_CUBIC_FEET, UnitOfTemperature,
VOLUME_CUBIC_METERS, UnitOfVolume,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import DeviceInfo
@ -47,7 +45,7 @@ async def async_setup_platform(
15.6, 15.6,
SensorDeviceClass.TEMPERATURE, SensorDeviceClass.TEMPERATURE,
SensorStateClass.MEASUREMENT, SensorStateClass.MEASUREMENT,
TEMP_CELSIUS, UnitOfTemperature.CELSIUS,
12, 12,
), ),
DemoSensor( DemoSensor(
@ -83,7 +81,7 @@ async def async_setup_platform(
100, 100,
SensorDeviceClass.POWER, SensorDeviceClass.POWER,
SensorStateClass.MEASUREMENT, SensorStateClass.MEASUREMENT,
POWER_WATT, UnitOfPower.WATT,
None, None,
), ),
DemoSumSensor( DemoSumSensor(
@ -92,7 +90,7 @@ async def async_setup_platform(
0.5, # 6kWh / h 0.5, # 6kWh / h
SensorDeviceClass.ENERGY, SensorDeviceClass.ENERGY,
SensorStateClass.TOTAL, SensorStateClass.TOTAL,
ENERGY_KILO_WATT_HOUR, UnitOfEnergy.KILO_WATT_HOUR,
None, None,
"total_energy_kwh", "total_energy_kwh",
), ),
@ -102,7 +100,7 @@ async def async_setup_platform(
0.00025, # 0.003 MWh/h (3 kWh / h) 0.00025, # 0.003 MWh/h (3 kWh / h)
SensorDeviceClass.ENERGY, SensorDeviceClass.ENERGY,
SensorStateClass.TOTAL, SensorStateClass.TOTAL,
ENERGY_MEGA_WATT_HOUR, UnitOfEnergy.MEGA_WATT_HOUR,
None, None,
"total_energy_mwh", "total_energy_mwh",
), ),
@ -112,7 +110,7 @@ async def async_setup_platform(
0.025, # 0.30 m³/h (10.6 ft³ / h) 0.025, # 0.30 m³/h (10.6 ft³ / h)
SensorDeviceClass.GAS, SensorDeviceClass.GAS,
SensorStateClass.TOTAL, SensorStateClass.TOTAL,
VOLUME_CUBIC_METERS, UnitOfVolume.CUBIC_METERS,
None, None,
"total_gas_m3", "total_gas_m3",
), ),
@ -122,7 +120,7 @@ async def async_setup_platform(
1.0, # 12 ft³/h (0.34 m³ / h) 1.0, # 12 ft³/h (0.34 m³ / h)
SensorDeviceClass.GAS, SensorDeviceClass.GAS,
SensorStateClass.TOTAL, SensorStateClass.TOTAL,
VOLUME_CUBIC_FEET, UnitOfVolume.CUBIC_FEET,
None, None,
"total_gas_ft3", "total_gas_ft3",
), ),

View File

@ -8,7 +8,7 @@ from homeassistant.components.water_heater import (
WaterHeaterEntityFeature, WaterHeaterEntityFeature,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS, TEMP_FAHRENHEIT from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature
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 ConfigType, DiscoveryInfoType from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
@ -29,8 +29,12 @@ async def async_setup_platform(
"""Set up the Demo water_heater devices.""" """Set up the Demo water_heater devices."""
async_add_entities( async_add_entities(
[ [
DemoWaterHeater("Demo Water Heater", 119, TEMP_FAHRENHEIT, False, "eco"), DemoWaterHeater(
DemoWaterHeater("Demo Water Heater Celsius", 45, TEMP_CELSIUS, True, "eco"), "Demo Water Heater", 119, UnitOfTemperature.FAHRENHEIT, False, "eco"
),
DemoWaterHeater(
"Demo Water Heater Celsius", 45, UnitOfTemperature.CELSIUS, True, "eco"
),
] ]
) )