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

Commit

Permalink
Merge pull request #22 from daenny/test/more-logging
Browse files Browse the repository at this point in the history
fix: testing for thermostats without preset
  • Loading branch information
daenny authored May 10, 2020
2 parents db74d9e + 2600515 commit f10a74b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions custom_components/climate_group/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ async def async_update(self):
# if nothing is in excluded everything will be in 'filtered states'
filtered_states = list(
filter(
lambda x: x.attributes.get("preset_mode", None) not in self._excluded,
lambda x: x.attributes.get(ATTR_PRESET_MODE, None)
not in self._excluded,
states,
)
)
Expand All @@ -277,9 +278,9 @@ async def async_update(self):

all_modes = [x.state for x in filtered_states]
# return the Mode (what the thermostat is set to do) in priority order (heat, cool, ...)
self._mode = HVAC_MODE_OFF
self._mode = None
# iterate through all hvac modes (skip first, as its off)
for hvac_mode in HVAC_MODES[1:]:
for hvac_mode in HVAC_MODES[1:] + [HVAC_MODE_OFF]:
# if any thermostat is in the given mode return it
if any([mode == hvac_mode for mode in all_modes]):
self._mode = hvac_mode
Expand All @@ -298,6 +299,7 @@ async def async_update(self):
all_presets = [
state.attributes.get(ATTR_PRESET_MODE, None) for state in filtered_states
]
self._preset = None
if all_presets:
# Report the most common preset_mode.
self._preset = Counter(itertools.chain(all_presets)).most_common(1)[0][0]
Expand Down Expand Up @@ -333,14 +335,14 @@ async def async_update(self):
# we find.
self._supported_features |= support

self._preset_modes = None
presets = []
for preset in _find_state_attributes(states, ATTR_PRESET_MODES):
presets.extend(preset)

if len(presets):
self._preset_modes = set(presets)
else:
self._preset_modes = None
_LOGGER.debug("State update complete")

async def async_set_preset_mode(self, preset_mode: str):
"""Forward the preset_mode to all climate in the climate group."""
Expand Down

0 comments on commit f10a74b

Please sign in to comment.