mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Remove HomeKit event guards (#54343)
This commit is contained in:
parent
c07b1423ee
commit
dcf4eb5e0d
@ -178,18 +178,11 @@ class GarageDoorOpener(HomeAccessory):
|
|||||||
obstruction_detected = (
|
obstruction_detected = (
|
||||||
new_state.attributes[ATTR_OBSTRUCTION_DETECTED] is True
|
new_state.attributes[ATTR_OBSTRUCTION_DETECTED] is True
|
||||||
)
|
)
|
||||||
if self.char_obstruction_detected.value != obstruction_detected:
|
|
||||||
self.char_obstruction_detected.set_value(obstruction_detected)
|
self.char_obstruction_detected.set_value(obstruction_detected)
|
||||||
|
|
||||||
if (
|
if target_door_state is not None:
|
||||||
target_door_state is not None
|
|
||||||
and self.char_target_state.value != target_door_state
|
|
||||||
):
|
|
||||||
self.char_target_state.set_value(target_door_state)
|
self.char_target_state.set_value(target_door_state)
|
||||||
if (
|
if current_door_state is not None:
|
||||||
current_door_state is not None
|
|
||||||
and self.char_current_state.value != current_door_state
|
|
||||||
):
|
|
||||||
self.char_current_state.set_value(current_door_state)
|
self.char_current_state.set_value(current_door_state)
|
||||||
|
|
||||||
|
|
||||||
@ -260,9 +253,7 @@ class OpeningDeviceBase(HomeAccessory):
|
|||||||
# We'll have to normalize to [0,100]
|
# We'll have to normalize to [0,100]
|
||||||
current_tilt = (current_tilt / 100.0 * 180.0) - 90.0
|
current_tilt = (current_tilt / 100.0 * 180.0) - 90.0
|
||||||
current_tilt = int(current_tilt)
|
current_tilt = int(current_tilt)
|
||||||
if self.char_current_tilt.value != current_tilt:
|
|
||||||
self.char_current_tilt.set_value(current_tilt)
|
self.char_current_tilt.set_value(current_tilt)
|
||||||
if self.char_target_tilt.value != current_tilt:
|
|
||||||
self.char_target_tilt.set_value(current_tilt)
|
self.char_target_tilt.set_value(current_tilt)
|
||||||
|
|
||||||
|
|
||||||
@ -312,13 +303,10 @@ class OpeningDevice(OpeningDeviceBase, HomeAccessory):
|
|||||||
current_position = new_state.attributes.get(ATTR_CURRENT_POSITION)
|
current_position = new_state.attributes.get(ATTR_CURRENT_POSITION)
|
||||||
if isinstance(current_position, (float, int)):
|
if isinstance(current_position, (float, int)):
|
||||||
current_position = int(current_position)
|
current_position = int(current_position)
|
||||||
if self.char_current_position.value != current_position:
|
|
||||||
self.char_current_position.set_value(current_position)
|
self.char_current_position.set_value(current_position)
|
||||||
if self.char_target_position.value != current_position:
|
|
||||||
self.char_target_position.set_value(current_position)
|
self.char_target_position.set_value(current_position)
|
||||||
|
|
||||||
position_state = _hass_state_to_position_start(new_state.state)
|
position_state = _hass_state_to_position_start(new_state.state)
|
||||||
if self.char_position_state.value != position_state:
|
|
||||||
self.char_position_state.set_value(position_state)
|
self.char_position_state.set_value(position_state)
|
||||||
|
|
||||||
super().async_update_state(new_state)
|
super().async_update_state(new_state)
|
||||||
|
@ -193,7 +193,6 @@ class Fan(HomeAccessory):
|
|||||||
state = new_state.state
|
state = new_state.state
|
||||||
if state in (STATE_ON, STATE_OFF):
|
if state in (STATE_ON, STATE_OFF):
|
||||||
self._state = 1 if state == STATE_ON else 0
|
self._state = 1 if state == STATE_ON else 0
|
||||||
if self.char_active.value != self._state:
|
|
||||||
self.char_active.set_value(self._state)
|
self.char_active.set_value(self._state)
|
||||||
|
|
||||||
# Handle Direction
|
# Handle Direction
|
||||||
@ -201,7 +200,6 @@ class Fan(HomeAccessory):
|
|||||||
direction = new_state.attributes.get(ATTR_DIRECTION)
|
direction = new_state.attributes.get(ATTR_DIRECTION)
|
||||||
if direction in (DIRECTION_FORWARD, DIRECTION_REVERSE):
|
if direction in (DIRECTION_FORWARD, DIRECTION_REVERSE):
|
||||||
hk_direction = 1 if direction == DIRECTION_REVERSE else 0
|
hk_direction = 1 if direction == DIRECTION_REVERSE else 0
|
||||||
if self.char_direction.value != hk_direction:
|
|
||||||
self.char_direction.set_value(hk_direction)
|
self.char_direction.set_value(hk_direction)
|
||||||
|
|
||||||
# Handle Speed
|
# Handle Speed
|
||||||
@ -222,7 +220,7 @@ class Fan(HomeAccessory):
|
|||||||
# in order to avoid this incorrect behavior.
|
# in order to avoid this incorrect behavior.
|
||||||
if percentage == 0 and state == STATE_ON:
|
if percentage == 0 and state == STATE_ON:
|
||||||
percentage = 1
|
percentage = 1
|
||||||
if percentage is not None and self.char_speed.value != percentage:
|
if percentage is not None:
|
||||||
self.char_speed.set_value(percentage)
|
self.char_speed.set_value(percentage)
|
||||||
|
|
||||||
# Handle Oscillating
|
# Handle Oscillating
|
||||||
@ -230,11 +228,9 @@ class Fan(HomeAccessory):
|
|||||||
oscillating = new_state.attributes.get(ATTR_OSCILLATING)
|
oscillating = new_state.attributes.get(ATTR_OSCILLATING)
|
||||||
if isinstance(oscillating, bool):
|
if isinstance(oscillating, bool):
|
||||||
hk_oscillating = 1 if oscillating else 0
|
hk_oscillating = 1 if oscillating else 0
|
||||||
if self.char_swing.value != hk_oscillating:
|
|
||||||
self.char_swing.set_value(hk_oscillating)
|
self.char_swing.set_value(hk_oscillating)
|
||||||
|
|
||||||
current_preset_mode = new_state.attributes.get(ATTR_PRESET_MODE)
|
current_preset_mode = new_state.attributes.get(ATTR_PRESET_MODE)
|
||||||
for preset_mode, char in self.preset_mode_chars.items():
|
for preset_mode, char in self.preset_mode_chars.items():
|
||||||
hk_value = 1 if preset_mode == current_preset_mode else 0
|
hk_value = 1 if preset_mode == current_preset_mode else 0
|
||||||
if char.value != hk_value:
|
|
||||||
char.set_value(hk_value)
|
char.set_value(hk_value)
|
||||||
|
@ -224,7 +224,6 @@ class HumidifierDehumidifier(HomeAccessory):
|
|||||||
is_active = new_state.state == STATE_ON
|
is_active = new_state.state == STATE_ON
|
||||||
|
|
||||||
# Update active state
|
# Update active state
|
||||||
if self.char_active.value != is_active:
|
|
||||||
self.char_active.set_value(is_active)
|
self.char_active.set_value(is_active)
|
||||||
|
|
||||||
# Set current state
|
# Set current state
|
||||||
@ -235,13 +234,9 @@ class HumidifierDehumidifier(HomeAccessory):
|
|||||||
current_state = HC_STATE_DEHUMIDIFYING
|
current_state = HC_STATE_DEHUMIDIFYING
|
||||||
else:
|
else:
|
||||||
current_state = HC_STATE_INACTIVE
|
current_state = HC_STATE_INACTIVE
|
||||||
if self.char_current_humidifier_dehumidifier.value != current_state:
|
|
||||||
self.char_current_humidifier_dehumidifier.set_value(current_state)
|
self.char_current_humidifier_dehumidifier.set_value(current_state)
|
||||||
|
|
||||||
# Update target humidity
|
# Update target humidity
|
||||||
target_humidity = new_state.attributes.get(ATTR_HUMIDITY)
|
target_humidity = new_state.attributes.get(ATTR_HUMIDITY)
|
||||||
if (
|
if isinstance(target_humidity, (int, float)):
|
||||||
isinstance(target_humidity, (int, float))
|
|
||||||
and self.char_target_humidity.value != target_humidity
|
|
||||||
):
|
|
||||||
self.char_target_humidity.set_value(target_humidity)
|
self.char_target_humidity.set_value(target_humidity)
|
||||||
|
@ -205,12 +205,9 @@ class Light(HomeAccessory):
|
|||||||
color_temp_mode = color_mode == COLOR_MODE_COLOR_TEMP
|
color_temp_mode = color_mode == COLOR_MODE_COLOR_TEMP
|
||||||
primary_on_value = char_on_value if not color_temp_mode else 0
|
primary_on_value = char_on_value if not color_temp_mode else 0
|
||||||
secondary_on_value = char_on_value if color_temp_mode else 0
|
secondary_on_value = char_on_value if color_temp_mode else 0
|
||||||
if self.char_on_primary.value != primary_on_value:
|
|
||||||
self.char_on_primary.set_value(primary_on_value)
|
self.char_on_primary.set_value(primary_on_value)
|
||||||
if self.char_on_secondary.value != secondary_on_value:
|
|
||||||
self.char_on_secondary.set_value(secondary_on_value)
|
self.char_on_secondary.set_value(secondary_on_value)
|
||||||
else:
|
else:
|
||||||
if self.char_on_primary.value != char_on_value:
|
|
||||||
self.char_on_primary.set_value(char_on_value)
|
self.char_on_primary.set_value(char_on_value)
|
||||||
|
|
||||||
# Handle Brightness
|
# Handle Brightness
|
||||||
@ -230,12 +227,8 @@ class Light(HomeAccessory):
|
|||||||
# order to avoid this incorrect behavior.
|
# order to avoid this incorrect behavior.
|
||||||
if brightness == 0 and state == STATE_ON:
|
if brightness == 0 and state == STATE_ON:
|
||||||
brightness = 1
|
brightness = 1
|
||||||
if self.char_brightness_primary.value != brightness:
|
|
||||||
self.char_brightness_primary.set_value(brightness)
|
self.char_brightness_primary.set_value(brightness)
|
||||||
if (
|
if self.color_and_temp_supported:
|
||||||
self.color_and_temp_supported
|
|
||||||
and self.char_brightness_secondary.value != brightness
|
|
||||||
):
|
|
||||||
self.char_brightness_secondary.set_value(brightness)
|
self.char_brightness_secondary.set_value(brightness)
|
||||||
|
|
||||||
# Handle color temperature
|
# Handle color temperature
|
||||||
@ -243,7 +236,6 @@ class Light(HomeAccessory):
|
|||||||
color_temperature = attributes.get(ATTR_COLOR_TEMP)
|
color_temperature = attributes.get(ATTR_COLOR_TEMP)
|
||||||
if isinstance(color_temperature, (int, float)):
|
if isinstance(color_temperature, (int, float)):
|
||||||
color_temperature = round(color_temperature, 0)
|
color_temperature = round(color_temperature, 0)
|
||||||
if self.char_color_temperature.value != color_temperature:
|
|
||||||
self.char_color_temperature.set_value(color_temperature)
|
self.char_color_temperature.set_value(color_temperature)
|
||||||
|
|
||||||
# Handle Color
|
# Handle Color
|
||||||
@ -252,7 +244,5 @@ class Light(HomeAccessory):
|
|||||||
if isinstance(hue, (int, float)) and isinstance(saturation, (int, float)):
|
if isinstance(hue, (int, float)) and isinstance(saturation, (int, float)):
|
||||||
hue = round(hue, 0)
|
hue = round(hue, 0)
|
||||||
saturation = round(saturation, 0)
|
saturation = round(saturation, 0)
|
||||||
if hue != self.char_hue.value:
|
|
||||||
self.char_hue.set_value(hue)
|
self.char_hue.set_value(hue)
|
||||||
if saturation != self.char_saturation.value:
|
|
||||||
self.char_saturation.set_value(saturation)
|
self.char_saturation.set_value(saturation)
|
||||||
|
@ -106,14 +106,10 @@ class Lock(HomeAccessory):
|
|||||||
# LockTargetState only supports locked and unlocked
|
# LockTargetState only supports locked and unlocked
|
||||||
# Must set lock target state before current state
|
# Must set lock target state before current state
|
||||||
# or there will be no notification
|
# or there will be no notification
|
||||||
if (
|
if target_lock_state is not None:
|
||||||
target_lock_state is not None
|
|
||||||
and self.char_target_state.value != target_lock_state
|
|
||||||
):
|
|
||||||
self.char_target_state.set_value(target_lock_state)
|
self.char_target_state.set_value(target_lock_state)
|
||||||
|
|
||||||
# Set lock current state ONLY after ensuring that
|
# Set lock current state ONLY after ensuring that
|
||||||
# target state is correct or there will be no
|
# target state is correct or there will be no
|
||||||
# notification
|
# notification
|
||||||
if self.char_current_state.value != current_lock_state:
|
|
||||||
self.char_current_state.set_value(current_lock_state)
|
self.char_current_state.set_value(current_lock_state)
|
||||||
|
@ -180,7 +180,6 @@ class MediaPlayer(HomeAccessory):
|
|||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
'%s: Set current state for "on_off" to %s', self.entity_id, hk_state
|
'%s: Set current state for "on_off" to %s', self.entity_id, hk_state
|
||||||
)
|
)
|
||||||
if self.chars[FEATURE_ON_OFF].value != hk_state:
|
|
||||||
self.chars[FEATURE_ON_OFF].set_value(hk_state)
|
self.chars[FEATURE_ON_OFF].set_value(hk_state)
|
||||||
|
|
||||||
if self.chars[FEATURE_PLAY_PAUSE]:
|
if self.chars[FEATURE_PLAY_PAUSE]:
|
||||||
@ -190,7 +189,6 @@ class MediaPlayer(HomeAccessory):
|
|||||||
self.entity_id,
|
self.entity_id,
|
||||||
hk_state,
|
hk_state,
|
||||||
)
|
)
|
||||||
if self.chars[FEATURE_PLAY_PAUSE].value != hk_state:
|
|
||||||
self.chars[FEATURE_PLAY_PAUSE].set_value(hk_state)
|
self.chars[FEATURE_PLAY_PAUSE].set_value(hk_state)
|
||||||
|
|
||||||
if self.chars[FEATURE_PLAY_STOP]:
|
if self.chars[FEATURE_PLAY_STOP]:
|
||||||
@ -200,7 +198,6 @@ class MediaPlayer(HomeAccessory):
|
|||||||
self.entity_id,
|
self.entity_id,
|
||||||
hk_state,
|
hk_state,
|
||||||
)
|
)
|
||||||
if self.chars[FEATURE_PLAY_STOP].value != hk_state:
|
|
||||||
self.chars[FEATURE_PLAY_STOP].set_value(hk_state)
|
self.chars[FEATURE_PLAY_STOP].set_value(hk_state)
|
||||||
|
|
||||||
if self.chars[FEATURE_TOGGLE_MUTE]:
|
if self.chars[FEATURE_TOGGLE_MUTE]:
|
||||||
@ -210,7 +207,6 @@ class MediaPlayer(HomeAccessory):
|
|||||||
self.entity_id,
|
self.entity_id,
|
||||||
current_state,
|
current_state,
|
||||||
)
|
)
|
||||||
if self.chars[FEATURE_TOGGLE_MUTE].value != current_state:
|
|
||||||
self.chars[FEATURE_TOGGLE_MUTE].set_value(current_state)
|
self.chars[FEATURE_TOGGLE_MUTE].set_value(current_state)
|
||||||
|
|
||||||
|
|
||||||
@ -341,7 +337,6 @@ class TelevisionMediaPlayer(RemoteInputSelectAccessory):
|
|||||||
if current_state not in MEDIA_PLAYER_OFF_STATES:
|
if current_state not in MEDIA_PLAYER_OFF_STATES:
|
||||||
hk_state = 1
|
hk_state = 1
|
||||||
_LOGGER.debug("%s: Set current active state to %s", self.entity_id, hk_state)
|
_LOGGER.debug("%s: Set current active state to %s", self.entity_id, hk_state)
|
||||||
if self.char_active.value != hk_state:
|
|
||||||
self.char_active.set_value(hk_state)
|
self.char_active.set_value(hk_state)
|
||||||
|
|
||||||
# Set mute state
|
# Set mute state
|
||||||
@ -352,7 +347,6 @@ class TelevisionMediaPlayer(RemoteInputSelectAccessory):
|
|||||||
self.entity_id,
|
self.entity_id,
|
||||||
current_mute_state,
|
current_mute_state,
|
||||||
)
|
)
|
||||||
if self.char_mute.value != current_mute_state:
|
|
||||||
self.char_mute.set_value(current_mute_state)
|
self.char_mute.set_value(current_mute_state)
|
||||||
|
|
||||||
self._async_update_input_state(hk_state, new_state)
|
self._async_update_input_state(hk_state, new_state)
|
||||||
|
@ -154,7 +154,6 @@ class RemoteInputSelectAccessory(HomeAccessory):
|
|||||||
_LOGGER.debug("%s: Set current input to %s", self.entity_id, source_name)
|
_LOGGER.debug("%s: Set current input to %s", self.entity_id, source_name)
|
||||||
if source_name in self.sources:
|
if source_name in self.sources:
|
||||||
index = self.sources.index(source_name)
|
index = self.sources.index(source_name)
|
||||||
if self.char_input_source.value != index:
|
|
||||||
self.char_input_source.set_value(index)
|
self.char_input_source.set_value(index)
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -174,7 +173,6 @@ class RemoteInputSelectAccessory(HomeAccessory):
|
|||||||
source_name,
|
source_name,
|
||||||
possible_sources,
|
possible_sources,
|
||||||
)
|
)
|
||||||
if self.char_input_source.value != 0:
|
|
||||||
self.char_input_source.set_value(0)
|
self.char_input_source.set_value(0)
|
||||||
|
|
||||||
|
|
||||||
@ -225,7 +223,6 @@ class ActivityRemote(RemoteInputSelectAccessory):
|
|||||||
# Power state remote
|
# Power state remote
|
||||||
hk_state = 1 if current_state == STATE_ON else 0
|
hk_state = 1 if current_state == STATE_ON else 0
|
||||||
_LOGGER.debug("%s: Set current active state to %s", self.entity_id, hk_state)
|
_LOGGER.debug("%s: Set current active state to %s", self.entity_id, hk_state)
|
||||||
if self.char_active.value != hk_state:
|
|
||||||
self.char_active.set_value(hk_state)
|
self.char_active.set_value(hk_state)
|
||||||
|
|
||||||
self._async_update_input_state(hk_state, new_state)
|
self._async_update_input_state(hk_state, new_state)
|
||||||
|
@ -158,7 +158,6 @@ class SecuritySystem(HomeAccessory):
|
|||||||
"""Update security state after state changed."""
|
"""Update security state after state changed."""
|
||||||
hass_state = new_state.state
|
hass_state = new_state.state
|
||||||
if (current_state := HASS_TO_HOMEKIT_CURRENT.get(hass_state)) is not None:
|
if (current_state := HASS_TO_HOMEKIT_CURRENT.get(hass_state)) is not None:
|
||||||
if self.char_current_state.value != current_state:
|
|
||||||
self.char_current_state.set_value(current_state)
|
self.char_current_state.set_value(current_state)
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"%s: Updated current state to %s (%d)",
|
"%s: Updated current state to %s (%d)",
|
||||||
@ -166,7 +165,5 @@ class SecuritySystem(HomeAccessory):
|
|||||||
hass_state,
|
hass_state,
|
||||||
current_state,
|
current_state,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (target_state := HASS_TO_HOMEKIT_TARGET.get(hass_state)) is not None:
|
if (target_state := HASS_TO_HOMEKIT_TARGET.get(hass_state)) is not None:
|
||||||
if self.char_target_state.value != target_state:
|
|
||||||
self.char_target_state.set_value(target_state)
|
self.char_target_state.set_value(target_state)
|
||||||
|
@ -101,7 +101,6 @@ class TemperatureSensor(HomeAccessory):
|
|||||||
temperature = convert_to_float(new_state.state)
|
temperature = convert_to_float(new_state.state)
|
||||||
if temperature:
|
if temperature:
|
||||||
temperature = temperature_to_homekit(temperature, unit)
|
temperature = temperature_to_homekit(temperature, unit)
|
||||||
if self.char_temp.value != temperature:
|
|
||||||
self.char_temp.set_value(temperature)
|
self.char_temp.set_value(temperature)
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
"%s: Current temperature set to %.1f°C", self.entity_id, temperature
|
"%s: Current temperature set to %.1f°C", self.entity_id, temperature
|
||||||
@ -128,7 +127,7 @@ class HumiditySensor(HomeAccessory):
|
|||||||
def async_update_state(self, new_state):
|
def async_update_state(self, new_state):
|
||||||
"""Update accessory after state change."""
|
"""Update accessory after state change."""
|
||||||
humidity = convert_to_float(new_state.state)
|
humidity = convert_to_float(new_state.state)
|
||||||
if humidity and self.char_humidity.value != humidity:
|
if humidity:
|
||||||
self.char_humidity.set_value(humidity)
|
self.char_humidity.set_value(humidity)
|
||||||
_LOGGER.debug("%s: Percent set to %d%%", self.entity_id, humidity)
|
_LOGGER.debug("%s: Percent set to %d%%", self.entity_id, humidity)
|
||||||
|
|
||||||
@ -161,7 +160,6 @@ class AirQualitySensor(HomeAccessory):
|
|||||||
self.char_density.set_value(density)
|
self.char_density.set_value(density)
|
||||||
_LOGGER.debug("%s: Set density to %d", self.entity_id, density)
|
_LOGGER.debug("%s: Set density to %d", self.entity_id, density)
|
||||||
air_quality = density_to_air_quality(density)
|
air_quality = density_to_air_quality(density)
|
||||||
if self.char_quality.value != air_quality:
|
|
||||||
self.char_quality.set_value(air_quality)
|
self.char_quality.set_value(air_quality)
|
||||||
_LOGGER.debug("%s: Set air_quality to %d", self.entity_id, air_quality)
|
_LOGGER.debug("%s: Set air_quality to %d", self.entity_id, air_quality)
|
||||||
|
|
||||||
@ -194,12 +192,10 @@ class CarbonMonoxideSensor(HomeAccessory):
|
|||||||
"""Update accessory after state change."""
|
"""Update accessory after state change."""
|
||||||
value = convert_to_float(new_state.state)
|
value = convert_to_float(new_state.state)
|
||||||
if value:
|
if value:
|
||||||
if self.char_level.value != value:
|
|
||||||
self.char_level.set_value(value)
|
self.char_level.set_value(value)
|
||||||
if value > self.char_peak.value:
|
if value > self.char_peak.value:
|
||||||
self.char_peak.set_value(value)
|
self.char_peak.set_value(value)
|
||||||
co_detected = value > THRESHOLD_CO
|
co_detected = value > THRESHOLD_CO
|
||||||
if self.char_detected.value is not co_detected:
|
|
||||||
self.char_detected.set_value(co_detected)
|
self.char_detected.set_value(co_detected)
|
||||||
_LOGGER.debug("%s: Set to %d", self.entity_id, value)
|
_LOGGER.debug("%s: Set to %d", self.entity_id, value)
|
||||||
|
|
||||||
@ -232,12 +228,10 @@ class CarbonDioxideSensor(HomeAccessory):
|
|||||||
"""Update accessory after state change."""
|
"""Update accessory after state change."""
|
||||||
value = convert_to_float(new_state.state)
|
value = convert_to_float(new_state.state)
|
||||||
if value:
|
if value:
|
||||||
if self.char_level.value != value:
|
|
||||||
self.char_level.set_value(value)
|
self.char_level.set_value(value)
|
||||||
if value > self.char_peak.value:
|
if value > self.char_peak.value:
|
||||||
self.char_peak.set_value(value)
|
self.char_peak.set_value(value)
|
||||||
co2_detected = value > THRESHOLD_CO2
|
co2_detected = value > THRESHOLD_CO2
|
||||||
if self.char_detected.value is not co2_detected:
|
|
||||||
self.char_detected.set_value(co2_detected)
|
self.char_detected.set_value(co2_detected)
|
||||||
_LOGGER.debug("%s: Set to %d", self.entity_id, value)
|
_LOGGER.debug("%s: Set to %d", self.entity_id, value)
|
||||||
|
|
||||||
@ -262,7 +256,7 @@ class LightSensor(HomeAccessory):
|
|||||||
def async_update_state(self, new_state):
|
def async_update_state(self, new_state):
|
||||||
"""Update accessory after state change."""
|
"""Update accessory after state change."""
|
||||||
luminance = convert_to_float(new_state.state)
|
luminance = convert_to_float(new_state.state)
|
||||||
if luminance and self.char_light.value != luminance:
|
if luminance:
|
||||||
self.char_light.set_value(luminance)
|
self.char_light.set_value(luminance)
|
||||||
_LOGGER.debug("%s: Set to %d", self.entity_id, luminance)
|
_LOGGER.debug("%s: Set to %d", self.entity_id, luminance)
|
||||||
|
|
||||||
@ -297,6 +291,5 @@ class BinarySensor(HomeAccessory):
|
|||||||
"""Update accessory after state change."""
|
"""Update accessory after state change."""
|
||||||
state = new_state.state
|
state = new_state.state
|
||||||
detected = self.format(state in (STATE_ON, STATE_HOME))
|
detected = self.format(state in (STATE_ON, STATE_HOME))
|
||||||
if self.char_detected.value != detected:
|
|
||||||
self.char_detected.set_value(detected)
|
self.char_detected.set_value(detected)
|
||||||
_LOGGER.debug("%s: Set to %d", self.entity_id, detected)
|
_LOGGER.debug("%s: Set to %d", self.entity_id, detected)
|
||||||
|
@ -91,7 +91,6 @@ class Outlet(HomeAccessory):
|
|||||||
def async_update_state(self, new_state):
|
def async_update_state(self, new_state):
|
||||||
"""Update switch state after state changed."""
|
"""Update switch state after state changed."""
|
||||||
current_state = new_state.state == STATE_ON
|
current_state = new_state.state == STATE_ON
|
||||||
if self.char_on.value is not current_state:
|
|
||||||
_LOGGER.debug("%s: Set current state to %s", self.entity_id, current_state)
|
_LOGGER.debug("%s: Set current state to %s", self.entity_id, current_state)
|
||||||
self.char_on.set_value(current_state)
|
self.char_on.set_value(current_state)
|
||||||
|
|
||||||
@ -123,7 +122,6 @@ class Switch(HomeAccessory):
|
|||||||
def reset_switch(self, *args):
|
def reset_switch(self, *args):
|
||||||
"""Reset switch to emulate activate click."""
|
"""Reset switch to emulate activate click."""
|
||||||
_LOGGER.debug("%s: Reset switch to off", self.entity_id)
|
_LOGGER.debug("%s: Reset switch to off", self.entity_id)
|
||||||
if self.char_on.value is not False:
|
|
||||||
self.char_on.set_value(False)
|
self.char_on.set_value(False)
|
||||||
|
|
||||||
def set_state(self, value):
|
def set_state(self, value):
|
||||||
@ -156,7 +154,6 @@ class Switch(HomeAccessory):
|
|||||||
return
|
return
|
||||||
|
|
||||||
current_state = new_state.state == STATE_ON
|
current_state = new_state.state == STATE_ON
|
||||||
if self.char_on.value is not current_state:
|
|
||||||
_LOGGER.debug("%s: Set current state to %s", self.entity_id, current_state)
|
_LOGGER.debug("%s: Set current state to %s", self.entity_id, current_state)
|
||||||
self.char_on.set_value(current_state)
|
self.char_on.set_value(current_state)
|
||||||
|
|
||||||
@ -186,7 +183,6 @@ class Vacuum(Switch):
|
|||||||
def async_update_state(self, new_state):
|
def async_update_state(self, new_state):
|
||||||
"""Update switch state after state changed."""
|
"""Update switch state after state changed."""
|
||||||
current_state = new_state.state in (STATE_CLEANING, STATE_ON)
|
current_state = new_state.state in (STATE_CLEANING, STATE_ON)
|
||||||
if self.char_on.value is not current_state:
|
|
||||||
_LOGGER.debug("%s: Set current state to %s", self.entity_id, current_state)
|
_LOGGER.debug("%s: Set current state to %s", self.entity_id, current_state)
|
||||||
self.char_on.set_value(current_state)
|
self.char_on.set_value(current_state)
|
||||||
|
|
||||||
@ -226,9 +222,7 @@ class Valve(HomeAccessory):
|
|||||||
def async_update_state(self, new_state):
|
def async_update_state(self, new_state):
|
||||||
"""Update switch state after state changed."""
|
"""Update switch state after state changed."""
|
||||||
current_state = 1 if new_state.state == STATE_ON else 0
|
current_state = 1 if new_state.state == STATE_ON else 0
|
||||||
if self.char_active.value != current_state:
|
|
||||||
_LOGGER.debug("%s: Set active state to %s", self.entity_id, current_state)
|
_LOGGER.debug("%s: Set active state to %s", self.entity_id, current_state)
|
||||||
self.char_active.set_value(current_state)
|
self.char_active.set_value(current_state)
|
||||||
if self.char_in_use.value != current_state:
|
|
||||||
_LOGGER.debug("%s: Set in_use state to %s", self.entity_id, current_state)
|
_LOGGER.debug("%s: Set in_use state to %s", self.entity_id, current_state)
|
||||||
self.char_in_use.set_value(current_state)
|
self.char_in_use.set_value(current_state)
|
||||||
|
@ -446,7 +446,6 @@ class Thermostat(HomeAccessory):
|
|||||||
if hvac_mode and hvac_mode in HC_HASS_TO_HOMEKIT:
|
if hvac_mode and hvac_mode in HC_HASS_TO_HOMEKIT:
|
||||||
homekit_hvac_mode = HC_HASS_TO_HOMEKIT[hvac_mode]
|
homekit_hvac_mode = HC_HASS_TO_HOMEKIT[hvac_mode]
|
||||||
if homekit_hvac_mode in self.hc_homekit_to_hass:
|
if homekit_hvac_mode in self.hc_homekit_to_hass:
|
||||||
if self.char_target_heat_cool.value != homekit_hvac_mode:
|
|
||||||
self.char_target_heat_cool.set_value(homekit_hvac_mode)
|
self.char_target_heat_cool.set_value(homekit_hvac_mode)
|
||||||
else:
|
else:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
@ -459,30 +458,23 @@ class Thermostat(HomeAccessory):
|
|||||||
hvac_action = new_state.attributes.get(ATTR_HVAC_ACTION)
|
hvac_action = new_state.attributes.get(ATTR_HVAC_ACTION)
|
||||||
if hvac_action:
|
if hvac_action:
|
||||||
homekit_hvac_action = HC_HASS_TO_HOMEKIT_ACTION[hvac_action]
|
homekit_hvac_action = HC_HASS_TO_HOMEKIT_ACTION[hvac_action]
|
||||||
if self.char_current_heat_cool.value != homekit_hvac_action:
|
|
||||||
self.char_current_heat_cool.set_value(homekit_hvac_action)
|
self.char_current_heat_cool.set_value(homekit_hvac_action)
|
||||||
|
|
||||||
# Update current temperature
|
# Update current temperature
|
||||||
current_temp = _get_current_temperature(new_state, self._unit)
|
current_temp = _get_current_temperature(new_state, self._unit)
|
||||||
if current_temp is not None and self.char_current_temp.value != current_temp:
|
if current_temp is not None:
|
||||||
self.char_current_temp.set_value(current_temp)
|
self.char_current_temp.set_value(current_temp)
|
||||||
|
|
||||||
# Update current humidity
|
# Update current humidity
|
||||||
if CHAR_CURRENT_HUMIDITY in self.chars:
|
if CHAR_CURRENT_HUMIDITY in self.chars:
|
||||||
current_humdity = new_state.attributes.get(ATTR_CURRENT_HUMIDITY)
|
current_humdity = new_state.attributes.get(ATTR_CURRENT_HUMIDITY)
|
||||||
if (
|
if isinstance(current_humdity, (int, float)):
|
||||||
isinstance(current_humdity, (int, float))
|
|
||||||
and self.char_current_humidity.value != current_humdity
|
|
||||||
):
|
|
||||||
self.char_current_humidity.set_value(current_humdity)
|
self.char_current_humidity.set_value(current_humdity)
|
||||||
|
|
||||||
# Update target humidity
|
# Update target humidity
|
||||||
if CHAR_TARGET_HUMIDITY in self.chars:
|
if CHAR_TARGET_HUMIDITY in self.chars:
|
||||||
target_humdity = new_state.attributes.get(ATTR_HUMIDITY)
|
target_humdity = new_state.attributes.get(ATTR_HUMIDITY)
|
||||||
if (
|
if isinstance(target_humdity, (int, float)):
|
||||||
isinstance(target_humdity, (int, float))
|
|
||||||
and self.char_target_humidity.value != target_humdity
|
|
||||||
):
|
|
||||||
self.char_target_humidity.set_value(target_humdity)
|
self.char_target_humidity.set_value(target_humdity)
|
||||||
|
|
||||||
# Update cooling threshold temperature if characteristic exists
|
# Update cooling threshold temperature if characteristic exists
|
||||||
@ -490,7 +482,6 @@ class Thermostat(HomeAccessory):
|
|||||||
cooling_thresh = new_state.attributes.get(ATTR_TARGET_TEMP_HIGH)
|
cooling_thresh = new_state.attributes.get(ATTR_TARGET_TEMP_HIGH)
|
||||||
if isinstance(cooling_thresh, (int, float)):
|
if isinstance(cooling_thresh, (int, float)):
|
||||||
cooling_thresh = self._temperature_to_homekit(cooling_thresh)
|
cooling_thresh = self._temperature_to_homekit(cooling_thresh)
|
||||||
if self.char_heating_thresh_temp.value != cooling_thresh:
|
|
||||||
self.char_cooling_thresh_temp.set_value(cooling_thresh)
|
self.char_cooling_thresh_temp.set_value(cooling_thresh)
|
||||||
|
|
||||||
# Update heating threshold temperature if characteristic exists
|
# Update heating threshold temperature if characteristic exists
|
||||||
@ -498,7 +489,6 @@ class Thermostat(HomeAccessory):
|
|||||||
heating_thresh = new_state.attributes.get(ATTR_TARGET_TEMP_LOW)
|
heating_thresh = new_state.attributes.get(ATTR_TARGET_TEMP_LOW)
|
||||||
if isinstance(heating_thresh, (int, float)):
|
if isinstance(heating_thresh, (int, float)):
|
||||||
heating_thresh = self._temperature_to_homekit(heating_thresh)
|
heating_thresh = self._temperature_to_homekit(heating_thresh)
|
||||||
if self.char_heating_thresh_temp.value != heating_thresh:
|
|
||||||
self.char_heating_thresh_temp.set_value(heating_thresh)
|
self.char_heating_thresh_temp.set_value(heating_thresh)
|
||||||
|
|
||||||
# Update target temperature
|
# Update target temperature
|
||||||
@ -515,13 +505,12 @@ class Thermostat(HomeAccessory):
|
|||||||
temp_high = new_state.attributes.get(ATTR_TARGET_TEMP_HIGH)
|
temp_high = new_state.attributes.get(ATTR_TARGET_TEMP_HIGH)
|
||||||
if isinstance(temp_high, (int, float)):
|
if isinstance(temp_high, (int, float)):
|
||||||
target_temp = self._temperature_to_homekit(temp_high)
|
target_temp = self._temperature_to_homekit(temp_high)
|
||||||
if target_temp and self.char_target_temp.value != target_temp:
|
if target_temp:
|
||||||
self.char_target_temp.set_value(target_temp)
|
self.char_target_temp.set_value(target_temp)
|
||||||
|
|
||||||
# Update display units
|
# Update display units
|
||||||
if self._unit and self._unit in UNIT_HASS_TO_HOMEKIT:
|
if self._unit and self._unit in UNIT_HASS_TO_HOMEKIT:
|
||||||
unit = UNIT_HASS_TO_HOMEKIT[self._unit]
|
unit = UNIT_HASS_TO_HOMEKIT[self._unit]
|
||||||
if self.char_display_units.value != unit:
|
|
||||||
self.char_display_units.set_value(unit)
|
self.char_display_units.set_value(unit)
|
||||||
|
|
||||||
|
|
||||||
@ -580,7 +569,7 @@ class WaterHeater(HomeAccessory):
|
|||||||
"""Change operation mode to value if call came from HomeKit."""
|
"""Change operation mode to value if call came from HomeKit."""
|
||||||
_LOGGER.debug("%s: Set heat-cool to %d", self.entity_id, value)
|
_LOGGER.debug("%s: Set heat-cool to %d", self.entity_id, value)
|
||||||
hass_value = HC_HOMEKIT_TO_HASS[value]
|
hass_value = HC_HOMEKIT_TO_HASS[value]
|
||||||
if hass_value != HVAC_MODE_HEAT and self.char_target_heat_cool.value != 1:
|
if hass_value != HVAC_MODE_HEAT:
|
||||||
self.char_target_heat_cool.set_value(1) # Heat
|
self.char_target_heat_cool.set_value(1) # Heat
|
||||||
|
|
||||||
def set_target_temperature(self, value):
|
def set_target_temperature(self, value):
|
||||||
@ -600,28 +589,21 @@ class WaterHeater(HomeAccessory):
|
|||||||
"""Update water_heater state after state change."""
|
"""Update water_heater state after state change."""
|
||||||
# Update current and target temperature
|
# Update current and target temperature
|
||||||
target_temperature = _get_target_temperature(new_state, self._unit)
|
target_temperature = _get_target_temperature(new_state, self._unit)
|
||||||
if (
|
if target_temperature is not None:
|
||||||
target_temperature is not None
|
|
||||||
and target_temperature != self.char_target_temp.value
|
|
||||||
):
|
|
||||||
self.char_target_temp.set_value(target_temperature)
|
self.char_target_temp.set_value(target_temperature)
|
||||||
|
|
||||||
current_temperature = _get_current_temperature(new_state, self._unit)
|
current_temperature = _get_current_temperature(new_state, self._unit)
|
||||||
if (
|
if current_temperature is not None:
|
||||||
current_temperature is not None
|
|
||||||
and current_temperature != self.char_current_temp.value
|
|
||||||
):
|
|
||||||
self.char_current_temp.set_value(current_temperature)
|
self.char_current_temp.set_value(current_temperature)
|
||||||
|
|
||||||
# Update display units
|
# Update display units
|
||||||
if self._unit and self._unit in UNIT_HASS_TO_HOMEKIT:
|
if self._unit and self._unit in UNIT_HASS_TO_HOMEKIT:
|
||||||
unit = UNIT_HASS_TO_HOMEKIT[self._unit]
|
unit = UNIT_HASS_TO_HOMEKIT[self._unit]
|
||||||
if self.char_display_units.value != unit:
|
|
||||||
self.char_display_units.set_value(unit)
|
self.char_display_units.set_value(unit)
|
||||||
|
|
||||||
# Update target operation mode
|
# Update target operation mode
|
||||||
operation_mode = new_state.state
|
operation_mode = new_state.state
|
||||||
if operation_mode and self.char_target_heat_cool.value != 1:
|
if operation_mode:
|
||||||
self.char_target_heat_cool.set_value(1) # Heat
|
self.char_target_heat_cool.set_value(1) # Heat
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user