def __init__(
        self,
        container,
        prefix,
        cname,
        alias,
        variable,
        sensor_name_format,
        condition_list=None,
    ):
        """Initialize the sensor."""
        self._loop = asyncio.get_running_loop()
        self._container = container
        self._prefix = prefix
        self._cname = cname
        self._condition_list = condition_list

        self._var_id = variable

        if self._var_id == CONTAINER_INFO_ALLINONE:
            self._var_name = CONTAINER_MONITOR_LIST[CONTAINER_INFO_STATE][0]
            self._var_unit = CONTAINER_MONITOR_LIST[CONTAINER_INFO_STATE][1]
            self._var_icon = CONTAINER_MONITOR_LIST[CONTAINER_INFO_STATE][2]
            self._var_class = CONTAINER_MONITOR_LIST[CONTAINER_INFO_STATE][3]
        else:
            self._var_name = CONTAINER_MONITOR_LIST[variable][0]
            self._var_unit = CONTAINER_MONITOR_LIST[variable][1]
            self._var_icon = CONTAINER_MONITOR_LIST[variable][2]
            self._var_class = CONTAINER_MONITOR_LIST[variable][3]

        self._state_extra = None

        if self._var_id == CONTAINER_INFO_ALLINONE:
            self._entity_id = ENTITY_ID_FORMAT.format(
                slugify(self._prefix + "_" + self._cname))
            self._name = sensor_name_format.format(name=alias,
                                                   sensorname="",
                                                   sensor="")
        else:
            self._entity_id = ENTITY_ID_FORMAT.format(
                slugify(self._prefix + "_" + self._cname + "_" +
                        self._var_name))
            self._name = sensor_name_format.format(name=alias,
                                                   sensorname=self._var_name,
                                                   sensor=self._var_name)

        self._state = None
        self._state_extra = None

        self._attributes = {}

        _LOGGER.info("%s: Initializing sensor with parameter: %s", self._cname,
                     self._var_name)
示例#2
0
    def __init__(self, tesla_device, controller, sensor_type=None):
        """Initialize of the sensor."""
        self.current_value = None
        self._unit = None
        self.last_changed_time = None
        self.type = sensor_type
        super().__init__(tesla_device, controller)

        if self.type:
            self._name = '{} ({})'.format(self.tesla_device.name, self.type)
            self.entity_id = ENTITY_ID_FORMAT.format(
                '{}_{}'.format(self.tesla_id, self.type))
        else:
            self.entity_id = ENTITY_ID_FORMAT.format(self.tesla_id)
示例#3
0
    def __init__(self, tesla_device, controller, sensor_type=None):
        """Initialize of the sensor."""
        self.current_value = None
        self._unit = None
        self.last_changed_time = None
        self.type = sensor_type
        super().__init__(tesla_device, controller)

        if self.type:
            self._name = '{} ({})'.format(self.tesla_device.name, self.type)
            self.entity_id = ENTITY_ID_FORMAT.format(
                '{}_{}'.format(self.tesla_id, self.type))
        else:
            self.entity_id = ENTITY_ID_FORMAT.format(self.tesla_id)
示例#4
0
    def __init__(self, gateway):
        """Initialize the sensor."""
        self.current_value = None
        self._latest_cluster_health = {}
        self._gateway = gateway

        self.entity_id = ENTITY_ID_FORMAT.format("es_cluster_health")
示例#5
0
文件: sensor.py 项目: jcgoette/core
 def __init__(self, fibaro_device):
     """Initialize the sensor."""
     self.current_value = None
     self.last_changed_time = None
     super().__init__(fibaro_device)
     self.entity_id = ENTITY_ID_FORMAT.format(self.ha_id)
     if fibaro_device.type in SENSOR_TYPES:
         self._unit = SENSOR_TYPES[fibaro_device.type][1]
         self._icon = SENSOR_TYPES[fibaro_device.type][2]
         self._device_class = SENSOR_TYPES[fibaro_device.type][3]
         self._attr_state_class = SENSOR_TYPES[fibaro_device.type][4]
     else:
         self._unit = None
         self._icon = None
         self._device_class = None
     with suppress(KeyError, ValueError):
         if not self._unit:
             if self.fibaro_device.properties.unit == "lux":
                 self._unit = LIGHT_LUX
             elif self.fibaro_device.properties.unit == "C":
                 self._unit = TEMP_CELSIUS
             elif self.fibaro_device.properties.unit == "F":
                 self._unit = TEMP_FAHRENHEIT
             else:
                 self._unit = self.fibaro_device.properties.unit
