def __init__(self, hass, device, attribute): """Initialize the sensor.""" self._device = device self._attribute = attribute self._device_class = None if self._is_zone_status(): self._is_on = attribute.get('value', {}).get('alarm1', False) else: self._is_on = attribute.get('value', False) name = attribute.get('name') ieee = device.ieee or device.addr # compatibility entity_id = 'zigate_{}_{}'.format(ieee, name) self.entity_id = ENTITY_ID_FORMAT.format(entity_id) typ = self._device.get_value('type', '').lower() if name == 'presence': self._device_class = 'motion' elif 'magnet' in typ: self._device_class = 'door' elif 'smok' in typ: self._device_class = 'smoke' elif 'zone_status' in name: self._device_class = 'safety' hass.bus.listen('zigate.attribute_updated', self._handle_event)
def __init__(self, serial, entity_id, name, icon, device_class, attributes): """Initialize a binary sensor. Args: serial (str): serial of the mower entity_id (str): entity_id of the sensor name (str): name of the sensor icon (str, Callable): string or function for icons device_class (str): device class of the sensor """ self._serial = serial self.entity_id = BINARY_SENSOR_FORMAT.format(entity_id) self._unique_id = entity_id self._name = name self._updateble_icon = callable(icon) if self._updateble_icon: self._icon_func = icon self._icon = icon(None) else: self._icon = icon self._device_class = device_class self._attr = {key: None for key in attributes} self._should_poll = False self._state = None self._is_on = None
def __init__(self, tesla_device, controller, sensor_type): """Initialisation of binary sensor.""" super().__init__(tesla_device, controller) self._name = self.tesla_device.name self._state = False self.entity_id = ENTITY_ID_FORMAT.format(self.tesla_id) self._sensor_type = sensor_type
def __init__( self, entity_id: str, name: str, device_class: str, port: int, account: str, zone: int, ping_interval: int, ): """Create SIABinarySensor object.""" self.entity_id = BINARY_SENSOR_FORMAT.format(entity_id) self._unique_id = entity_id self._name = name self._device_class = device_class self._port = port self._account = account self._zone = zone self._ping_interval = ping_interval self._should_poll = False self._is_on = None self._is_available = True self._remove_unavailability_tracker = None self._attr = { CONF_ACCOUNT: self._account, CONF_PING_INTERVAL: str(self._ping_interval), CONF_ZONE: self._zone, }
def __init__(self, tesla_device, controller, sensor_type): """Initialisation of binary sensor.""" super().__init__(tesla_device, controller) self._name = self.tesla_device.name self._state = False self.entity_id = ENTITY_ID_FORMAT.format(self.tesla_id) self._sensor_type = sensor_type
class FritzBoxConnectivitySensor(BinarySensorDevice): name = "FRITZ!Box Connectivity" entity_id = ENTITY_ID_FORMAT.format("fritzbox_connectivity") icon = "mdi:router-wireless" device_class = "connectivity" def __init__(self, fritzbox_tools): self.fritzbox_tools = fritzbox_tools self._is_on = True # We assume the fritzbox to be online initially self._is_available = ( True # set to False if an error happend during toggling the switch ) self._attributes = defaultdict(str) super().__init__() @property def is_on(self) -> bool: return self._is_on @property def unique_id(self): return f"{self.fritzbox_tools.unique_id}-{self.entity_id}" @property def device_info(self): return self.fritzbox_tools.device_info @property def available(self) -> bool: return self._is_available @property def device_state_attributes(self) -> dict: return self._attributes async def _async_fetch_update(self): self._is_on = True try: status = self.fritzbox_tools.fritzstatus self._is_on = status.is_connected self._is_available = True for attr in [ "modelname", "external_ip", "external_ipv6", "uptime", "str_uptime", ]: self._attributes[attr] = getattr(status, attr) except Exception: _LOGGER.error("Error getting the state from the FRITZ!Box", exc_info=True) self._is_available = False async def async_update(self) -> None: _LOGGER.debug("Updating Connectivity sensor...") await self._async_fetch_update()
def __init__(self, connection, config): """Initialize sensor with car connection.""" self._conn = connection self._name = config.name self._attr = config.attr self._type = config.device_class self._is_on = None self.entity_id = ENTITY_ID_FORMAT.format( '{}_{}'.format(MYCHEVY_DOMAIN, slugify(self._name)))
def __init__(self, connection, config, car_vid): """Initialize sensor with car connection.""" self._conn = connection self._name = config.name self._attr = config.attr self._type = config.device_class self._is_on = None self._car_vid = car_vid self.entity_id = ENTITY_ID_FORMAT.format('{}_{}_{}'.format( MYCHEVY_DOMAIN, slugify(self._car.name), slugify(self._name)))
def __init__(self, fritzbox_tools): self.fritzbox_tools = fritzbox_tools self.entity_id = ENTITY_ID_FORMAT.format( f"fritzbox_{self.fritzbox_tools.fritzbox_model}_connectivity") self._is_on = True # We assume the fritzbox to be online initially self._is_available = ( True # set to False if an error happend during toggling the switch ) self._attributes = defaultdict(str) super().__init__()
def __init__(self, client, heater) -> None: """Initialize the binary sensor.""" super().__init__() self._unique_id = f"{heater.serial_no}_failed" self.entity_id = ENTITY_ID_FORMAT.format(f"{DOMAIN}_failed") self._name = "Boiler Fault" self._client = client self._heater = heater
def __init__(self, fibaro_device: Any) -> None: """Initialize the binary_sensor.""" super().__init__(fibaro_device) self.entity_id = ENTITY_ID_FORMAT.format(self.ha_id) stype = None if fibaro_device.type in SENSOR_TYPES: stype = fibaro_device.type elif fibaro_device.baseType in SENSOR_TYPES: stype = fibaro_device.baseType if stype: self._attr_device_class = SENSOR_TYPES[stype][2] self._attr_icon = SENSOR_TYPES[stype][1]
def __init__(self, uplink, system_id, parameter_id, name=None, object_id=None, data=None): super().__init__(uplink, system_id, parameter_id) self._name = name self.parse_data(data) if object_id: # Forced id on discovery self.entity_id = ENTITY_ID_FORMAT.format(object_id)
def add_new_device(sensor): name, device_class, _, _ = get_sensor_details(sensor) _LOGGER.debug("adding binary sensor %s with id %s", name, sensor["id"]) kubemotionsensor = KubeMotionDevice( hass=hass, name=name, state_topic="/sensor/" + sensor["id"] + "/" + sensor["data_type"], device_class=device_class, qos=0, force_update=False, timeout=DEFAULT_TIMEOUT, unique_id=ENTITY_ID_FORMAT.format(sensor["id"])) # Add device entity async_add_devices([kubemotionsensor])
def __init__(self, dev, idx, val, param): super().__init__(dev, idx, val, param) self.entity_id = ENTITY_ID_FORMAT.format( (dev['devtype'] + "_" + dev['me'] + "_" + idx).lower()) devtype = dev['devtype'] if devtype in GUARD_SENSOR: self._device_class = "door" elif devtype in MOTION_SENSOR: self._device_class = "motion" else: self._device_class = "smoke" if val['val'] == 1: self._state = True else: self._state = False
def __init__(self, fibaro_device, controller): """Initialize the binary_sensor.""" self._state = None super().__init__(fibaro_device, controller) self.entity_id = ENTITY_ID_FORMAT.format(self.ha_id) stype = None if fibaro_device.type in SENSOR_TYPES: stype = fibaro_device.type elif fibaro_device.baseType in SENSOR_TYPES: stype = fibaro_device.baseType if stype: self._device_class = SENSOR_TYPES[stype][2] self._icon = SENSOR_TYPES[stype][1] else: self._device_class = None self._icon = None
def __init__(self, fibaro_device, controller): """Initialize the binary_sensor.""" self._state = None super().__init__(fibaro_device, controller) self.entity_id = ENTITY_ID_FORMAT.format(self.ha_id) stype = None if fibaro_device.type in SENSOR_TYPES: stype = fibaro_device.type elif fibaro_device.baseType in SENSOR_TYPES: stype = fibaro_device.baseType if stype: self._device_class = SENSOR_TYPES[stype][2] self._icon = SENSOR_TYPES[stype][1] else: self._device_class = None self._icon = None
def __init__(self, device, attribute): """Initialize the sensor.""" self._device = device self._attribute = attribute self._device_class = None name = attribute.get('name') entity_id = 'zigate_{}_{}'.format(device.addr, name) self.entity_id = ENTITY_ID_FORMAT.format(entity_id) typ = self._device.get_value('type', '').lower() if name == 'presence': self._device_class = 'motion' elif 'magnet' in typ: self._device_class = 'door' elif 'smok' in typ: self._device_class = 'smoke' elif 'zone_status' in name: self._device_class = 'safety'
def __init__(self, fibaro_device): """Initialize the binary_sensor.""" self._state = None super().__init__(fibaro_device) self.entity_id = ENTITY_ID_FORMAT.format(self.ha_id) stype = None devconf = fibaro_device.device_config if fibaro_device.type in SENSOR_TYPES: stype = fibaro_device.type elif fibaro_device.baseType in SENSOR_TYPES: stype = fibaro_device.baseType if stype: self._device_class = SENSOR_TYPES[stype][2] self._icon = SENSOR_TYPES[stype][1] else: self._device_class = None self._icon = None # device_config overrides: self._device_class = devconf.get(CONF_DEVICE_CLASS, self._device_class) self._icon = devconf.get(CONF_ICON, self._icon)
def __init__(self, fibaro_device): """Initialize the binary_sensor.""" self._state = None super().__init__(fibaro_device) self.entity_id = ENTITY_ID_FORMAT.format(self.ha_id) stype = None devconf = fibaro_device.device_config if fibaro_device.type in SENSOR_TYPES: stype = fibaro_device.type elif fibaro_device.baseType in SENSOR_TYPES: stype = fibaro_device.baseType if stype: self._device_class = SENSOR_TYPES[stype][2] self._icon = SENSOR_TYPES[stype][1] else: self._device_class = None self._icon = None # device_config overrides: self._device_class = devconf.get(CONF_DEVICE_CLASS, self._device_class) self._icon = devconf.get(CONF_ICON, self._icon)
async def add_new_device(sensor): name, device_class, _, _ = get_sensor_details(sensor) _LOGGER.debug("adding binary sensor %s with id %s", name, sensor["id"]) mqttsensorconfig = {} mqttsensorconfig["platform"] = "mqtt" mqttsensorconfig["name"] = name mqttsensorconfig["state_topic"] = "/sensor/" + sensor[ "id"] + "/" + sensor["data_type"] if device_class: mqttsensorconfig["device_class"] = device_class if device_class and (device_class == "problem"): mqttsensorconfig["value_template"] = """ {% if (value.split(",")[1]|int) > 0 %} ON {% else %} OFF {% endif %}""" else: mqttsensorconfig["off_delay"] = DEFAULT_TIMEOUT mqttsensorconfig["value_template"] = """ {% if value %} ON {% else %} OFF {% endif %}""" mqttsensorconfig["unique_id"] = ENTITY_ID_FORMAT.format(sensor["id"]) mqttsensorconfig["qos"] = "0" mqttsensorconfig["force_update"] = "false" config = MQTT_BINARY_SENSOR_PLATFORM_SCHEMA(mqttsensorconfig) # Add device entity async_add_devices([MqttBinarySensor(config, None, None)])
def __init__(self, hubitat_device): self._state = False super().__init__(hubitat_device) self.entity_id = ENTITY_ID_FORMAT.format(self.entity_id)
def __init__(self, vera_device, controller): """Initialize the binary_sensor.""" self._state = False VeraDevice.__init__(self, vera_device, controller) self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
def __init__(self, vera_device, controller): """Initialize the binary_sensor.""" self._state = False VeraDevice.__init__(self, vera_device, controller) self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
def __init__(self, vera_device: veraApi.VeraBinarySensor, controller_data: ControllerData): """Initialize the binary_sensor.""" self._state = False VeraDevice.__init__(self, vera_device, controller_data) self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)