def state_attributes(self): """ Returns optional state attributes. """ thermostat_unit = self.unit_of_measurement user_unit = self.hass.config.temperature_unit data = { ATTR_CURRENT_TEMPERATURE: round(convert(self.current_temperature, thermostat_unit, user_unit), 1), ATTR_MIN_TEMP: round(convert(self.min_temp, thermostat_unit, user_unit), 0), ATTR_MAX_TEMP: round(convert(self.max_temp, thermostat_unit, user_unit), 0) } is_away = self.is_away_mode_on if is_away is not None: data[ATTR_AWAY_MODE] = STATE_ON if is_away else STATE_OFF device_attr = self.device_state_attributes if device_attr is not None: data.update(device_attr) return data
def thermostat_service(service): """ Handles calls to the services. """ # Convert the entity ids to valid light ids target_thermostats = component.extract_from_service(service) if service.service == SERVICE_SET_AWAY_MODE: away_mode = service.data.get(ATTR_AWAY_MODE) if away_mode is None: _LOGGER.error( "Received call to %s without attribute %s", SERVICE_SET_AWAY_MODE, ATTR_AWAY_MODE) elif away_mode: for thermostat in target_thermostats: thermostat.turn_away_mode_on() else: for thermostat in target_thermostats: thermostat.turn_away_mode_off() elif service.service == SERVICE_SET_TEMPERATURE: temperature = util.convert( service.data.get(ATTR_TEMPERATURE), float) if temperature is None: return for thermostat in target_thermostats: thermostat.set_temperature(convert( temperature, hass.config.temperature_unit, thermostat.unit_of_measurement)) for thermostat in target_thermostats: thermostat.update_ha_state(True)
def thermostat_service(service): """ Handles calls to the services. """ # Convert the entity ids to valid light ids target_thermostats = component.extract_from_service(service) if service.service == SERVICE_SET_AWAY_MODE: away_mode = service.data.get(ATTR_AWAY_MODE) if away_mode is None: _LOGGER.error("Received call to %s without attribute %s", SERVICE_SET_AWAY_MODE, ATTR_AWAY_MODE) elif away_mode: for thermostat in target_thermostats: thermostat.turn_away_mode_on() else: for thermostat in target_thermostats: thermostat.turn_away_mode_off() elif service.service == SERVICE_SET_TEMPERATURE: temperature = util.convert(service.data.get(ATTR_TEMPERATURE), float) if temperature is None: return for thermostat in target_thermostats: thermostat.set_temperature( convert(temperature, hass.config.temperature_unit, thermostat.unit_of_measurement)) for thermostat in target_thermostats: thermostat.update_ha_state(True)
def _convert(self, temp, round_dec=None): """Convert temperature into user preferred temperature.""" if temp is None: return None value = convert(temp, self.unit_of_measurement, self.hass.config.temperature_unit) return value if round_dec is None else round(value, round_dec)
def temperature(self, value, unit): """ Converts temperature to user preferred unit if set. """ if not (unit in (TEMP_CELCIUS, TEMP_FAHRENHEIT) and self.temperature_unit and unit != self.temperature_unit): return value, unit try: temp = float(value) except ValueError: # Could not convert value to float return value, unit return (round(temp_helper.convert(temp, unit, self.temperature_unit), 1), self.temperature_unit)
def temperature_set_service(service): """Set temperature on the target thermostats.""" target_thermostats = component.extract_from_service(service) temperature = service.data[ATTR_TEMPERATURE] for thermostat in target_thermostats: thermostat.set_temperature(convert( temperature, hass.config.temperature_unit, thermostat.unit_of_measurement)) thermostat.update_ha_state(True)
def temperature_set_service(service): """Set temperature on the target thermostats.""" target_thermostats = component.extract_from_service(service) temperature = service.data[ATTR_TEMPERATURE] for thermostat in target_thermostats: thermostat.set_temperature( convert(temperature, hass.config.temperature_unit, thermostat.unit_of_measurement)) thermostat.update_ha_state(True)
def temperature(self, value, unit): """Convert temperature to user preferred unit if set.""" if not (unit in (TEMP_CELCIUS, TEMP_FAHRENHEIT) and self.temperature_unit and unit != self.temperature_unit): return value, unit try: temp = float(value) except ValueError: # Could not convert value to float return value, unit return (round(temp_helper.convert(temp, unit, self.temperature_unit), 1), self.temperature_unit)
def _convert_for_display(self, temp): """Convert temperature into preferred units for display purposes.""" if temp is None: return None value = convert(temp, self.unit_of_measurement, self.hass.config.temperature_unit) if self.hass.config.temperature_unit is TEMP_CELCIUS: decimal_count = 1 else: # Users of fahrenheit generally expect integer units. decimal_count = 0 return round(value, decimal_count)
def _convert_for_display(self, temp): """Convert temperature into preferred units for display purposes.""" if temp is None: return None value = convert(temp, self.unit_of_measurement, self.hass.config.temperature_unit) if self.hass.config.temperature_unit is TEMP_CELSIUS: decimal_count = 1 else: # Users of fahrenheit generally expect integer units. decimal_count = 0 return round(value, decimal_count)
def temperature_set_service(service): """ Set temperature on the target thermostats """ target_thermostats = component.extract_from_service(service) temperature = util.convert(service.data.get(ATTR_TEMPERATURE), float) if temperature is None: return for thermostat in target_thermostats: thermostat.set_temperature( convert(temperature, hass.config.temperature_unit, thermostat.unit_of_measurement)) thermostat.update_ha_state(True)
def temperature_set_service(service): """Set temperature on the target thermostats.""" target_thermostats = component.extract_from_service(service) temperature = util.convert(service.data.get(ATTR_TEMPERATURE), float) if temperature is None: _LOGGER.error("Received call to %s without attribute %s", SERVICE_SET_TEMPERATURE, ATTR_TEMPERATURE) return for thermostat in target_thermostats: thermostat.set_temperature( convert(temperature, hass.config.temperature_unit, thermostat.unit_of_measurement)) thermostat.update_ha_state(True)
def temperature_set_service(service): """ Set temperature on the target thermostats """ target_thermostats = component.extract_from_service(service) temperature = util.convert( service.data.get(ATTR_TEMPERATURE), float) if temperature is None: return for thermostat in target_thermostats: thermostat.set_temperature(convert( temperature, hass.config.temperature_unit, thermostat.unit_of_measurement)) thermostat.update_ha_state(True)
def temperature_set_service(service): """Set temperature on the target thermostats.""" target_thermostats = component.extract_from_service(service) temperature = util.convert( service.data.get(ATTR_TEMPERATURE), float) if temperature is None: _LOGGER.error( "Received call to %s without attribute %s", SERVICE_SET_TEMPERATURE, ATTR_TEMPERATURE) return for thermostat in target_thermostats: thermostat.set_temperature(convert( temperature, hass.config.temperature_unit, thermostat.unit_of_measurement)) thermostat.update_ha_state(True)
def max_temp(self): """ Return maxmum temperature. """ return convert(35, TEMP_CELCIUS, self.unit_of_measurement)
def min_temp(self): """ Return minimum temperature. """ return convert(7, TEMP_CELCIUS, self.unit_of_measurement)
def max_temp(self): """Return the maximum temperature.""" return convert(self._thermostat.max_temp, TEMP_CELCIUS, self.unit_of_measurement)
def min_temp(self): """Return the minimum temperature - 4.5 means off.""" return convert(4.5, TEMP_CELSIUS, self.unit_of_measurement)
def min_temp(self): """Return the minimum temperature.""" return convert(7, TEMP_CELSIUS, self.unit_of_measurement)
def min_temp(self): """Return the minimum temperature.""" return round(convert(4.5, TEMP_CELCIUS, self.unit_of_measurement))
def max_temp(self): """Return the maximum temperature - 30.5 means on.""" return convert(30.5, TEMP_CELSIUS, self.unit_of_measurement)
def max_temp(self): """Return the maximum temperature.""" return convert(35, TEMP_CELSIUS, self.unit_of_measurement)
def min_temp(self): """ Return minimum temperature. """ return round(convert(7, TEMP_CELCIUS, self.unit_of_measurement))
def max_temp(self): """ Return maxmum temperature. """ return round(convert(35, TEMP_CELCIUS, self.unit_of_measurement))