示例#6
0
 def __init__(self, config_entry: ConfigEntry,
              publisher: DocumentPublisher):
     super().__init__(config_entry)
     self._publisher = publisher
     self.current_value = None
     self.attr = {}
     self.entity_id = ENTITY_ID_FORMAT.format("es_publish_queue")
示例#7
0
    def __init__(
        self, serial, entity_id, name, icon, device_class, unit_of_measurement, attributes
    ):
        """Initialize a 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
            unit_of_measurement (str): unit of measurement of the sensor

        """
        self._serial = serial
        self.entity_id = 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._unit = unit_of_measurement
        self._attr = {key: None for key in attributes}
        self._state = None
        self._should_poll = False
示例#8
0
 def __init__(self, vera_device, controller):
     """Initialize the sensor."""
     self.current_value = None
     self._temperature_units = None
     self.last_changed_time = None
     VeraDevice.__init__(self, vera_device, controller)
     self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
    def __init__(self, api, instance, prefix, variable):
        """Initialize the sensor."""

        self._loop = asyncio.get_running_loop()
        self._api = api
        self._instance = instance
        self._prefix = prefix

        self._var_id = variable
        self._var_name = DOCKER_MONITOR_LIST[variable][0]
        self._var_unit = DOCKER_MONITOR_LIST[variable][1]
        self._var_icon = DOCKER_MONITOR_LIST[variable][2]
        self._var_class = DOCKER_MONITOR_LIST[variable][3]

        self._entity_id = ENTITY_ID_FORMAT.format(
            slugify(self._prefix + "_" + self._var_name)
        )
        self._name = "{name} {sensor}".format(name=self._prefix, sensor=self._var_name)

        self._state = None
        self._attributes = {}

        _LOGGER.info(
            "[%s]: Initializing Docker sensor '%s'", self._instance, self._var_id
        )
示例#10
0
    def __init__(
        self,
        entity_id: str,
        name: str,
        device_class: str,
        port: int,
        account: str,
        zone: int,
        ping_interval: int,
    ):
        """Create SIASensor object."""
        self.entity_id = 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 = str(ping_interval)

        self._state = utcnow()
        self._should_poll = False
        self._attr = {
            CONF_ACCOUNT: self._account,
            CONF_PING_INTERVAL: self._ping_interval,
            CONF_ZONE: self._zone,
        }
示例#11
0
 def __init__(self, fibaro_device, controller):
     """Initialize the sensor."""
     self.current_value = None
     self.last_changed_time = None
     super().__init__(fibaro_device, controller)
     self.entity_id = ENTITY_ID_FORMAT.format(self.ha_id)
     if fibaro_device.type in SENSOR_TYPES:
         self._unit = SENSOR_TYPES[fibaro_device.type][1]
         self._icon = SENSOR_TYPES[fibaro_device.type][2]
         self._device_class = SENSOR_TYPES[fibaro_device.type][3]
     else:
         self._unit = None
         self._icon = None
         self._device_class = None
     try:
         if not self._unit:
             if self.fibaro_device.properties.unit == 'lux':
                 self._unit = 'lx'
             elif self.fibaro_device.properties.unit == 'C':
                 self._unit = TEMP_CELSIUS
             elif self.fibaro_device.properties.unit == 'F':
                 self._unit = TEMP_FAHRENHEIT
             else:
                 self._unit = self.fibaro_device.properties.unit
     except (KeyError, ValueError):
         pass
