Beispiel #1
0
    def __init__(
        self,
        wrapper: ShellyDeviceWrapper,
        block: aioshelly.Block,
        attribute: str,
        description: BlockAttributeDescription,
        same_type_count: int,
    ) -> None:
        """Initialize sensor."""
        super().__init__(wrapper, block)
        self.attribute = attribute
        self.description = description
        self.info = block.info(attribute)

        unit = self.description.unit

        if callable(unit):
            unit = unit(self.info)

        self._unit = unit
        self._unique_id = f"{super().unique_id}-{self.attribute}"

        name_parts = [self.wrapper.name]
        if same_type_count > 1:
            name_parts.append(str(block.channel))
        name_parts.append(self.description.name)

        self._name = " ".join(name_parts)
Beispiel #2
0
    def __init__(
        self,
        wrapper: ShellyDeviceWrapper,
        block: aioshelly.Block,
        attribute: str,
        description: BlockAttributeDescription,
        entry: entity_registry.RegistryEntry | None = None,
        sensors: dict[tuple[str, str], BlockAttributeDescription]
        | None = None,
    ) -> None:
        """Initialize the sleeping sensor."""
        self.sensors = sensors
        self.last_state: StateType = None
        self.wrapper = wrapper
        self.attribute = attribute
        self.block = block
        self.description = description
        self._unit = self.description.unit

        if block is not None:
            if callable(self._unit):
                self._unit = self._unit(block.info(attribute))

            self._unique_id = f"{self.wrapper.mac}-{block.description}-{attribute}"
            self._name = get_entity_name(self.wrapper.device, block,
                                         self.description.name)
        elif entry is not None:
            self._unique_id = entry.unique_id
            self._name = cast(str, entry.original_name)
Beispiel #3
0
    def __init__(
        self,
        wrapper: ShellyDeviceWrapper,
        block: aioshelly.Block,
        attribute: str,
        description: BlockAttributeDescription,
        entry: Optional[ConfigEntry] = None,
    ) -> None:
        """Initialize the sleeping sensor."""
        self.last_state = None
        self.wrapper = wrapper
        self.attribute = attribute
        self.block = block
        self.description = description
        self._unit = self.description.unit

        if block is not None:
            if callable(self._unit):
                self._unit = self._unit(block.info(attribute))

            self._unique_id = f"{self.wrapper.mac}-{block.description}-{attribute}"
            self._name = get_entity_name(self.wrapper.device, block,
                                         self.description.name)
        else:
            self._unique_id = entry.unique_id
            self._name = entry.original_name
Beispiel #4
0
    def __init__(
        self,
        wrapper: ShellyDeviceWrapper,
        block: aioshelly.Block,
        attribute: str,
        description: BlockAttributeDescription,
    ) -> None:
        """Initialize sensor."""
        super().__init__(wrapper, block)
        self.attribute = attribute
        self.description = description

        unit = self.description.unit

        if callable(unit):
            unit = unit(block.info(attribute))

        self._unit: None | str | Callable[[dict], str] = unit
        self._unique_id: str = f"{super().unique_id}-{self.attribute}"
        self._name = get_entity_name(wrapper.device, block, self.description.name)
    def __init__(
        self,
        wrapper: ShellyDeviceWrapper,
        block: aioshelly.Block,
        attribute: str,
        description: BlockAttributeDescription,
    ) -> None:
        """Initialize sensor."""
        super().__init__(wrapper, block)
        self.attribute = attribute
        self.description = description
        self.info = block.info(attribute)

        unit = self.description.unit

        if callable(unit):
            unit = unit(self.info)

        self._unit = unit
        self._unique_id = f"{super().unique_id}-{self.attribute}"
        self._name = shelly_naming(self, block, "sensor")