Fix inconsistent lyric temperature unit (#98457)
parent
d5338e88f2
commit
9be532cea9
|
@ -21,7 +21,12 @@ from homeassistant.components.climate import (
|
|||
HVACMode,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import ATTR_TEMPERATURE
|
||||
from homeassistant.const import (
|
||||
ATTR_TEMPERATURE,
|
||||
PRECISION_HALVES,
|
||||
PRECISION_WHOLE,
|
||||
UnitOfTemperature,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers import entity_platform
|
||||
|
@ -113,7 +118,6 @@ async def async_setup_entry(
|
|||
),
|
||||
location,
|
||||
device,
|
||||
hass.config.units.temperature_unit,
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -140,10 +144,15 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
|||
description: ClimateEntityDescription,
|
||||
location: LyricLocation,
|
||||
device: LyricDevice,
|
||||
temperature_unit: str,
|
||||
) -> None:
|
||||
"""Initialize Honeywell Lyric climate entity."""
|
||||
self._temperature_unit = temperature_unit
|
||||
# Use the native temperature unit from the device settings
|
||||
if device.units == "Fahrenheit":
|
||||
self._attr_temperature_unit = UnitOfTemperature.FAHRENHEIT
|
||||
self._attr_precision = PRECISION_WHOLE
|
||||
else:
|
||||
self._attr_temperature_unit = UnitOfTemperature.CELSIUS
|
||||
self._attr_precision = PRECISION_HALVES
|
||||
|
||||
# Setup supported hvac modes
|
||||
self._attr_hvac_modes = [HVACMode.OFF]
|
||||
|
@ -176,11 +185,6 @@ class LyricClimate(LyricDeviceEntity, ClimateEntity):
|
|||
return SUPPORT_FLAGS_LCC
|
||||
return SUPPORT_FLAGS_TCC
|
||||
|
||||
@property
|
||||
def temperature_unit(self) -> str:
|
||||
"""Return the unit of measurement."""
|
||||
return self._temperature_unit
|
||||
|
||||
@property
|
||||
def current_temperature(self) -> float | None:
|
||||
"""Return the current temperature."""
|
||||
|
|
|
@ -17,7 +17,7 @@ from homeassistant.components.sensor import (
|
|||
SensorStateClass,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import PERCENTAGE
|
||||
from homeassistant.const import PERCENTAGE, UnitOfTemperature
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import StateType
|
||||
|
@ -76,6 +76,11 @@ async def async_setup_entry(
|
|||
for location in coordinator.data.locations:
|
||||
for device in location.devices:
|
||||
if device.indoorTemperature:
|
||||
if device.units == "Fahrenheit":
|
||||
native_temperature_unit = UnitOfTemperature.FAHRENHEIT
|
||||
else:
|
||||
native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||
|
||||
entities.append(
|
||||
LyricSensor(
|
||||
coordinator,
|
||||
|
@ -84,7 +89,7 @@ async def async_setup_entry(
|
|||
name="Indoor Temperature",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=hass.config.units.temperature_unit,
|
||||
native_unit_of_measurement=native_temperature_unit,
|
||||
value=lambda device: device.indoorTemperature,
|
||||
),
|
||||
location,
|
||||
|
@ -108,6 +113,11 @@ async def async_setup_entry(
|
|||
)
|
||||
)
|
||||
if device.outdoorTemperature:
|
||||
if device.units == "Fahrenheit":
|
||||
native_temperature_unit = UnitOfTemperature.FAHRENHEIT
|
||||
else:
|
||||
native_temperature_unit = UnitOfTemperature.CELSIUS
|
||||
|
||||
entities.append(
|
||||
LyricSensor(
|
||||
coordinator,
|
||||
|
@ -116,7 +126,7 @@ async def async_setup_entry(
|
|||
name="Outdoor Temperature",
|
||||
device_class=SensorDeviceClass.TEMPERATURE,
|
||||
state_class=SensorStateClass.MEASUREMENT,
|
||||
native_unit_of_measurement=hass.config.units.temperature_unit,
|
||||
native_unit_of_measurement=native_temperature_unit,
|
||||
value=lambda device: device.outdoorTemperature,
|
||||
),
|
||||
location,
|
||||
|
|
Loading…
Reference in New Issue