示例#12
0
    def __init__(self, hass, meross_device_uuid, meross_device_name,
                 meross_sensor_name):
        # attributes
        self._value = 0
        self._meross_sensor_name = meross_sensor_name

        # add entity to the meross_plug
        self._meross_plug = hass.data[DOMAIN].meross_plugs_by_uuid[
            meross_device_uuid]
        meross_device = self._meross_plug.device
        meross_device_online = meross_device.online
        self._meross_plug.sensor_states[meross_sensor_name] = {
            'available': meross_device_online,
            'value': self._value,
        }

        # naming
        meross_sensor_id = "{}_{}_{}".format(
            DOMAIN, meross_device_uuid,
            MEROSS_SENSORS_MAP[meross_sensor_name]['eid'])
        meross_entity_id = ENTITY_ID_FORMAT.format(meross_sensor_id)
        _LOGGER.debug(meross_device_name + ' >>> ' + meross_sensor_name +
                      ' >>> __init__()')

        # init MerossEntity
        super().__init__(hass, meross_device_uuid, meross_device_name,
                         meross_entity_id, meross_sensor_name,
                         meross_device_online)
示例#13
0
 def __init__(self, fibaro_device):
     """Initialize the sensor."""
     self.current_value = None
     self.last_changed_time = None
     super().__init__(fibaro_device)
     self.entity_id = ENTITY_ID_FORMAT.format(self.ha_id)
     if fibaro_device.type in SENSOR_TYPES:
         self._unit = SENSOR_TYPES[fibaro_device.type][1]
         self._icon = SENSOR_TYPES[fibaro_device.type][2]
         self._device_class = SENSOR_TYPES[fibaro_device.type][3]
     else:
         self._unit = None
         self._icon = None
         self._device_class = None
     try:
         if not self._unit:
             if self.fibaro_device.properties.unit == 'lux':
                 self._unit = 'lx'
             elif self.fibaro_device.properties.unit == 'C':
                 self._unit = TEMP_CELSIUS
             elif self.fibaro_device.properties.unit == 'F':
                 self._unit = TEMP_FAHRENHEIT
             else:
                 self._unit = self.fibaro_device.properties.unit
     except (KeyError, ValueError):
         pass
示例#14
0
 def __init__(self, vera_device, controller):
     """Initialize the sensor."""
     self.current_value = None
     self._temperature_units = None
     self.last_changed_time = None
     VeraDevice.__init__(self, vera_device, controller)
     self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
示例#15
0
文件: ikea.py 项目: psvanstrom/hass
 def __init__(self, name, friendly_name, product_id, store_id, url_locale):
     self.entity_id = ENTITY_ID_FORMAT.format(slugify(name))
     self._friendly_name = friendly_name
     self._url = "https://www.ikea.com/{}/iows/catalog/availability/{}". \
                format(url_locale, product_id)
     self._data = None
     self._product_id = product_id
     self._store_id = store_id
示例#16
0
 def __init__(self, hass, watcher, section, index):
     """Initialize the section sensor."""
     self.hass = hass
     self.watcher = watcher
     self.section = section
     self.index = index
     self.entity_id = ENTITY_ID_FORMAT.format(slugify(section + '_' + str(index)))
     self._latest_item = None
示例#17
0
 def __init__(self, homee_node, homee_attribute, cube):
     """Initialize the sensor."""
     self.current_value = homee_attribute.value
     self.attribute_id = homee_attribute.id
     self._temperature_units = None
     HomeeDevice.__init__(self, homee_node, homee_attribute, cube)
     self.entity_id = ENTITY_ID_FORMAT.format(self.homee_id)
     self.update_state(homee_attribute)
示例#18
0
    def __init__(self, config_entry: ConfigEntry, gateway):
        """Initialize the sensor."""
        super().__init__(config_entry)
        self.current_value = DEFAULT_CLUSTER_HEALTH
        self._latest_cluster_health = {}
        self._gateway = gateway
        self._available = False

        self.entity_id = ENTITY_ID_FORMAT.format("es_cluster_health")
示例#19
0
 def __init__(self, hass, name, devType):
     """Initialize the sensor."""
     self._hass = hass
     self.entity_id = ENTITY_ID_FORMAT.format(slugify(devType))
     self._name = name
     self._type = devType
     self._state = None
     self._attributes = {}
     hass.bus.listen(CONF_EVENT_ZINGUO_SENSOR, self._handle_event)
