def get_value(self): value = 0 if self.state.domain == air_quality.DOMAIN: value = self.state.attributes.get( 'total_volatile_organic_compounds') if value in (STATE_UNAVAILABLE, STATE_UNKNOWN, None): raise SmartHomeError(ERR_NOT_SUPPORTED_IN_CURRENT_MODE, "Invalid tvoc property value") return float(value)
def get_value(self): value = 0 if self.state.domain == vacuum.DOMAIN: value = self.state.attributes.get(vacuum.ATTR_BATTERY_LEVEL) elif self.state.domain == sensor.DOMAIN or self.state.domain == binary_sensor.DOMAIN: value = self.state.attributes.get(ATTR_BATTERY_LEVEL) if value in (STATE_UNAVAILABLE, STATE_UNKNOWN, None): raise SmartHomeError(ERR_NOT_SUPPORTED_IN_CURRENT_MODE, "Invalid value") return float(value)
def get_value(self): value = False if self.state.domain == binary_sensor.DOMAIN: value = self.state.state if value in (STATE_UNAVAILABLE, STATE_UNKNOWN, None): raise SmartHomeError( ERR_NOT_SUPPORTED_IN_CURRENT_MODE, "Invalid {} property value".format(self.instance)) return self.event_value(value)
def get_value(self): value = 0.0 if self.state.domain == sensor.DOMAIN: value = self.state.state if value in (STATE_UNAVAILABLE, STATE_UNKNOWN, None): raise SmartHomeError( ERR_NOT_SUPPORTED_IN_CURRENT_MODE, "Invalid value") # Get a conversion multiplier to pascal unit = self.state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) if not unit in PRESSURE_TO_PASCAL: raise SmartHomeError( ERR_NOT_SUPPORTED_IN_CURRENT_MODE, f"Unsupported pressure unit: {unit}") # Convert the value to pascal and then to the chosen Yandex unit val = float(value) * PRESSURE_TO_PASCAL[unit] * PRESSURE_FROM_PASCAL[self.config.settings[CONF_PRESSURE_UNIT]] return round(val, 2)
def get_value(self): value = 0 if self.state.domain == sensor.DOMAIN: value = self.state.state elif self.state.domain == climate.DOMAIN: value = self.state.attributes.get(climate.ATTR_CURRENT_HUMIDITY) if value in (STATE_UNAVAILABLE, STATE_UNKNOWN, None): raise SmartHomeError(ERR_NOT_SUPPORTED_IN_CURRENT_MODE, "Invalid value") return float(value)
def get_value(self): value = 0 attribute = None if CONF_ENTITY_PROPERTY_ATTRIBUTE in self.property_config: attribute = self.property_config.get( CONF_ENTITY_PROPERTY_ATTRIBUTE) if attribute: value = self.state.attributes.get(attribute) if CONF_ENTITY_PROPERTY_ENTITY in self.property_config: property_entity_id = self.property_config.get( CONF_ENTITY_PROPERTY_ENTITY) entity = self.hass.states.get(property_entity_id) if entity is None: _LOGGER.error(f'Entity not found: {property_entity_id}') raise SmartHomeError(ERR_DEVICE_NOT_FOUND, "Entity not found") if attribute: value = entity.attributes.get(attribute) else: value = entity.state if value in (STATE_UNAVAILABLE, STATE_UNKNOWN, None): _LOGGER.error(f'Invalid value: {entity}') raise SmartHomeError(ERR_INVALID_VALUE, "Invalid value") if self.instance == 'pressure': # Get a conversion multiplier to pascal unit = entity.attributes.get(ATTR_UNIT_OF_MEASUREMENT) if unit not in PRESSURE_TO_PASCAL: raise SmartHomeError(ERR_NOT_SUPPORTED_IN_CURRENT_MODE, f"Unsupported pressure unit: {unit}") # Convert the value to pascal and then to the chosen Yandex unit value = round(float(value) * PRESSURE_TO_PASCAL[unit] * \ PRESSURE_FROM_PASCAL[self.config.settings[CONF_PRESSURE_UNIT]], 2) return float( value) if self.type != PROPERTY_EVENT else self.event_value(value)
def get_value(self): value = 0 if self.state.domain == sensor.DOMAIN: value = self.state.state elif self.state.domain == switch.DOMAIN or self.state.domain == light.DOMAIN: value = self.state.attributes.get('current') if value in (STATE_UNAVAILABLE, STATE_UNKNOWN, None): raise SmartHomeError(ERR_NOT_SUPPORTED_IN_CURRENT_MODE, "Invalid amperage property value") return float(value)
def get_value(self): value = 0 if self.state.domain == sensor.DOMAIN: value = self.state.state elif self.state.domain == air_quality.DOMAIN or self.state.domain == fan.DOMAIN: value = self.state.attributes.get(air_quality.ATTR_CO2) if value in (STATE_UNAVAILABLE, STATE_UNKNOWN, None): raise SmartHomeError(ERR_NOT_SUPPORTED_IN_CURRENT_MODE, "Invalid co2 level property value") return float(value)
def get_value(self): value = 0.0 if self.state.domain == sensor.DOMAIN: value = self.state.state elif self.state.domain == climate.DOMAIN or self.state.domain == fan.DOMAIN or self.state.domain == humidifier.DOMAIN: value = self.state.attributes.get(climate.ATTR_CURRENT_TEMPERATURE) if value in (STATE_UNAVAILABLE, STATE_UNKNOWN, None): raise SmartHomeError(ERR_NOT_SUPPORTED_IN_CURRENT_MODE, "Invalid temperature property value") return float(value)
def __init__(self, hass, state, entity_config, property_config): super().__init__(hass, state, entity_config) self.instance_unit = { 'humidity': 'unit.percent', 'temperature': 'unit.temperature.celsius', 'pressure': PRESSURE_UNITS_TO_YANDEX_UNITS[ self.config.settings[CONF_PRESSURE_UNIT]], 'water_level': 'unit.percent', 'co2_level': 'unit.ppm', 'power': 'unit.watt', 'voltage': 'unit.volt', 'battery_level': 'unit.percent', 'amperage': 'unit.ampere', 'illumination': 'unit.illumination.lux', 'tvoc': 'unit.density.mcg_m3', 'pm1_density': 'unit.density.mcg_m3', 'pm2.5_density': 'unit.density.mcg_m3', 'pm10_density': 'unit.density.mcg_m3' } self.property_config = property_config self.type = PROPERTY_FLOAT self.instance = property_config.get(CONF_ENTITY_PROPERTY_TYPE) if CONF_ENTITY_PROPERTY_ENTITY in self.property_config: property_entity_id = self.property_config.get( CONF_ENTITY_PROPERTY_ENTITY) entity = self.hass.states.get(property_entity_id) if entity is None: _LOGGER.error(f'Entity not found: {property_entity_id}') raise SmartHomeError(ERR_DEVICE_NOT_FOUND, "Entity not found") if entity.domain == binary_sensor.DOMAIN and self.instance in EVENTS_VALUES.keys( ): self.type = PROPERTY_EVENT self.values = EVENTS_VALUES.get(self.instance)
def parameters(self): if self.instance in self.instance_unit: unit = self.instance_unit[self.instance] return {'instance': self.instance, 'unit': unit} elif self.type == PROPERTY_EVENT: return { 'instance': self.instance, 'events': [{ 'value': v } for v in self.values] } if self.values else {} raise SmartHomeError( ERR_NOT_SUPPORTED_IN_CURRENT_MODE, "Unit not found for type: {}".format(self.instance))
def get_value(self): value = 0 if self.state.domain == sensor.DOMAIN: value = self.state.state elif self.state.domain == switch.DOMAIN: if 'power' in self.state.attributes: value = self.state.attributes.get('power') elif 'load_power' in self.state.attributes: value = self.state.attributes.get('load_power') if value in (STATE_UNAVAILABLE, STATE_UNKNOWN, None): raise SmartHomeError(ERR_NOT_SUPPORTED_IN_CURRENT_MODE, "Invalid power property value") return float(value)
def __init__(self, hass, state, entity_config, property_config): super().__init__(hass, state, entity_config) self.hass = hass self.state = state self.entity_config = entity_config self.property_config = property_config self.type = PROPERTY_FLOAT self.instance = property_config.get(CONF_ENTITY_PROPERTY_TYPE) if CONF_ENTITY_PROPERTY_ENTITY in self.property_config: property_entity_id = self.property_config.get( CONF_ENTITY_PROPERTY_ENTITY) entity = self.hass.states.get(property_entity_id) if entity is None: _LOGGER.error(f'Entity not found: {property_entity_id}') raise SmartHomeError(ERR_DEVICE_NOT_FOUND, "Entity not found") if entity.domain == binary_sensor.DOMAIN: self.type = PROPERTY_BOOL
async def error(*args, **kwargs): raise SmartHomeError(ERR_INVALID_ACTION, '')
async def set_state(self, *args, **kwargs): raise SmartHomeError(ERR_INVALID_ACTION, '')
def parameters(self): if self.instance in self.instance_unit: unit = self.instance_unit[self.instance] return {'instance': self.instance, 'unit': unit} raise SmartHomeError(ERR_NOT_SUPPORTED_IN_CURRENT_MODE, "unit not found for type: {}".format(self.instance))