Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

Commit

Permalink
fix: use correct support flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Claes committed Jun 11, 2020
1 parent f10a74b commit 4efebb3
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions custom_components/climate_group/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@
),
}
)
#edit the supported_flags
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE_RANGE
# edit the supported_flags
SUPPORT_FLAGS = (
SUPPORT_TARGET_TEMPERATURE | SUPPORT_TARGET_TEMPERATURE_RANGE | SUPPORT_PRESET_MODE
)


# HVAC Action priority
Expand Down Expand Up @@ -110,7 +112,7 @@ def __init__(
self._max_temp = 0
self._current_temp = 0
self._target_temp = 0
#added the temp_low and temp_high
# added the temp_low and temp_high
self._target_temp_high = None
self._target_temp_low = None
self._mode = None
Expand Down Expand Up @@ -188,8 +190,8 @@ def current_temperature(self):
@property
def target_temperature(self):
return self._target_temp
#added the target_temperature_low and target_temperature_high

# added the target_temperature_low and target_temperature_high
@property
def target_temperature_low(self):
return self._target_temp_low
Expand All @@ -214,8 +216,12 @@ async def async_set_temperature(self, **kwargs):
if ATTR_HVAC_MODE in kwargs:
hvac_mode = kwargs.get(ATTR_HVAC_MODE)
await self.async_set_hvac_mode(hvac_mode)
#start add
elif ATTR_TEMPERATURE in kwargs or ATTR_TARGET_TEMP_LOW in kwargs or ATTR_TARGET_TEMP_HIGH in kwargs:
# start add
elif (
ATTR_TEMPERATURE in kwargs
or ATTR_TARGET_TEMP_LOW in kwargs
or ATTR_TARGET_TEMP_HIGH in kwargs
):
if ATTR_TEMPERATURE in kwargs:
temperature = kwargs.get(ATTR_TEMPERATURE)
data[ATTR_TEMPERATURE] = temperature
Expand All @@ -224,7 +230,7 @@ async def async_set_temperature(self, **kwargs):
temperature_high = kwargs.get(ATTR_TARGET_TEMP_HIGH)
data[climate.ATTR_TARGET_TEMP_LOW] = temperature_low
data[climate.ATTR_TARGET_TEMP_HIGH] = temperature_high
#end add
# end add
await self.hass.services.async_call(
climate.DOMAIN, climate.SERVICE_SET_TEMPERATURE, data, blocking=True
)
Expand Down Expand Up @@ -305,20 +311,21 @@ async def async_update(self):
self._preset = Counter(itertools.chain(all_presets)).most_common(1)[0][0]

self._target_temp = _reduce_attribute(filtered_states, ATTR_TEMPERATURE)
#start add

# start add
self._target_temp_low = _reduce_attribute(filtered_states, ATTR_TARGET_TEMP_LOW)
self._target_temp_high = _reduce_attribute(filtered_states, ATTR_TARGET_TEMP_HIGH)
#end add

self._target_temp_high = _reduce_attribute(
filtered_states, ATTR_TARGET_TEMP_HIGH
)
# end add

self._current_temp = _reduce_attribute(
filtered_states, ATTR_CURRENT_TEMPERATURE
)

_LOGGER.debug(
f"Target temp: {self._target_temp}; Target temp low: {self._target_temp_low}; Target temp high: {self._target_temp_high}; Current temp: {self._current_temp}"
f"Target temp: {self._target_temp}; Target temp low: {self._target_temp_low}; Target temp high: {self._target_temp_high}; Current temp: {self._current_temp}"
)

self._min_temp = _reduce_attribute(states, ATTR_MIN_TEMP, reduce=max)
self._max_temp = _reduce_attribute(states, ATTR_MAX_TEMP, reduce=min)

Expand All @@ -334,6 +341,9 @@ async def async_update(self):
# Merge supported features by emulating support for every feature
# we find.
self._supported_features |= support
# Bitwise-and the supported features with the Grouped climate's features
# so that we don't break in the future when a new feature is added.
self._supported_features &= SUPPORT_FLAGS

self._preset_modes = None
presets = []
Expand All @@ -342,12 +352,14 @@ async def async_update(self):

if len(presets):
self._preset_modes = set(presets)
_LOGGER.debug("State update complete")
_LOGGER.debug(
f"State update complete. Supported: {self._supported_features}, mode: {self._mode}"
)

async def async_set_preset_mode(self, preset_mode: str):
"""Forward the preset_mode to all climate in the climate group."""
data = {ATTR_ENTITY_ID: self._entity_ids, ATTR_PRESET_MODE: preset_mode}

await self.hass.services.async_call(
climate.DOMAIN, climate.SERVICE_SET_PRESET_MODE, data, blocking=True
)
Expand Down

0 comments on commit 4efebb3

Please sign in to comment.