def __init__( self, wrapper: BlockDeviceWrapper, block: Block, attribute: str, description: BlockSensorDescription, ) -> None: """Initialize sensor.""" super().__init__(wrapper, block, attribute, description) self._attr_native_unit_of_measurement = description.native_unit_of_measurement if unit_fn := description.unit_fn: self._attr_native_unit_of_measurement = unit_fn(block.info(attribute))
def __init__( self, wrapper: BlockDeviceWrapper, block: 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_block_entity_name(wrapper.device, block, self.description.name)