示例#20
0
 def __init__(
     self, vera_device: veraApi.VeraSensor, controller_data: ControllerData
 ) -> None:
     """Initialize the sensor."""
     self.current_value: StateType = None
     self._temperature_units: str | None = None
     self.last_changed_time = None
     VeraDevice.__init__(self, vera_device, controller_data)
     self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
示例#21
0
 def __init__(self, visonic_device):
     """Initialize the sensor."""
     #_LOGGER.info("Creating binary sensor {0}".format(visonic_device.dname))
     self.visonic_device = visonic_device
     self._name = "visonic_" + self.visonic_device.dname.lower()
     # Append device id to prevent name clashes in HA.
     self.visonic_id = slugify(self._name) # VISONIC_ID_FORMAT.format( slugify(self._name), visonic_device.getDeviceID())
     self.entity_id = ENTITY_ID_FORMAT.format(self.visonic_id)
     self.current_value = self.visonic_device.triggered or self.visonic_device.status
     self.visonic_device.install_change_handler(self.onChange)
    def __init__(self, coordinator, name, entity_id, icon):
        """Initialize Entities."""

        self._name = name
        self.entity_id = ENTITY_ID_FORMAT.format(entity_id)
        self._state = None
        self._icon = icon
        self._kind = entity_id
        self.coordinator = coordinator
        self.attrs = {}
示例#23
0
    def __init__(self, device, host, config):
        """Initialize sensor."""
        self._device = device
        self._host = host
        self._name = config[0]
        self._child = config[1]
        self._attr = config[2]
        self._unit_of_measurement = config[3]
        self._state = None

        self.entity_id = ENTITY_ID_FORMAT.format('{}_{}'.format(COOKER_DOMAIN, slugify(self._name)))
示例#24
0
 def __init__(self, data, sensor_type):
     """Initialize the sensor."""
     self.data = data
     self.type = sensor_type
     self.entity_id = ENTITY_ID_FORMAT.format(SENSOR_PREFIX + "_" +
                                              sensor_type)
     self._name = SENSOR_TYPES[self.type][0]
     self._unit_of_measurement = SENSOR_TYPES[self.type][1]
     self._icon = SENSOR_TYPES[self.type][2]
     self._state = None
     self.update()
示例#25
0
    def __init__(self, connection, config):
        """Initialize sensor with car connection."""
        self._conn = connection
        self._name = config.name
        self._attr = config.attr
        self._unit_of_measurement = config.unit_of_measurement
        self._icon = config.icon
        self._state = None

        self.entity_id = ENTITY_ID_FORMAT.format(
            '{}_{}'.format(MYCHEVY_DOMAIN, slugify(self._name)))
示例#26
0
 def __init__(self, hass, scraper, waste_type):
     self._state = None
     self._waste_type = waste_type
     self._scraper = scraper
     self._attributes = {
         ATTR_ADDRESS: self._scraper._address,
         ATTR_FRIENDLY_NAME: self._waste_type
         }
     self.entity_slug = "{} {}".format(self._scraper._address, self._waste_type)
     self.entity_id = ENTITY_ID_FORMAT.format(
         slugify(self.entity_slug.replace(' ', '_')))
示例#27
0
文件: sensor.py 项目: jbouwh/core
    def __init__(self, fibaro_device: Any,
                 entity_description: SensorEntityDescription) -> None:
        """Initialize the sensor."""
        super().__init__(fibaro_device)
        self.entity_description = entity_description

        # To differentiate additional sensors from main sensors they need
        # to get different names and ids
        self.entity_id = ENTITY_ID_FORMAT.format(
            f"{self.ha_id}_{entity_description.key}")
        self._attr_name = f"{fibaro_device.friendly_name} {entity_description.name}"
        self._attr_unique_id = f"{fibaro_device.unique_id_str}_{entity_description.key}"
示例#28
0
    def __init__(self, client, config):
        """Initialize the sensor."""
        self.client = client
        self._name = config.friendly_name
        self._attr = config.field
        self._state = None
        self._icon = config.icon
        self._unit_of_measurement = config.unit_of_measurement

        # This ensures that the sensors are isolated per waterfurnace unit
        self.entity_id = ENTITY_ID_FORMAT.format(
            'wf_{}_{}'.format(slugify(self.client.unit), slugify(self._attr)))
