Ensure humidity is still exported to HomeKit when it is read-only (#87051)
* Ensure humidity is still exported to HomeKit when is cannot be set We would only send humidity to HomeKit if the device supported changing the humidity * remove unrelated changes
This commit is contained in:
parent
be73e43989
commit
faf79d0b50
2 changed files with 32 additions and 2 deletions
|
@ -188,8 +188,14 @@ class Thermostat(HomeAccessory):
|
|||
(CHAR_COOLING_THRESHOLD_TEMPERATURE, CHAR_HEATING_THRESHOLD_TEMPERATURE)
|
||||
)
|
||||
|
||||
if (
|
||||
ATTR_CURRENT_HUMIDITY in attributes
|
||||
or features & ClimateEntityFeature.TARGET_HUMIDITY
|
||||
):
|
||||
self.chars.append(CHAR_CURRENT_HUMIDITY)
|
||||
|
||||
if features & ClimateEntityFeature.TARGET_HUMIDITY:
|
||||
self.chars.extend((CHAR_TARGET_HUMIDITY, CHAR_CURRENT_HUMIDITY))
|
||||
self.chars.append(CHAR_TARGET_HUMIDITY)
|
||||
|
||||
serv_thermostat = self.add_preload_service(SERV_THERMOSTAT, self.chars)
|
||||
self.set_primary_service(serv_thermostat)
|
||||
|
@ -253,7 +259,6 @@ class Thermostat(HomeAccessory):
|
|||
properties={PROP_MIN_VALUE: hc_min_temp, PROP_MAX_VALUE: hc_max_temp},
|
||||
)
|
||||
self.char_target_humidity = None
|
||||
self.char_current_humidity = None
|
||||
if CHAR_TARGET_HUMIDITY in self.chars:
|
||||
self.char_target_humidity = serv_thermostat.configure_char(
|
||||
CHAR_TARGET_HUMIDITY,
|
||||
|
@ -265,6 +270,8 @@ class Thermostat(HomeAccessory):
|
|||
# of 0-80%
|
||||
properties={PROP_MIN_VALUE: min_humidity},
|
||||
)
|
||||
self.char_current_humidity = None
|
||||
if CHAR_CURRENT_HUMIDITY in self.chars:
|
||||
self.char_current_humidity = serv_thermostat.configure_char(
|
||||
CHAR_CURRENT_HUMIDITY, value=50
|
||||
)
|
||||
|
|
|
@ -742,6 +742,29 @@ async def test_thermostat_humidity(hass, hk_driver, events):
|
|||
assert events[-1].data[ATTR_VALUE] == "35%"
|
||||
|
||||
|
||||
async def test_thermostat_humidity_with_target_humidity(hass, hk_driver, events):
|
||||
"""Test if accessory and HA are updated accordingly with humidity without target hudmidity.
|
||||
|
||||
This test is for thermostats that do not support target humidity but
|
||||
have a current humidity sensor.
|
||||
"""
|
||||
entity_id = "climate.test"
|
||||
|
||||
# support_auto = True
|
||||
hass.states.async_set(entity_id, HVACMode.OFF, {ATTR_CURRENT_HUMIDITY: 40})
|
||||
await hass.async_block_till_done()
|
||||
acc = Thermostat(hass, hk_driver, "Climate", entity_id, 1, None)
|
||||
hk_driver.add_accessory(acc)
|
||||
|
||||
await acc.run()
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert acc.char_current_humidity.value == 40
|
||||
hass.states.async_set(entity_id, HVACMode.HEAT_COOL, {ATTR_CURRENT_HUMIDITY: 65})
|
||||
await hass.async_block_till_done()
|
||||
assert acc.char_current_humidity.value == 65
|
||||
|
||||
|
||||
async def test_thermostat_power_state(hass, hk_driver, events):
|
||||
"""Test if accessory and HA are updated accordingly."""
|
||||
entity_id = "climate.test"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue