def _process_state(self, entity_observation): """Return True if state conditions are met.""" entity = entity_observation["entity_id"] try: return condition.state(self.opp, entity, entity_observation.get("to_state")) except ConditionError: return False
def test_is_state(opp: OpenPeerPower, variables: TemplateVarsType) -> bool: """Test if an entity is a certain state.""" return condition.state(opp, config[ATTR_ENTITY_ID], state)
async def _async_control_heating(self, time=None, force=False): """Check if we need to turn heating on or off.""" async with self._temp_lock: if not self._active and None not in ( self._cur_temp, self._target_temp, self._is_device_active, ): self._active = True _LOGGER.info( "Obtained current and target temperature. " "Generic thermostat active. %s, %s", self._cur_temp, self._target_temp, ) if not self._active or self._hvac_mode == HVAC_MODE_OFF: return # If the `force` argument is True, we # ignore `min_cycle_duration`. # If the `time` argument is not none, we were invoked for # keep-alive purposes, and `min_cycle_duration` is irrelevant. if not force and time is None and self.min_cycle_duration: if self._is_device_active: current_state = STATE_ON else: current_state = HVAC_MODE_OFF try: long_enough = condition.state( self.opp, self.heater_entity_id, current_state, self.min_cycle_duration, ) except ConditionError: long_enough = False if not long_enough: return too_cold = self._target_temp >= self._cur_temp + self._cold_tolerance too_hot = self._cur_temp >= self._target_temp + self._hot_tolerance if self._is_device_active: if (self.ac_mode and too_cold) or (not self.ac_mode and too_hot): _LOGGER.info("Turning off heater %s", self.heater_entity_id) await self._async_heater_turn_off() elif time is not None: # The time argument is passed only in keep-alive case _LOGGER.info( "Keep-alive - Turning on heater heater %s", self.heater_entity_id, ) await self._async_heater_turn_on() else: if (self.ac_mode and too_hot) or (not self.ac_mode and too_cold): _LOGGER.info("Turning on heater %s", self.heater_entity_id) await self._async_heater_turn_on() elif time is not None: # The time argument is passed only in keep-alive case _LOGGER.info("Keep-alive - Turning off heater %s", self.heater_entity_id) await self._async_heater_turn_off()