示例#29
0
    def __init__(self, coordinator, name, entity_id, icon, device_identifier):
        """Initialize Entities."""

        self._name = name
        self.entity_id = ENTITY_ID_FORMAT.format(entity_id)
        self._state = None
        self._icon = icon
        self._kind = entity_id
        self._device_identifier = device_identifier
        self.coordinator = coordinator
        self._unit_of_measure = None
        self.attrs = {}
示例#30
0
 def __init__(self, visonic_device):
     """Initialize the sensor."""
     self.visonic_device = visonic_device
     self._name = "Visonic " + self.visonic_device.dname
     # Append device id to prevent name clashes in HA.
     self.visonic_id = slugify(
         self._name
     )  # VISONIC_ID_FORMAT.format( slugify(self._name), visonic_device.getDeviceID())
     #self.update()
     self.entity_id = ENTITY_ID_FORMAT.format(self.visonic_id)
     self.current_value = "T" if self.visonic_device.triggered else "O" if self.visonic_device.status else "-"
     self.visonic_device.install_change_handler(self.onChange)
示例#31
0
    def __init__(self, client, config):
        """Initialize the sensor."""
        self.client = client
        self._name = config.friendly_name
        self._attr = config.field
        self._state = None
        self._icon = config.icon
        self._unit_of_measurement = config.unit_of_measurement

        # This ensures that the sensors are isolated per waterfurnace unit
        self.entity_id = ENTITY_ID_FORMAT.format(
            'wf_{}_{}'.format(slugify(self.client.unit), slugify(self._attr)))
示例#32
0
def check_data(user_input, hass):
	"""Check validity of the provided date."""

	entities = []
	entities.append([user_input[CONF_NET],ERROR_NET_ID_NOT_FOUND])
	entities.append([user_input[CONF_GEN],ERROR_GEN_ID_NOT_FOUND])

	ret = {}
	for d in entities:
		if(d[0].find(ENTITY_ID_FORMAT.replace("{}",""))>=0):
				test_entity_id = d[0].split(ENTITY_ID_FORMAT.replace("{}",""))
				if(len(test_entity_id)>=2):
					if(async_generate_entity_id(ENTITY_ID_FORMAT, test_entity_id[1], hass=hass) == d[0]):
						ret["base"] = d[1]
						return ret
				else:
					ret["base"] = d[1]
					return ret
		else:
			ret["base"] = d[1]
			return ret
	return ret
示例#33
0
 def __init__(self, hass, name, track_id):
     """Initialize the sensor."""
     self._name = name
     self._track_id = track_id
     self._state = None
     self._distance = None
     self._properties = None
     self._last_update = None
     self.hass = hass
     self.entity_slug = "Skisporet {}".format(self._name)
     self.entity_id = ENTITY_ID_FORMAT.format(
         slugify(self.entity_slug.replace(' ', '_')))
     _LOGGER.info(f"Added skisporet-sensor {self.entity_id}")
示例#34
0
    def __init__(self, client, heater, name) -> None:
        """Initialize the sensor."""
        super().__init__()

        self._client = client
        self._heater = heater

        self._unique_id = f"{heater.serial_no}_{slugify(name)}"
        self.entity_id = ENTITY_ID_FORMAT.format(f"{DOMAIN}_{slugify(name)}")
        self._name = f"Boiler {name}"

        self._device_class = None
        self._state_attr = INCOMFORT_MAP_ATTRS[name][0]
        self._unit_of_measurement = None
示例#35
0
    def __init__(self, connection, config, car_vid):
        """Initialize sensor with car connection."""
        self._conn = connection
        self._name = config.name
        self._attr = config.attr
        self._unit_of_measurement = config.unit_of_measurement
        self._icon = config.icon
        self._state = None
        self._car_vid = car_vid

        self.entity_id = ENTITY_ID_FORMAT.format(
            '{}_{}_{}'.format(MYCHEVY_DOMAIN,
                              slugify(self._car.name),
                              slugify(self._name)))