| 1 | |
| 2 | |
| 3 | Integration for Blebox devices in Home Assistant. |
| 4 | ============= |
| 5 | |
| 6 | This documentation assumes you are familiar with Home Assistant and the Blebox devices. |
| 7 | |
| 8 | How to Add a New Sensor (Based on MultiSensor Illuminance) |
| 9 | -------------------------------------------------------- |
| 10 | |
| 11 | 1. **Update SENSOR_TYPES tuple in homeassistant.components.blebox.sensor module to allow creation of proper homeassistant entities for light readings depending on device capability reported by blebox_uniapi library.**: |
| 12 | |
| 13 | |
| 14 | ```python |
| 15 | from homeassistant.components.blebox.sensor import SensorEntityDescription, SensorDeviceClass |
| 16 | from homeassistant.const import LIGHT_LUX |
| 17 | |
| 18 | SENSOR_TYPES = ( |
| 19 | # ... (existing entries) |
| 20 | |
| 21 | SensorEntityDescription( |
| 22 | key="illuminance", |
| 23 | device_class=SensorDeviceClass.ILLUMINANCE, |
| 24 | native_unit_of_measurement=LIGHT_LUX, |
| 25 | ), |
| 26 | )``` |
| 27 | 2. **Update box_types module in blebox_uniapi to support new sensor types. (API level will be given, use newest version of the sensor if u want to copy paste)** |
| 28 | ```python |
| 29 | "multiSensor": { |
| 30 | 20220114: { |
| 31 | "api_path": "/state", |
| 32 | "extended_state_path": "/state/extended", |
| 33 | "sensors": [ |
| 34 | [ |
| 35 | "multiSensor", |
| 36 | { |
| 37 | "illuminance": lambda x:f"multiSensor/sensors/[id={x}]/value", |
| 38 | "temperature": lambda x: f"multiSensor/sensors/[id={x}]/value", |
| 39 | "wind": lambda x: f"multiSensor/sensors/[id={x}]/value", |
| 40 | "humidity": lambda x: f"multiSensor/sensors/[id={x}]/value", |
| 41 | }, |
| 42 | ] |
| 43 | ], |
| 44 | "binary_sensors": [ |
| 45 | [ |
| 46 | "multiSensor", |
| 47 | { |
| 48 | "rain": lambda x: f"multiSensor/sensors/[id={x}]/value", |
| 49 | "flood": lambda x: f"multiSensor/sensors/[id={x}]/value", |
| 50 | }, |
| 51 | ] |
| 52 | ], |
| 53 | }, |
| 54 | ``` |
| 55 | 3. **Create new sensor class in blebox_uniapi.sensor module for light related readings updating type_class_mapper in blebox_uniapi.sensor.SensorFactory to return proper sensor class if device supports light related measurements** |
| 56 | |
| 57 | ```python |
| 58 | class Illuminance(BaseSensor): |
| 59 | def __init__(self, product: "Box", alias: str, methods: dict): |
| 60 | super().__init__(product, alias, methods) |
| 61 | self._unit = "lx" |
| 62 | self._device_class = "illuminance" |
| 63 | |
| 64 | def _read_illuminance(self): |
| 65 | product = self._product |
| 66 | if product.last_data is not None: |
| 67 | raw = self.raw_value("illuminance") |
| 68 | if raw is not None: |
| 69 | alias = self._alias |
| 70 | return round(product.expect_int(alias, raw, 100000, 0)/100.0, 1) |
| 71 | return None |
| 72 | ``` |
| 73 | ```python |
| 74 | class SensorFactory: |
| 75 | @classmethod |
| 76 | def many_from_config( |
| 77 | cls, product, box_type_config, extended_state |
| 78 | ) -> list["BaseSensor"]: |
| 79 | type_class_mapper = { |
| 80 | "airSensor": AirQuality, |
| 81 | "temperature": Temperature, |
| 82 | "humidity": Humidity, |
| 83 | "wind": Wind, |
| 84 | "illuminance" : Illuminance |
| 85 | } |
| 86 | ``` |