mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 17:27:52 +00:00
Use unit enums in demo (#83130)
This commit is contained in:
parent
90f2a54165
commit
aace084931
@ -16,14 +16,12 @@ from homeassistant.components.recorder.statistics import (
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
ENERGY_MEGA_WATT_HOUR,
|
||||
EVENT_HOMEASSISTANT_START,
|
||||
SOUND_PRESSURE_DB,
|
||||
TEMP_CELSIUS,
|
||||
VOLUME_CUBIC_FEET,
|
||||
VOLUME_CUBIC_METERS,
|
||||
Platform,
|
||||
UnitOfEnergy,
|
||||
UnitOfTemperature,
|
||||
UnitOfVolume,
|
||||
)
|
||||
import homeassistant.core as ha
|
||||
from homeassistant.core import Event, HomeAssistant
|
||||
@ -306,7 +304,7 @@ async def _insert_statistics(hass: HomeAssistant) -> None:
|
||||
"source": DOMAIN,
|
||||
"name": "Outdoor temperature",
|
||||
"statistic_id": f"{DOMAIN}:temperature_outdoor",
|
||||
"unit_of_measurement": TEMP_CELSIUS,
|
||||
"unit_of_measurement": UnitOfTemperature.CELSIUS,
|
||||
"has_mean": True,
|
||||
"has_sum": False,
|
||||
}
|
||||
@ -319,7 +317,7 @@ async def _insert_statistics(hass: HomeAssistant) -> None:
|
||||
"source": DOMAIN,
|
||||
"name": "Energy consumption 1",
|
||||
"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_sum": True,
|
||||
}
|
||||
@ -331,7 +329,7 @@ async def _insert_statistics(hass: HomeAssistant) -> None:
|
||||
"source": DOMAIN,
|
||||
"name": "Energy consumption 2",
|
||||
"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_sum": True,
|
||||
}
|
||||
@ -345,7 +343,7 @@ async def _insert_statistics(hass: HomeAssistant) -> None:
|
||||
"source": DOMAIN,
|
||||
"name": "Gas consumption 1",
|
||||
"statistic_id": f"{DOMAIN}:gas_consumption_m3",
|
||||
"unit_of_measurement": VOLUME_CUBIC_METERS,
|
||||
"unit_of_measurement": UnitOfVolume.CUBIC_METERS,
|
||||
"has_mean": False,
|
||||
"has_sum": True,
|
||||
}
|
||||
@ -359,7 +357,7 @@ async def _insert_statistics(hass: HomeAssistant) -> None:
|
||||
"source": DOMAIN,
|
||||
"name": "Gas consumption 2",
|
||||
"statistic_id": f"{DOMAIN}:gas_consumption_ft3",
|
||||
"unit_of_measurement": VOLUME_CUBIC_FEET,
|
||||
"unit_of_measurement": UnitOfVolume.CUBIC_FEET,
|
||||
"has_mean": False,
|
||||
"has_sum": True,
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ from homeassistant.components.climate import (
|
||||
HVACMode,
|
||||
)
|
||||
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.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
@ -36,7 +36,7 @@ async def async_setup_platform(
|
||||
unique_id="climate_1",
|
||||
name="HeatPump",
|
||||
target_temperature=68,
|
||||
unit_of_measurement=TEMP_FAHRENHEIT,
|
||||
unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
|
||||
preset=None,
|
||||
current_temperature=77,
|
||||
fan_mode=None,
|
||||
@ -54,7 +54,7 @@ async def async_setup_platform(
|
||||
unique_id="climate_2",
|
||||
name="Hvac",
|
||||
target_temperature=21,
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
preset=None,
|
||||
current_temperature=22,
|
||||
fan_mode="On High",
|
||||
@ -72,7 +72,7 @@ async def async_setup_platform(
|
||||
unique_id="climate_3",
|
||||
name="Ecobee",
|
||||
target_temperature=None,
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
preset="home",
|
||||
preset_modes=["home", "eco"],
|
||||
current_temperature=23,
|
||||
|
@ -7,7 +7,7 @@ from math import cos, pi, radians, sin
|
||||
import random
|
||||
|
||||
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.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import track_time_interval
|
||||
@ -80,7 +80,7 @@ class DemoManager:
|
||||
|
||||
event_name = random.choice(EVENT_NAMES)
|
||||
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:
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from homeassistant.components.number import NumberDeviceClass, NumberEntity, NumberMode
|
||||
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.helpers.entity import DeviceInfo
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
@ -71,7 +71,7 @@ async def async_setup_platform(
|
||||
native_max_value=35.0,
|
||||
native_step=1,
|
||||
mode=NumberMode.BOX,
|
||||
unit_of_measurement=TEMP_CELSIUS,
|
||||
unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||
),
|
||||
]
|
||||
)
|
||||
|
@ -15,13 +15,11 @@ from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_BATTERY_LEVEL,
|
||||
CONCENTRATION_PARTS_PER_MILLION,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
ENERGY_MEGA_WATT_HOUR,
|
||||
PERCENTAGE,
|
||||
POWER_WATT,
|
||||
TEMP_CELSIUS,
|
||||
VOLUME_CUBIC_FEET,
|
||||
VOLUME_CUBIC_METERS,
|
||||
UnitOfEnergy,
|
||||
UnitOfPower,
|
||||
UnitOfTemperature,
|
||||
UnitOfVolume,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.entity import DeviceInfo
|
||||
@ -47,7 +45,7 @@ async def async_setup_platform(
|
||||
15.6,
|
||||
SensorDeviceClass.TEMPERATURE,
|
||||
SensorStateClass.MEASUREMENT,
|
||||
TEMP_CELSIUS,
|
||||
UnitOfTemperature.CELSIUS,
|
||||
12,
|
||||
),
|
||||
DemoSensor(
|
||||
@ -83,7 +81,7 @@ async def async_setup_platform(
|
||||
100,
|
||||
SensorDeviceClass.POWER,
|
||||
SensorStateClass.MEASUREMENT,
|
||||
POWER_WATT,
|
||||
UnitOfPower.WATT,
|
||||
None,
|
||||
),
|
||||
DemoSumSensor(
|
||||
@ -92,7 +90,7 @@ async def async_setup_platform(
|
||||
0.5, # 6kWh / h
|
||||
SensorDeviceClass.ENERGY,
|
||||
SensorStateClass.TOTAL,
|
||||
ENERGY_KILO_WATT_HOUR,
|
||||
UnitOfEnergy.KILO_WATT_HOUR,
|
||||
None,
|
||||
"total_energy_kwh",
|
||||
),
|
||||
@ -102,7 +100,7 @@ async def async_setup_platform(
|
||||
0.00025, # 0.003 MWh/h (3 kWh / h)
|
||||
SensorDeviceClass.ENERGY,
|
||||
SensorStateClass.TOTAL,
|
||||
ENERGY_MEGA_WATT_HOUR,
|
||||
UnitOfEnergy.MEGA_WATT_HOUR,
|
||||
None,
|
||||
"total_energy_mwh",
|
||||
),
|
||||
@ -112,7 +110,7 @@ async def async_setup_platform(
|
||||
0.025, # 0.30 m³/h (10.6 ft³ / h)
|
||||
SensorDeviceClass.GAS,
|
||||
SensorStateClass.TOTAL,
|
||||
VOLUME_CUBIC_METERS,
|
||||
UnitOfVolume.CUBIC_METERS,
|
||||
None,
|
||||
"total_gas_m3",
|
||||
),
|
||||
@ -122,7 +120,7 @@ async def async_setup_platform(
|
||||
1.0, # 12 ft³/h (0.34 m³ / h)
|
||||
SensorDeviceClass.GAS,
|
||||
SensorStateClass.TOTAL,
|
||||
VOLUME_CUBIC_FEET,
|
||||
UnitOfVolume.CUBIC_FEET,
|
||||
None,
|
||||
"total_gas_ft3",
|
||||
),
|
||||
|
@ -8,7 +8,7 @@ from homeassistant.components.water_heater import (
|
||||
WaterHeaterEntityFeature,
|
||||
)
|
||||
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.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
@ -29,8 +29,12 @@ async def async_setup_platform(
|
||||
"""Set up the Demo water_heater devices."""
|
||||
async_add_entities(
|
||||
[
|
||||
DemoWaterHeater("Demo Water Heater", 119, TEMP_FAHRENHEIT, False, "eco"),
|
||||
DemoWaterHeater("Demo Water Heater Celsius", 45, TEMP_CELSIUS, True, "eco"),
|
||||
DemoWaterHeater(
|
||||
"Demo Water Heater", 119, UnitOfTemperature.FAHRENHEIT, False, "eco"
|
||||
),
|
||||
DemoWaterHeater(
|
||||
"Demo Water Heater Celsius", 45, UnitOfTemperature.CELSIUS, True, "eco"
|
||||
),
|
||||
]
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user