mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
fix homekit air purifier temperature sensor to convert unit (#144435)
This commit is contained in:
parent
d1b85cd452
commit
96a8902365
@ -8,7 +8,13 @@ from pyhap.const import CATEGORY_AIR_PURIFIER
|
|||||||
from pyhap.service import Service
|
from pyhap.service import Service
|
||||||
from pyhap.util import callback as pyhap_callback
|
from pyhap.util import callback as pyhap_callback
|
||||||
|
|
||||||
from homeassistant.const import STATE_ON, STATE_UNAVAILABLE, STATE_UNKNOWN
|
from homeassistant.const import (
|
||||||
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
|
STATE_ON,
|
||||||
|
STATE_UNAVAILABLE,
|
||||||
|
STATE_UNKNOWN,
|
||||||
|
UnitOfTemperature,
|
||||||
|
)
|
||||||
from homeassistant.core import (
|
from homeassistant.core import (
|
||||||
Event,
|
Event,
|
||||||
EventStateChangedData,
|
EventStateChangedData,
|
||||||
@ -43,7 +49,12 @@ from .const import (
|
|||||||
THRESHOLD_FILTER_CHANGE_NEEDED,
|
THRESHOLD_FILTER_CHANGE_NEEDED,
|
||||||
)
|
)
|
||||||
from .type_fans import ATTR_PRESET_MODE, CHAR_ROTATION_SPEED, Fan
|
from .type_fans import ATTR_PRESET_MODE, CHAR_ROTATION_SPEED, Fan
|
||||||
from .util import cleanup_name_for_homekit, convert_to_float, density_to_air_quality
|
from .util import (
|
||||||
|
cleanup_name_for_homekit,
|
||||||
|
convert_to_float,
|
||||||
|
density_to_air_quality,
|
||||||
|
temperature_to_homekit,
|
||||||
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -345,8 +356,13 @@ class AirPurifier(Fan):
|
|||||||
):
|
):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
unit = new_state.attributes.get(
|
||||||
|
ATTR_UNIT_OF_MEASUREMENT, UnitOfTemperature.CELSIUS
|
||||||
|
)
|
||||||
|
current_temperature = temperature_to_homekit(current_temperature, unit)
|
||||||
|
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"%s: Linked temperature sensor %s changed to %d",
|
"%s: Linked temperature sensor %s changed to %d °C",
|
||||||
self.entity_id,
|
self.entity_id,
|
||||||
self.linked_temperature_sensor,
|
self.linked_temperature_sensor,
|
||||||
current_temperature,
|
current_temperature,
|
||||||
|
@ -34,9 +34,11 @@ from homeassistant.const import (
|
|||||||
ATTR_DEVICE_CLASS,
|
ATTR_DEVICE_CLASS,
|
||||||
ATTR_ENTITY_ID,
|
ATTR_ENTITY_ID,
|
||||||
ATTR_SUPPORTED_FEATURES,
|
ATTR_SUPPORTED_FEATURES,
|
||||||
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
STATE_OFF,
|
STATE_OFF,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
STATE_UNAVAILABLE,
|
STATE_UNAVAILABLE,
|
||||||
|
UnitOfTemperature,
|
||||||
)
|
)
|
||||||
from homeassistant.core import Event, HomeAssistant
|
from homeassistant.core import Event, HomeAssistant
|
||||||
|
|
||||||
@ -437,6 +439,22 @@ async def test_expose_linked_sensors(
|
|||||||
assert acc.char_air_quality.value == 1
|
assert acc.char_air_quality.value == 1
|
||||||
assert len(broker.mock_calls) == 0
|
assert len(broker.mock_calls) == 0
|
||||||
|
|
||||||
|
# Updated temperature with different unit should reflect in HomeKit
|
||||||
|
broker = MagicMock()
|
||||||
|
acc.char_current_temperature.broker = broker
|
||||||
|
hass.states.async_set(
|
||||||
|
temperature_entity_id,
|
||||||
|
60,
|
||||||
|
{
|
||||||
|
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
|
||||||
|
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.FAHRENHEIT,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert acc.char_current_temperature.value == 15.6
|
||||||
|
assert len(broker.mock_calls) == 2
|
||||||
|
broker.reset_mock()
|
||||||
|
|
||||||
# Updated temperature should reflect in HomeKit
|
# Updated temperature should reflect in HomeKit
|
||||||
broker = MagicMock()
|
broker = MagicMock()
|
||||||
acc.char_current_temperature.broker = broker
|
acc.char_current_temperature.broker = broker
|
||||||
|
Loading…
x
Reference in New Issue
Block a user