Use UnitOfTemperature in integrations (e-h) (#84305)
This commit is contained in:
parent
d89ba40010
commit
9580c4f1ec
28 changed files with 113 additions and 87 deletions
|
@ -2,7 +2,7 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
|
||||||
from homeassistant.const import TEMP_CELSIUS
|
from homeassistant.const import 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
|
||||||
|
@ -31,7 +31,7 @@ class EcoalTempSensor(SensorEntity):
|
||||||
"""Representation of a temperature sensor using ecoal status data."""
|
"""Representation of a temperature sensor using ecoal status data."""
|
||||||
|
|
||||||
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||||
_attr_native_unit_of_measurement = TEMP_CELSIUS
|
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
|
||||||
|
|
||||||
def __init__(self, ecoal_contr, name, status_attr):
|
def __init__(self, ecoal_contr, name, status_attr):
|
||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
|
|
|
@ -16,7 +16,7 @@ from homeassistant.const import (
|
||||||
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
CONCENTRATION_MICROGRAMS_PER_CUBIC_METER,
|
||||||
CONCENTRATION_PARTS_PER_MILLION,
|
CONCENTRATION_PARTS_PER_MILLION,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
TEMP_FAHRENHEIT,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import DeviceInfo
|
from homeassistant.helpers.entity import DeviceInfo
|
||||||
|
@ -43,7 +43,7 @@ SENSOR_TYPES: tuple[EcobeeSensorEntityDescription, ...] = (
|
||||||
EcobeeSensorEntityDescription(
|
EcobeeSensorEntityDescription(
|
||||||
key="temperature",
|
key="temperature",
|
||||||
name="Temperature",
|
name="Temperature",
|
||||||
native_unit_of_measurement=TEMP_FAHRENHEIT,
|
native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
runtime_key=None,
|
runtime_key=None,
|
||||||
|
|
|
@ -13,7 +13,7 @@ from pyeconet.errors import (
|
||||||
)
|
)
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, TEMP_FAHRENHEIT, Platform
|
from homeassistant.const import CONF_EMAIL, CONF_PASSWORD, Platform, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect, dispatcher_send
|
||||||
|
@ -156,4 +156,4 @@ class EcoNetEntity(Entity):
|
||||||
@property
|
@property
|
||||||
def temperature_unit(self):
|
def temperature_unit(self):
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
return TEMP_FAHRENHEIT
|
return UnitOfTemperature.FAHRENHEIT
|
||||||
|
|
|
@ -22,7 +22,7 @@ from homeassistant.const import (
|
||||||
EVENT_HOMEASSISTANT_START,
|
EVENT_HOMEASSISTANT_START,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import Event, HomeAssistant
|
from homeassistant.core import Event, HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
@ -114,7 +114,7 @@ class EddystoneTemp(SensorEntity):
|
||||||
"""Representation of a temperature sensor."""
|
"""Representation of a temperature sensor."""
|
||||||
|
|
||||||
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||||
_attr_native_unit_of_measurement = TEMP_CELSIUS
|
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, name: str, namespace: str, instance: str) -> None:
|
def __init__(self, name: str, namespace: str, instance: str) -> None:
|
||||||
|
|
|
@ -21,8 +21,8 @@ from homeassistant.const import (
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
STATE_CLOSED,
|
STATE_CLOSED,
|
||||||
STATE_OPEN,
|
STATE_OPEN,
|
||||||
TEMP_CELSIUS,
|
|
||||||
UnitOfPower,
|
UnitOfPower,
|
||||||
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
@ -62,7 +62,7 @@ class EnOceanSensorEntityDescription(
|
||||||
SENSOR_DESC_TEMPERATURE = EnOceanSensorEntityDescription(
|
SENSOR_DESC_TEMPERATURE = EnOceanSensorEntityDescription(
|
||||||
key=SENSOR_TYPE_TEMPERATURE,
|
key=SENSOR_TYPE_TEMPERATURE,
|
||||||
name="Temperature",
|
name="Temperature",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
icon="mdi:thermometer",
|
icon="mdi:thermometer",
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
|
|
@ -9,8 +9,8 @@ from homeassistant.components.sensor import (
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
TEMP_FAHRENHEIT,
|
|
||||||
UnitOfPressure,
|
UnitOfPressure,
|
||||||
|
UnitOfTemperature,
|
||||||
UnitOfVolume,
|
UnitOfVolume,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -125,7 +125,7 @@ class FloTemperatureSensor(FloEntity, SensorEntity):
|
||||||
"""Monitors the temperature."""
|
"""Monitors the temperature."""
|
||||||
|
|
||||||
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||||
_attr_native_unit_of_measurement = TEMP_FAHRENHEIT
|
_attr_native_unit_of_measurement = UnitOfTemperature.FAHRENHEIT
|
||||||
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
_attr_state_class: SensorStateClass = SensorStateClass.MEASUREMENT
|
||||||
|
|
||||||
def __init__(self, name, device):
|
def __init__(self, name, device):
|
||||||
|
|
|
@ -23,7 +23,7 @@ from homeassistant.const import (
|
||||||
CONF_TOKEN,
|
CONF_TOKEN,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import PlatformNotReady
|
from homeassistant.exceptions import PlatformNotReady
|
||||||
|
@ -52,7 +52,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
key="tmp",
|
key="tmp",
|
||||||
name=ATTR_TEMPERATURE,
|
name=ATTR_TEMPERATURE,
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
|
|
|
@ -7,7 +7,7 @@ from homeassistant.components.sensor import (
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import LIGHT_LUX, PERCENTAGE, TEMP_CELSIUS
|
from homeassistant.const import LIGHT_LUX, PERCENTAGE, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
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
|
||||||
|
@ -27,7 +27,7 @@ STATE_CLASS_MAP = {
|
||||||
"lightSensor": None,
|
"lightSensor": None,
|
||||||
}
|
}
|
||||||
UNIT_MAP = {
|
UNIT_MAP = {
|
||||||
"temperatureSensor": TEMP_CELSIUS,
|
"temperatureSensor": UnitOfTemperature.CELSIUS,
|
||||||
"humiditySensor": PERCENTAGE,
|
"humiditySensor": PERCENTAGE,
|
||||||
"lightSensor": LIGHT_LUX,
|
"lightSensor": LIGHT_LUX,
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ from homeassistant.const import (
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
EVENT_HOMEASSISTANT_STOP,
|
EVENT_HOMEASSISTANT_STOP,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import Event, HomeAssistant
|
from homeassistant.core import Event, HomeAssistant
|
||||||
from homeassistant.exceptions import ConfigEntryAuthFailed
|
from homeassistant.exceptions import ConfigEntryAuthFailed
|
||||||
|
@ -62,7 +62,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
def _update_unique_id(entry: RegistryEntry) -> dict[str, str] | None:
|
def _update_unique_id(entry: RegistryEntry) -> dict[str, str] | None:
|
||||||
"""Update unique ID of entity entry."""
|
"""Update unique ID of entity entry."""
|
||||||
if (
|
if (
|
||||||
entry.unit_of_measurement == TEMP_CELSIUS
|
entry.unit_of_measurement == UnitOfTemperature.CELSIUS
|
||||||
and "_temperature" not in entry.unique_id
|
and "_temperature" not in entry.unique_id
|
||||||
):
|
):
|
||||||
new_unique_id = f"{entry.unique_id}_temperature"
|
new_unique_id = f"{entry.unique_id}_temperature"
|
||||||
|
|
|
@ -18,11 +18,11 @@ from homeassistant.components.sensor import (
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
TEMP_CELSIUS,
|
|
||||||
UnitOfElectricCurrent,
|
UnitOfElectricCurrent,
|
||||||
UnitOfElectricPotential,
|
UnitOfElectricPotential,
|
||||||
UnitOfEnergy,
|
UnitOfEnergy,
|
||||||
UnitOfPower,
|
UnitOfPower,
|
||||||
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
|
@ -103,7 +103,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
|
||||||
FritzSensorEntityDescription(
|
FritzSensorEntityDescription(
|
||||||
key="temperature",
|
key="temperature",
|
||||||
name="Temperature",
|
name="Temperature",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
@ -168,7 +168,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
|
||||||
FritzSensorEntityDescription(
|
FritzSensorEntityDescription(
|
||||||
key="comfort_temperature",
|
key="comfort_temperature",
|
||||||
name="Comfort Temperature",
|
name="Comfort Temperature",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
suitable=suitable_comfort_temperature,
|
suitable=suitable_comfort_temperature,
|
||||||
native_value=lambda device: device.comfort_temperature, # type: ignore[no-any-return]
|
native_value=lambda device: device.comfort_temperature, # type: ignore[no-any-return]
|
||||||
|
@ -176,7 +176,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
|
||||||
FritzSensorEntityDescription(
|
FritzSensorEntityDescription(
|
||||||
key="eco_temperature",
|
key="eco_temperature",
|
||||||
name="Eco Temperature",
|
name="Eco Temperature",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
suitable=suitable_eco_temperature,
|
suitable=suitable_eco_temperature,
|
||||||
native_value=lambda device: device.eco_temperature, # type: ignore[no-any-return]
|
native_value=lambda device: device.eco_temperature, # type: ignore[no-any-return]
|
||||||
|
@ -184,7 +184,7 @@ SENSOR_TYPES: Final[tuple[FritzSensorEntityDescription, ...]] = (
|
||||||
FritzSensorEntityDescription(
|
FritzSensorEntityDescription(
|
||||||
key="nextchange_temperature",
|
key="nextchange_temperature",
|
||||||
name="Next Scheduled Temperature",
|
name="Next Scheduled Temperature",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
suitable=suitable_nextchange_temperature,
|
suitable=suitable_nextchange_temperature,
|
||||||
native_value=lambda device: device.nextchange_temperature, # type: ignore[no-any-return]
|
native_value=lambda device: device.nextchange_temperature, # type: ignore[no-any-return]
|
||||||
|
|
|
@ -17,8 +17,8 @@ from homeassistant.const import (
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_TOKEN,
|
CONF_TOKEN,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
TEMP_CELSIUS,
|
|
||||||
Platform,
|
Platform,
|
||||||
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
from homeassistant.core import HomeAssistant, ServiceCall, callback
|
||||||
from homeassistant.helpers import config_validation as cv, entity_registry as er
|
from homeassistant.helpers import config_validation as cv, entity_registry as er
|
||||||
|
@ -356,7 +356,7 @@ class GeniusHeatingZone(GeniusZone):
|
||||||
@property
|
@property
|
||||||
def temperature_unit(self) -> str:
|
def temperature_unit(self) -> str:
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
return TEMP_CELSIUS
|
return UnitOfTemperature.CELSIUS
|
||||||
|
|
||||||
async def async_set_temperature(self, **kwargs) -> None:
|
async def async_set_temperature(self, **kwargs) -> None:
|
||||||
"""Set a new target temperature for this zone."""
|
"""Set a new target temperature for this zone."""
|
||||||
|
|
|
@ -16,9 +16,9 @@ from homeassistant.const import (
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
REVOLUTIONS_PER_MINUTE,
|
REVOLUTIONS_PER_MINUTE,
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
TEMP_CELSIUS,
|
|
||||||
Platform,
|
Platform,
|
||||||
UnitOfInformation,
|
UnitOfInformation,
|
||||||
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import entity_registry
|
from homeassistant.helpers import entity_registry
|
||||||
|
@ -171,7 +171,7 @@ SENSOR_TYPES: tuple[GlancesSensorEntityDescription, ...] = (
|
||||||
key="temperature_core",
|
key="temperature_core",
|
||||||
type="sensors",
|
type="sensors",
|
||||||
name_suffix="Temperature",
|
name_suffix="Temperature",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
|
@ -179,7 +179,7 @@ SENSOR_TYPES: tuple[GlancesSensorEntityDescription, ...] = (
|
||||||
key="temperature_hdd",
|
key="temperature_hdd",
|
||||||
type="sensors",
|
type="sensors",
|
||||||
name_suffix="Temperature",
|
name_suffix="Temperature",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
|
|
|
@ -13,11 +13,11 @@ from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
SIGNAL_STRENGTH_DECIBELS,
|
SIGNAL_STRENGTH_DECIBELS,
|
||||||
TEMP_CELSIUS,
|
|
||||||
UnitOfElectricCurrent,
|
UnitOfElectricCurrent,
|
||||||
UnitOfElectricPotential,
|
UnitOfElectricPotential,
|
||||||
UnitOfEnergy,
|
UnitOfEnergy,
|
||||||
UnitOfPower,
|
UnitOfPower,
|
||||||
|
UnitOfTemperature,
|
||||||
UnitOfTime,
|
UnitOfTime,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -97,7 +97,7 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
||||||
key="temperature",
|
key="temperature",
|
||||||
name="Temperature",
|
name="Temperature",
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
),
|
),
|
||||||
SensorEntityDescription(
|
SensorEntityDescription(
|
||||||
|
|
|
@ -11,7 +11,7 @@ from homeassistant.components.sensor import (
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import PERCENTAGE, TEMP_CELSIUS
|
from homeassistant.const import PERCENTAGE, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
@ -96,7 +96,7 @@ class DoorSensorTemperature(DoorSensorEntity):
|
||||||
|
|
||||||
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||||
_attr_state_class = SensorStateClass.MEASUREMENT
|
_attr_state_class = SensorStateClass.MEASUREMENT
|
||||||
_attr_native_unit_of_measurement = TEMP_CELSIUS
|
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -63,8 +63,7 @@ from homeassistant.const import (
|
||||||
STATE_STANDBY,
|
STATE_STANDBY,
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
TEMP_FAHRENHEIT,
|
|
||||||
)
|
)
|
||||||
from homeassistant.core import DOMAIN as HA_DOMAIN
|
from homeassistant.core import DOMAIN as HA_DOMAIN
|
||||||
from homeassistant.helpers.network import get_url
|
from homeassistant.helpers.network import get_url
|
||||||
|
@ -175,7 +174,7 @@ def register_trait(trait):
|
||||||
|
|
||||||
def _google_temp_unit(units):
|
def _google_temp_unit(units):
|
||||||
"""Return Google temperature unit."""
|
"""Return Google temperature unit."""
|
||||||
if units == TEMP_FAHRENHEIT:
|
if units == UnitOfTemperature.FAHRENHEIT:
|
||||||
return "F"
|
return "F"
|
||||||
return "C"
|
return "C"
|
||||||
|
|
||||||
|
@ -845,7 +844,10 @@ class TemperatureControlTrait(_Trait):
|
||||||
current_temp = self.state.state
|
current_temp = self.state.state
|
||||||
if current_temp not in (STATE_UNKNOWN, STATE_UNAVAILABLE):
|
if current_temp not in (STATE_UNKNOWN, STATE_UNAVAILABLE):
|
||||||
temp = round(
|
temp = round(
|
||||||
TemperatureConverter.convert(float(current_temp), unit, TEMP_CELSIUS), 1
|
TemperatureConverter.convert(
|
||||||
|
float(current_temp), unit, UnitOfTemperature.CELSIUS
|
||||||
|
),
|
||||||
|
1,
|
||||||
)
|
)
|
||||||
response["temperatureSetpointCelsius"] = temp
|
response["temperatureSetpointCelsius"] = temp
|
||||||
response["temperatureAmbientCelsius"] = temp
|
response["temperatureAmbientCelsius"] = temp
|
||||||
|
@ -951,7 +953,10 @@ class TemperatureSettingTrait(_Trait):
|
||||||
current_temp = attrs.get(climate.ATTR_CURRENT_TEMPERATURE)
|
current_temp = attrs.get(climate.ATTR_CURRENT_TEMPERATURE)
|
||||||
if current_temp is not None:
|
if current_temp is not None:
|
||||||
response["thermostatTemperatureAmbient"] = round(
|
response["thermostatTemperatureAmbient"] = round(
|
||||||
TemperatureConverter.convert(current_temp, unit, TEMP_CELSIUS), 1
|
TemperatureConverter.convert(
|
||||||
|
current_temp, unit, UnitOfTemperature.CELSIUS
|
||||||
|
),
|
||||||
|
1,
|
||||||
)
|
)
|
||||||
|
|
||||||
current_humidity = attrs.get(climate.ATTR_CURRENT_HUMIDITY)
|
current_humidity = attrs.get(climate.ATTR_CURRENT_HUMIDITY)
|
||||||
|
@ -962,27 +967,37 @@ class TemperatureSettingTrait(_Trait):
|
||||||
if supported & climate.SUPPORT_TARGET_TEMPERATURE_RANGE:
|
if supported & climate.SUPPORT_TARGET_TEMPERATURE_RANGE:
|
||||||
response["thermostatTemperatureSetpointHigh"] = round(
|
response["thermostatTemperatureSetpointHigh"] = round(
|
||||||
TemperatureConverter.convert(
|
TemperatureConverter.convert(
|
||||||
attrs[climate.ATTR_TARGET_TEMP_HIGH], unit, TEMP_CELSIUS
|
attrs[climate.ATTR_TARGET_TEMP_HIGH],
|
||||||
|
unit,
|
||||||
|
UnitOfTemperature.CELSIUS,
|
||||||
),
|
),
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
response["thermostatTemperatureSetpointLow"] = round(
|
response["thermostatTemperatureSetpointLow"] = round(
|
||||||
TemperatureConverter.convert(
|
TemperatureConverter.convert(
|
||||||
attrs[climate.ATTR_TARGET_TEMP_LOW], unit, TEMP_CELSIUS
|
attrs[climate.ATTR_TARGET_TEMP_LOW],
|
||||||
|
unit,
|
||||||
|
UnitOfTemperature.CELSIUS,
|
||||||
),
|
),
|
||||||
1,
|
1,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
if (target_temp := attrs.get(ATTR_TEMPERATURE)) is not None:
|
if (target_temp := attrs.get(ATTR_TEMPERATURE)) is not None:
|
||||||
target_temp = round(
|
target_temp = round(
|
||||||
TemperatureConverter.convert(target_temp, unit, TEMP_CELSIUS), 1
|
TemperatureConverter.convert(
|
||||||
|
target_temp, unit, UnitOfTemperature.CELSIUS
|
||||||
|
),
|
||||||
|
1,
|
||||||
)
|
)
|
||||||
response["thermostatTemperatureSetpointHigh"] = target_temp
|
response["thermostatTemperatureSetpointHigh"] = target_temp
|
||||||
response["thermostatTemperatureSetpointLow"] = target_temp
|
response["thermostatTemperatureSetpointLow"] = target_temp
|
||||||
else:
|
else:
|
||||||
if (target_temp := attrs.get(ATTR_TEMPERATURE)) is not None:
|
if (target_temp := attrs.get(ATTR_TEMPERATURE)) is not None:
|
||||||
response["thermostatTemperatureSetpoint"] = round(
|
response["thermostatTemperatureSetpoint"] = round(
|
||||||
TemperatureConverter.convert(target_temp, unit, TEMP_CELSIUS), 1
|
TemperatureConverter.convert(
|
||||||
|
target_temp, unit, UnitOfTemperature.CELSIUS
|
||||||
|
),
|
||||||
|
1,
|
||||||
)
|
)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
@ -996,9 +1011,9 @@ class TemperatureSettingTrait(_Trait):
|
||||||
|
|
||||||
if command == COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT:
|
if command == COMMAND_THERMOSTAT_TEMPERATURE_SETPOINT:
|
||||||
temp = TemperatureConverter.convert(
|
temp = TemperatureConverter.convert(
|
||||||
params["thermostatTemperatureSetpoint"], TEMP_CELSIUS, unit
|
params["thermostatTemperatureSetpoint"], UnitOfTemperature.CELSIUS, unit
|
||||||
)
|
)
|
||||||
if unit == TEMP_FAHRENHEIT:
|
if unit == UnitOfTemperature.FAHRENHEIT:
|
||||||
temp = round(temp)
|
temp = round(temp)
|
||||||
|
|
||||||
if temp < min_temp or temp > max_temp:
|
if temp < min_temp or temp > max_temp:
|
||||||
|
@ -1017,9 +1032,11 @@ class TemperatureSettingTrait(_Trait):
|
||||||
|
|
||||||
elif command == COMMAND_THERMOSTAT_TEMPERATURE_SET_RANGE:
|
elif command == COMMAND_THERMOSTAT_TEMPERATURE_SET_RANGE:
|
||||||
temp_high = TemperatureConverter.convert(
|
temp_high = TemperatureConverter.convert(
|
||||||
params["thermostatTemperatureSetpointHigh"], TEMP_CELSIUS, unit
|
params["thermostatTemperatureSetpointHigh"],
|
||||||
|
UnitOfTemperature.CELSIUS,
|
||||||
|
unit,
|
||||||
)
|
)
|
||||||
if unit == TEMP_FAHRENHEIT:
|
if unit == UnitOfTemperature.FAHRENHEIT:
|
||||||
temp_high = round(temp_high)
|
temp_high = round(temp_high)
|
||||||
|
|
||||||
if temp_high < min_temp or temp_high > max_temp:
|
if temp_high < min_temp or temp_high > max_temp:
|
||||||
|
@ -1032,9 +1049,11 @@ class TemperatureSettingTrait(_Trait):
|
||||||
)
|
)
|
||||||
|
|
||||||
temp_low = TemperatureConverter.convert(
|
temp_low = TemperatureConverter.convert(
|
||||||
params["thermostatTemperatureSetpointLow"], TEMP_CELSIUS, unit
|
params["thermostatTemperatureSetpointLow"],
|
||||||
|
UnitOfTemperature.CELSIUS,
|
||||||
|
unit,
|
||||||
)
|
)
|
||||||
if unit == TEMP_FAHRENHEIT:
|
if unit == UnitOfTemperature.FAHRENHEIT:
|
||||||
temp_low = round(temp_low)
|
temp_low = round(temp_low)
|
||||||
|
|
||||||
if temp_low < min_temp or temp_low > max_temp:
|
if temp_low < min_temp or temp_low > max_temp:
|
||||||
|
|
|
@ -22,7 +22,7 @@ from homeassistant.components.sensor import (
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||||
TEMP_CELSIUS,
|
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
|
||||||
|
@ -34,7 +34,7 @@ SENSOR_DESCRIPTIONS = {
|
||||||
(DeviceClass.TEMPERATURE, Units.TEMP_CELSIUS): SensorEntityDescription(
|
(DeviceClass.TEMPERATURE, Units.TEMP_CELSIUS): SensorEntityDescription(
|
||||||
key=f"{DeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}",
|
key=f"{DeviceClass.TEMPERATURE}_{Units.TEMP_CELSIUS}",
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
(DeviceClass.HUMIDITY, Units.PERCENTAGE): SensorEntityDescription(
|
(DeviceClass.HUMIDITY, Units.PERCENTAGE): SensorEntityDescription(
|
||||||
|
|
|
@ -3,12 +3,12 @@ from __future__ import annotations
|
||||||
|
|
||||||
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
|
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
TEMP_CELSIUS,
|
|
||||||
UnitOfElectricCurrent,
|
UnitOfElectricCurrent,
|
||||||
UnitOfElectricPotential,
|
UnitOfElectricPotential,
|
||||||
UnitOfEnergy,
|
UnitOfEnergy,
|
||||||
UnitOfFrequency,
|
UnitOfFrequency,
|
||||||
UnitOfPower,
|
UnitOfPower,
|
||||||
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .sensor_entity_description import GrowattSensorEntityDescription
|
from .sensor_entity_description import GrowattSensorEntityDescription
|
||||||
|
@ -155,7 +155,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
|
||||||
key="inverter_ipm_temperature",
|
key="inverter_ipm_temperature",
|
||||||
name="Intelligent Power Management temperature",
|
name="Intelligent Power Management temperature",
|
||||||
api_key="ipmTemperature",
|
api_key="ipmTemperature",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
precision=1,
|
precision=1,
|
||||||
),
|
),
|
||||||
|
@ -163,7 +163,7 @@ INVERTER_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
|
||||||
key="inverter_temperature",
|
key="inverter_temperature",
|
||||||
name="Temperature",
|
name="Temperature",
|
||||||
api_key="temperature",
|
api_key="temperature",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
precision=1,
|
precision=1,
|
||||||
),
|
),
|
||||||
|
|
|
@ -8,12 +8,12 @@ from __future__ import annotations
|
||||||
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
|
from homeassistant.components.sensor import SensorDeviceClass, SensorStateClass
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
TEMP_CELSIUS,
|
|
||||||
UnitOfElectricCurrent,
|
UnitOfElectricCurrent,
|
||||||
UnitOfElectricPotential,
|
UnitOfElectricPotential,
|
||||||
UnitOfEnergy,
|
UnitOfEnergy,
|
||||||
UnitOfFrequency,
|
UnitOfFrequency,
|
||||||
UnitOfPower,
|
UnitOfPower,
|
||||||
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .sensor_entity_description import GrowattSensorEntityDescription
|
from .sensor_entity_description import GrowattSensorEntityDescription
|
||||||
|
@ -255,7 +255,7 @@ TLX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
|
||||||
key="tlx_temperature_1",
|
key="tlx_temperature_1",
|
||||||
name="Temperature 1",
|
name="Temperature 1",
|
||||||
api_key="temp1",
|
api_key="temp1",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
precision=1,
|
precision=1,
|
||||||
),
|
),
|
||||||
|
@ -263,7 +263,7 @@ TLX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
|
||||||
key="tlx_temperature_2",
|
key="tlx_temperature_2",
|
||||||
name="Temperature 2",
|
name="Temperature 2",
|
||||||
api_key="temp2",
|
api_key="temp2",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
precision=1,
|
precision=1,
|
||||||
),
|
),
|
||||||
|
@ -271,7 +271,7 @@ TLX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
|
||||||
key="tlx_temperature_3",
|
key="tlx_temperature_3",
|
||||||
name="Temperature 3",
|
name="Temperature 3",
|
||||||
api_key="temp3",
|
api_key="temp3",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
precision=1,
|
precision=1,
|
||||||
),
|
),
|
||||||
|
@ -279,7 +279,7 @@ TLX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
|
||||||
key="tlx_temperature_4",
|
key="tlx_temperature_4",
|
||||||
name="Temperature 4",
|
name="Temperature 4",
|
||||||
api_key="temp4",
|
api_key="temp4",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
precision=1,
|
precision=1,
|
||||||
),
|
),
|
||||||
|
@ -287,7 +287,7 @@ TLX_SENSOR_TYPES: tuple[GrowattSensorEntityDescription, ...] = (
|
||||||
key="tlx_temperature_5",
|
key="tlx_temperature_5",
|
||||||
name="Temperature 5",
|
name="Temperature 5",
|
||||||
api_key="temp5",
|
api_key="temp5",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
precision=1,
|
precision=1,
|
||||||
),
|
),
|
||||||
|
|
|
@ -10,7 +10,7 @@ from homeassistant.components.sensor import (
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import TEMP_FAHRENHEIT, UnitOfElectricPotential, UnitOfTime
|
from homeassistant.const import UnitOfElectricPotential, UnitOfTemperature, UnitOfTime
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
|
@ -54,7 +54,7 @@ PAIRED_SENSOR_DESCRIPTIONS = (
|
||||||
key=SENSOR_KIND_TEMPERATURE,
|
key=SENSOR_KIND_TEMPERATURE,
|
||||||
name="Temperature",
|
name="Temperature",
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
native_unit_of_measurement=TEMP_FAHRENHEIT,
|
native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -63,7 +63,7 @@ VALVE_CONTROLLER_DESCRIPTIONS = (
|
||||||
key=SENSOR_KIND_TEMPERATURE,
|
key=SENSOR_KIND_TEMPERATURE,
|
||||||
name="Temperature",
|
name="Temperature",
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
native_unit_of_measurement=TEMP_FAHRENHEIT,
|
native_unit_of_measurement=UnitOfTemperature.FAHRENHEIT,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
api_category=API_SYSTEM_ONBOARD_SENSOR_STATUS,
|
api_category=API_SYSTEM_ONBOARD_SENSOR_STATUS,
|
||||||
),
|
),
|
||||||
|
|
|
@ -18,8 +18,7 @@ from homeassistant.const import (
|
||||||
CONF_HOST,
|
CONF_HOST,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
TEMP_FAHRENHEIT,
|
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
@ -99,9 +98,9 @@ class HddTempSensor(SensorEntity):
|
||||||
self._details = self.hddtemp.data[self.disk].split("|")
|
self._details = self.hddtemp.data[self.disk].split("|")
|
||||||
self._attr_native_value = self._details[2]
|
self._attr_native_value = self._details[2]
|
||||||
if self._details is not None and self._details[3] == "F":
|
if self._details is not None and self._details[3] == "F":
|
||||||
self._attr_native_unit_of_measurement = TEMP_FAHRENHEIT
|
self._attr_native_unit_of_measurement = UnitOfTemperature.FAHRENHEIT
|
||||||
else:
|
else:
|
||||||
self._attr_native_unit_of_measurement = TEMP_CELSIUS
|
self._attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
|
||||||
else:
|
else:
|
||||||
self._attr_native_value = None
|
self._attr_native_value = None
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,7 @@ from homeassistant.const import (
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
TEMP_FAHRENHEIT,
|
|
||||||
__version__,
|
__version__,
|
||||||
)
|
)
|
||||||
from homeassistant.core import (
|
from homeassistant.core import (
|
||||||
|
@ -184,8 +183,8 @@ def get_accessory( # noqa: C901
|
||||||
unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT)
|
||||||
|
|
||||||
if device_class == SensorDeviceClass.TEMPERATURE or unit in (
|
if device_class == SensorDeviceClass.TEMPERATURE or unit in (
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature.CELSIUS,
|
||||||
TEMP_FAHRENHEIT,
|
UnitOfTemperature.FAHRENHEIT,
|
||||||
):
|
):
|
||||||
a_type = "TemperatureSensor"
|
a_type = "TemperatureSensor"
|
||||||
elif device_class == SensorDeviceClass.HUMIDITY and unit == PERCENTAGE:
|
elif device_class == SensorDeviceClass.HUMIDITY and unit == PERCENTAGE:
|
||||||
|
|
|
@ -13,7 +13,7 @@ from homeassistant.const import (
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
STATE_HOME,
|
STATE_HOME,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
|
|
||||||
|
@ -124,7 +124,9 @@ class TemperatureSensor(HomeAccessory):
|
||||||
@callback
|
@callback
|
||||||
def async_update_state(self, new_state):
|
def async_update_state(self, new_state):
|
||||||
"""Update temperature after state changed."""
|
"""Update temperature after state changed."""
|
||||||
unit = new_state.attributes.get(ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS)
|
unit = new_state.attributes.get(
|
||||||
|
ATTR_UNIT_OF_MEASUREMENT, UnitOfTemperature.CELSIUS
|
||||||
|
)
|
||||||
if (temperature := convert_to_float(new_state.state)) is not None:
|
if (temperature := convert_to_float(new_state.state)) is not None:
|
||||||
temperature = temperature_to_homekit(temperature, unit)
|
temperature = temperature_to_homekit(temperature, unit)
|
||||||
self.char_temp.set_value(temperature)
|
self.char_temp.set_value(temperature)
|
||||||
|
|
|
@ -53,8 +53,7 @@ from homeassistant.const import (
|
||||||
ATTR_SUPPORTED_FEATURES,
|
ATTR_SUPPORTED_FEATURES,
|
||||||
ATTR_TEMPERATURE,
|
ATTR_TEMPERATURE,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
TEMP_FAHRENHEIT,
|
|
||||||
)
|
)
|
||||||
from homeassistant.core import State, callback
|
from homeassistant.core import State, callback
|
||||||
from homeassistant.util.percentage import (
|
from homeassistant.util.percentage import (
|
||||||
|
@ -98,7 +97,7 @@ DEFAULT_HVAC_MODES = [
|
||||||
]
|
]
|
||||||
|
|
||||||
HC_HOMEKIT_VALID_MODES_WATER_HEATER = {"Heat": 1}
|
HC_HOMEKIT_VALID_MODES_WATER_HEATER = {"Heat": 1}
|
||||||
UNIT_HASS_TO_HOMEKIT = {TEMP_CELSIUS: 0, TEMP_FAHRENHEIT: 1}
|
UNIT_HASS_TO_HOMEKIT = {UnitOfTemperature.CELSIUS: 0, UnitOfTemperature.FAHRENHEIT: 1}
|
||||||
|
|
||||||
HC_HEAT_COOL_OFF = 0
|
HC_HEAT_COOL_OFF = 0
|
||||||
HC_HEAT_COOL_HEAT = 1
|
HC_HEAT_COOL_HEAT = 1
|
||||||
|
|
|
@ -35,7 +35,7 @@ from homeassistant.const import (
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
CONF_PORT,
|
CONF_PORT,
|
||||||
CONF_TYPE,
|
CONF_TYPE,
|
||||||
TEMP_CELSIUS,
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import Event, HomeAssistant, State, callback, split_entity_id
|
from homeassistant.core import Event, HomeAssistant, State, callback, split_entity_id
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
|
@ -391,12 +391,20 @@ def cleanup_name_for_homekit(name: str | None) -> str:
|
||||||
|
|
||||||
def temperature_to_homekit(temperature: float | int, unit: str) -> float:
|
def temperature_to_homekit(temperature: float | int, unit: str) -> float:
|
||||||
"""Convert temperature to Celsius for HomeKit."""
|
"""Convert temperature to Celsius for HomeKit."""
|
||||||
return round(TemperatureConverter.convert(temperature, unit, TEMP_CELSIUS), 1)
|
return round(
|
||||||
|
TemperatureConverter.convert(temperature, unit, UnitOfTemperature.CELSIUS), 1
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def temperature_to_states(temperature: float | int, unit: str) -> float:
|
def temperature_to_states(temperature: float | int, unit: str) -> float:
|
||||||
"""Convert temperature back from Celsius to Home Assistant unit."""
|
"""Convert temperature back from Celsius to Home Assistant unit."""
|
||||||
return round(TemperatureConverter.convert(temperature, TEMP_CELSIUS, unit) * 2) / 2
|
return (
|
||||||
|
round(
|
||||||
|
TemperatureConverter.convert(temperature, UnitOfTemperature.CELSIUS, unit)
|
||||||
|
* 2
|
||||||
|
)
|
||||||
|
/ 2
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def density_to_air_quality(density: float) -> int:
|
def density_to_air_quality(density: float) -> int:
|
||||||
|
|
|
@ -26,7 +26,6 @@ from homeassistant.const import (
|
||||||
LIGHT_LUX,
|
LIGHT_LUX,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
|
||||||
TEMP_CELSIUS,
|
|
||||||
Platform,
|
Platform,
|
||||||
UnitOfElectricCurrent,
|
UnitOfElectricCurrent,
|
||||||
UnitOfElectricPotential,
|
UnitOfElectricPotential,
|
||||||
|
@ -34,6 +33,7 @@ from homeassistant.const import (
|
||||||
UnitOfPower,
|
UnitOfPower,
|
||||||
UnitOfPressure,
|
UnitOfPressure,
|
||||||
UnitOfSoundPressure,
|
UnitOfSoundPressure,
|
||||||
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
|
@ -230,7 +230,7 @@ SIMPLE_SENSOR: dict[str, HomeKitSensorEntityDescription] = {
|
||||||
name="Current Temperature",
|
name="Current Temperature",
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
# This sensor is only for temperature characteristics that are not part
|
# This sensor is only for temperature characteristics that are not part
|
||||||
# of a temperature sensor service.
|
# of a temperature sensor service.
|
||||||
probe=(lambda char: char.service.type != ServicesTypes.TEMPERATURE_SENSOR),
|
probe=(lambda char: char.service.type != ServicesTypes.TEMPERATURE_SENSOR),
|
||||||
|
@ -380,7 +380,7 @@ class HomeKitTemperatureSensor(HomeKitSensor):
|
||||||
"""Representation of a Homekit temperature sensor."""
|
"""Representation of a Homekit temperature sensor."""
|
||||||
|
|
||||||
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||||
_attr_native_unit_of_measurement = TEMP_CELSIUS
|
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
|
||||||
|
|
||||||
def get_characteristic_types(self) -> list[str]:
|
def get_characteristic_types(self) -> list[str]:
|
||||||
"""Define the homekit characteristics the entity is tracking."""
|
"""Define the homekit characteristics the entity is tracking."""
|
||||||
|
|
|
@ -17,7 +17,6 @@ from homeassistant.const import (
|
||||||
DEGREE,
|
DEGREE,
|
||||||
LIGHT_LUX,
|
LIGHT_LUX,
|
||||||
PERCENTAGE,
|
PERCENTAGE,
|
||||||
TEMP_CELSIUS,
|
|
||||||
UnitOfElectricCurrent,
|
UnitOfElectricCurrent,
|
||||||
UnitOfElectricPotential,
|
UnitOfElectricPotential,
|
||||||
UnitOfEnergy,
|
UnitOfEnergy,
|
||||||
|
@ -26,6 +25,7 @@ from homeassistant.const import (
|
||||||
UnitOfPrecipitationDepth,
|
UnitOfPrecipitationDepth,
|
||||||
UnitOfPressure,
|
UnitOfPressure,
|
||||||
UnitOfSpeed,
|
UnitOfSpeed,
|
||||||
|
UnitOfTemperature,
|
||||||
UnitOfVolume,
|
UnitOfVolume,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
@ -63,13 +63,13 @@ SENSOR_DESCRIPTIONS: dict[str, SensorEntityDescription] = {
|
||||||
),
|
),
|
||||||
"ACTUAL_TEMPERATURE": SensorEntityDescription(
|
"ACTUAL_TEMPERATURE": SensorEntityDescription(
|
||||||
key="ACTUAL_TEMPERATURE",
|
key="ACTUAL_TEMPERATURE",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
"TEMPERATURE": SensorEntityDescription(
|
"TEMPERATURE": SensorEntityDescription(
|
||||||
key="TEMPERATURE",
|
key="TEMPERATURE",
|
||||||
native_unit_of_measurement=TEMP_CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
state_class=SensorStateClass.MEASUREMENT,
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
),
|
),
|
||||||
|
|
|
@ -11,7 +11,7 @@ from homeassistant.components.sensor import (
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.const import LIGHT_LUX, PERCENTAGE, TEMP_CELSIUS
|
from homeassistant.const import LIGHT_LUX, PERCENTAGE, UnitOfTemperature
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
|
|
||||||
from ..const import DOMAIN as HUE_DOMAIN
|
from ..const import DOMAIN as HUE_DOMAIN
|
||||||
|
@ -76,7 +76,7 @@ class HueTemperature(GenericHueGaugeSensorEntity):
|
||||||
|
|
||||||
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||||
_attr_state_class = SensorStateClass.MEASUREMENT
|
_attr_state_class = SensorStateClass.MEASUREMENT
|
||||||
_attr_native_unit_of_measurement = TEMP_CELSIUS
|
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
|
|
|
@ -23,7 +23,7 @@ from homeassistant.components.sensor import (
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import LIGHT_LUX, PERCENTAGE, TEMP_CELSIUS
|
from homeassistant.const import LIGHT_LUX, PERCENTAGE, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.entity import EntityCategory
|
from homeassistant.helpers.entity import EntityCategory
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
@ -96,7 +96,7 @@ class HueSensorBase(HueBaseEntity, SensorEntity):
|
||||||
class HueTemperatureSensor(HueSensorBase):
|
class HueTemperatureSensor(HueSensorBase):
|
||||||
"""Representation of a Hue Temperature sensor."""
|
"""Representation of a Hue Temperature sensor."""
|
||||||
|
|
||||||
_attr_native_unit_of_measurement = TEMP_CELSIUS
|
_attr_native_unit_of_measurement = UnitOfTemperature.CELSIUS
|
||||||
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
_attr_device_class = SensorDeviceClass.TEMPERATURE
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue