Skip to content

Commit

Permalink
Update climate.py
Browse files Browse the repository at this point in the history
  • Loading branch information
RobHofmann authored Jul 18, 2024
1 parent 9bbfe64 commit 5a27235
Showing 1 changed file with 36 additions and 36 deletions.
72 changes: 36 additions & 36 deletions custom_components/gree/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def __init__(self, hass, name, ip_addr, port, mac_addr, timeout, target_temp_ste
self._unit_of_measurement = '°C'

self._hvac_modes = hvac_modes
self._hvac_mode = None
self._hvac_mode = HVACMode.OFF
self._fan_modes = fan_modes
self._fan_mode = None
self._swing_modes = swing_modes
Expand Down Expand Up @@ -292,33 +292,33 @@ def __init__(self, hass, name, ip_addr, port, mac_addr, timeout, target_temp_ste

if light_sensor_entity_id:
_LOGGER.info('Setting up light sensor entity: ' + str(light_sensor_entity_id))
if self.hass.states.get(light_sensor_entity_id).state is STATE_ON:
if self.hass.states.get(light_sensor_entity_id) is not None and self.hass.states.get(light_sensor_entity_id).state is STATE_ON:
self._enable_light_sensor = True
elif self.hass.states.get(light_sensor_entity_id).state is STATE_OFF:
elif self.hass.states.get(light_sensor_entity_id) is not None and self.hass.states.get(light_sensor_entity_id).state is STATE_OFF:
self._enable_light_sensor = False
async_track_state_change_event(hass, light_sensor_entity_id, self._async_light_sensor_entity_state_changed)
else:
self._enable_light_sensor = None
self._enable_light_sensor = False

if auto_light_entity_id:
_LOGGER.info('Setting up auto light entity: ' + str(auto_light_entity_id))
if self.hass.states.get(auto_light_entity_id).state is STATE_ON:
if self.hass.states.get(auto_light_entity_id) is not None and self.hass.states.get(auto_light_entity_id).state is STATE_ON:
self._auto_light = True
elif self.hass.states.get(auto_light_entity_id).state is STATE_OFF:
elif self.hass.states.get(auto_light_entity_id) is not None and self.hass.states.get(auto_light_entity_id).state is STATE_OFF:
self._auto_light = False
async_track_state_change_event(hass, auto_light_entity_id, self._async_auto_light_entity_state_changed)
else:
self._auto_light = None
self._auto_light = False

if auto_xfan_entity_id:
_LOGGER.info('Setting up auto xfan entity: ' + str(auto_xfan_entity_id))
if self.hass.states.get(auto_xfan_entity_id).state is STATE_ON:
if self.hass.states.get(auto_xfan_entity_id) is not None and self.hass.states.get(auto_xfan_entity_id).state is STATE_ON:
self._auto_xfan = True
elif self.hass.states.get(auto_xfan_entity_id).state is STATE_OFF:
elif self.hass.states.get(auto_xfan_entity_id) is not None and self.hass.states.get(auto_xfan_entity_id).state is STATE_OFF:
self._auto_xfan = False
async_track_state_change_event(hass, auto_xfan_entity_id, self._async_auto_xfan_entity_state_changed)
else:
self._auto_xfan = None
self._auto_xfan = False

# Pad helper method to help us get the right string for encrypting
def Pad(self, s):
Expand Down Expand Up @@ -754,7 +754,7 @@ async def _async_lights_entity_state_changed(self, event: Event[EventStateChange
entity_id = event.data["entity_id"]
old_state = event.data["old_state"]
new_state = event.data["new_state"]
_LOGGER.info('lights_entity state changed | ' + str(entity_id) + ' from ' + str(old_state.state) + ' to ' + str(new_state.state))
_LOGGER.info('lights_entity state changed | ' + str(entity_id) + ' from ' + (str(old_state.state) if hasattr(old_state,'state') else "None") + ' to ' + str(new_state.state))
if new_state is None:
return
if new_state.state is self._current_lights:
Expand All @@ -778,7 +778,7 @@ async def _async_xfan_entity_state_changed(self, event: Event[EventStateChangedD
entity_id = event.data["entity_id"]
old_state = event.data["old_state"]
new_state = event.data["new_state"]
_LOGGER.info('xfan_entity state changed | ' + str(entity_id) + ' from ' + str(old_state.state) + ' to ' + str(new_state.state))
_LOGGER.info('xfan_entity state changed | ' + str(entity_id) + ' from ' + (str(old_state.state) if hasattr(old_state,'state') else "None") + ' to ' + str(new_state.state))
if new_state is None:
return
if new_state.state is self._current_xfan:
Expand Down Expand Up @@ -806,7 +806,7 @@ async def _async_health_entity_state_changed(self, event: Event[EventStateChange
entity_id = event.data["entity_id"]
old_state = event.data["old_state"]
new_state = event.data["new_state"]
_LOGGER.info('health_entity state changed | ' + str(entity_id) + ' from ' + str(old_state.state) + ' to ' + str(new_state.state))
_LOGGER.info('health_entity state changed | ' + str(entity_id) + ' from ' + (str(old_state.state) if hasattr(old_state,'state') else "None") + ' to ' + str(new_state.state))
if new_state is None:
return
if new_state.state is self._current_health:
Expand All @@ -830,13 +830,13 @@ async def _async_powersave_entity_state_changed(self, event: Event[EventStateCha
entity_id = event.data["entity_id"]
old_state = event.data["old_state"]
new_state = event.data["new_state"]
_LOGGER.info('powersave_entity state changed | ' + str(entity_id) + ' from ' + str(old_state.state) + ' to ' + str(new_state.state))
_LOGGER.info('powersave_entity state changed | ' + str(entity_id) + ' from ' + (str(old_state.state) if hasattr(old_state,'state') else "None") + ' to ' + str(new_state.state))
if new_state is None:
return
if new_state.state is self._current_powersave:
# do nothing if state change is triggered due to Sync with HVAC
return
if not self._hvac_mode in (HVACMode.COOL):
if hasattr(self, "_hvac_mode") and self._hvac_mode is not None and not self._hvac_mode in (HVACMode.COOL):
# do nothing if not in cool mode
_LOGGER.info('Cant set powersave in %s mode' % str(self._hvac_mode))
return
Expand All @@ -859,7 +859,7 @@ async def _async_sleep_entity_state_changed(self, event: Event[EventStateChanged
entity_id = event.data["entity_id"]
old_state = event.data["old_state"]
new_state = event.data["new_state"]
_LOGGER.info('sleep_entity state changed | ' + str(entity_id) + ' from ' + str(old_state.state) + ' to ' + str(new_state.state))
_LOGGER.info('sleep_entity state changed | ' + str(entity_id) + ' from ' + (str(old_state.state) if hasattr(old_state,'state') else "None") + ' to ' + str(new_state.state))
if new_state is None:
return
if new_state.state is self._current_sleep:
Expand Down Expand Up @@ -887,7 +887,7 @@ async def _async_eightdegheat_entity_state_changed(self, event: Event[EventState
entity_id = event.data["entity_id"]
old_state = event.data["old_state"]
new_state = event.data["new_state"]
_LOGGER.info('eightdegheat_entity state changed | ' + str(entity_id) + ' from ' + str(old_state.state) + ' to ' + str(new_state.state))
_LOGGER.info('eightdegheat_entity state changed | ' + str(entity_id) + ' from ' + (str(old_state.state) if hasattr(old_state,'state') else "None") + ' to ' + str(new_state.state))
if new_state is None:
return
if new_state.state is self._current_eightdegheat:
Expand Down Expand Up @@ -915,7 +915,7 @@ def _async_air_entity_state_changed(self, event: Event[EventStateChangedData]) -
entity_id = event.data["entity_id"]
old_state = event.data["old_state"]
new_state = event.data["new_state"]
_LOGGER.info('air_entity state changed | ' + str(entity_id) + ' from ' + str(old_state.state) + ' to ' + str(new_state.state))
_LOGGER.info('air_entity state changed | ' + str(entity_id) + ' from ' + (str(old_state.state) if hasattr(old_state,'state') else "None") + ' to ' + str(new_state.state))
if new_state is None:
return
if new_state.state is self._current_air:
Expand All @@ -940,7 +940,7 @@ def _async_anti_direct_blow_entity_state_changed(self, event: Event[EventStateCh
entity_id = event.data["entity_id"]
old_state = event.data["old_state"]
new_state = event.data["new_state"]
_LOGGER.info('anti_direct_blow_entity state changed | ' + str(entity_id) + ' from ' + str(old_state.state) + ' to ' + str(new_state.state))
_LOGGER.info('anti_direct_blow_entity state changed | ' + str(entity_id) + ' from ' + (str(old_state.state) if hasattr(old_state,'state') else "None") + ' to ' + str(new_state.state))
if new_state is None:
return
if new_state.state is self._current_anti_direct_blow:
Expand All @@ -964,7 +964,7 @@ def _async_light_sensor_entity_state_changed(self, event: Event[EventStateChange
entity_id = event.data["entity_id"]
old_state = event.data["old_state"]
new_state = event.data["new_state"]
_LOGGER.info('light_sensor_entity state changed | ' + str(entity_id) + ' from ' + str(old_state.state) + ' to ' + str(new_state.state))
_LOGGER.info('light_sensor_entity state changed | ' + str(entity_id) + ' from ' + (str(old_state.state) if hasattr(old_state,'state') else "None") + ' to ' + str(new_state.state))
if new_state is None:
return
if new_state.state is self._enable_light_sensor:
Expand All @@ -990,10 +990,10 @@ def _async_auto_light_entity_state_changed(self, event: Event[EventStateChangedD
entity_id = event.data["entity_id"]
old_state = event.data["old_state"]
new_state = event.data["new_state"]
_LOGGER.info('auto_light_entity state changed | ' + str(entity_id) + ' from ' + str(old_state.state) + ' to ' + str(new_state.state))
_LOGGER.info('auto_light_entity state changed | ' + str(entity_id) + ' from ' + (str(old_state.state) if hasattr(old_state,'state') else "None") + ' to ' + str(new_state.state))
if new_state is None:
return
if new_state.state is self._auto_light:
if hasattr(self, "_auto_light") and new_state.state is self._auto_light:
# do nothing if state change is triggered due to Sync with HVAC
return
self._async_update_auto_light(new_state)
Expand All @@ -1018,10 +1018,10 @@ def _async_auto_xfan_entity_state_changed(self, event: Event[EventStateChangedDa
entity_id = event.data["entity_id"]
old_state = event.data["old_state"]
new_state = event.data["new_state"]
_LOGGER.info('auto_xfan_entity state changed | ' + str(entity_id) + ' from ' + str(old_state.state) + ' to ' + str(new_state.state))
_LOGGER.info('auto_xfan_entity state changed | ' + str(entity_id) + ' from ' + (str(old_state.state) if hasattr(old_state,'state') else "None") + ' to ' + str(new_state.state))
if new_state is None:
return
if new_state.state is self._auto_xfan:
if hasattr(self, "_auto_xfan") and new_state.state is self._auto_xfan:
# do nothing if state change is triggered due to Sync with HVAC
return
self._async_update_auto_xfan(new_state)
Expand All @@ -1043,7 +1043,7 @@ def _async_target_temp_entity_state_changed(self, event: Event[EventStateChanged
entity_id = event.data["entity_id"]
old_state = event.data["old_state"]
new_state = event.data["new_state"]
_LOGGER.info('target_temp_entity state changed | ' + str(entity_id) + ' from ' + str(old_state.state) + ' to ' + str(new_state.state))
_LOGGER.info('target_temp_entity state changed | ' + str(entity_id) + ' from ' + (str(old_state.state) if hasattr(old_state,'state') else "None") + ' to ' + str(new_state.state))
if new_state is None:
return
if int(float(new_state.state)) is self._target_temperature:
Expand Down Expand Up @@ -1155,7 +1155,7 @@ def swing_modes(self):

@property
def preset_mode(self):
if self._horizontal_swing:
if hasattr(self, "_horizontal_swing") and self._horizontal_swing:
_LOGGER.info('preset_mode(): ' + str(self._preset_mode))
# get the current preset mode
return self._preset_mode
Expand Down Expand Up @@ -1188,7 +1188,7 @@ def fan_modes(self):

@property
def supported_features(self):
if self._horizontal_swing:
if hasattr(self, "_horizontal_swing") and self._horizontal_swing:
sf = SUPPORT_FLAGS | ClimateEntityFeature.PRESET_MODE
else:
sf = SUPPORT_FLAGS
Expand Down Expand Up @@ -1249,17 +1249,17 @@ def set_hvac_mode(self, hvac_mode):
c = {}
if (hvac_mode == HVACMode.OFF):
c.update({'Pow': 0})
if self._auto_light:
if hasattr(self, "_auto_light") and self._auto_light:
c.update({'Lig': 0})
if self._has_light_sensor and self._enable_light_sensor:
if hasattr(self, "_has_light_sensor") and self._has_light_sensor and hasattr(self, "_enable_light_sensor") and self._enable_light_sensor:
c.update({'LigSen': 1})
else:
c.update({'Pow': 1, 'Mod': self.hvac_modes.index(hvac_mode)})
if self._auto_light:
if hasattr(self, "_auto_light") and self._auto_light:
c.update({'Lig': 1})
if self._has_light_sensor and self._enable_light_sensor:
if hasattr(self, "_has_light_sensor") and self._has_light_sensor and hasattr(self, "_enable_light_sensor") and self._enable_light_sensor:
c.update({'LigSen': 0})
if self._auto_xfan:
if hasattr(self, "_auto_xfan") and self._auto_xfan:
if (hvac_mode == HVACMode.COOL) or (hvac_mode == HVACMode.DRY):
c.update({'Blo': 1})
self.SyncState(c)
Expand All @@ -1269,9 +1269,9 @@ def turn_on(self):
_LOGGER.info('turn_on(): ')
# Turn on.
c = {'Pow': 1}
if self._auto_light:
if hasattr(self, "_auto_light") and self._auto_light:
c.update({'Lig': 1})
if self._has_light_sensor and self._enable_light_sensor:
if hasattr(self, "_has_light_sensor") and self._has_light_sensor and hasattr(self, "_enable_light_sensor") and self._enable_light_sensor:
c.update({'LigSen': 0})
self.SyncState(c)
self.schedule_update_ha_state()
Expand All @@ -1280,9 +1280,9 @@ def turn_off(self):
_LOGGER.info('turn_off(): ')
# Turn off.
c = {'Pow': 0}
if self._auto_light:
if hasattr(self, "_auto_light") and self._auto_light:
c.update({'Lig': 0})
if self._has_light_sensor and self._enable_light_sensor:
if hasattr(self, "_has_light_sensor") and self._has_light_sensor and hasattr(self, "_enable_light_sensor") and self._enable_light_sensor:
c.update({'LigSen': 1})
self.SyncState(c)
self.schedule_update_ha_state()
Expand Down

0 comments on commit 5a27235

Please sign in to comment.