-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: BleBox Multisensor Illuminance Integration (#161)
* BleBox Multisensor Illuminance Integration
- Loading branch information
Showing
7 changed files
with
138 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,4 +102,4 @@ ENV/ | |
.mypy_cache/ | ||
|
||
# IDE settings | ||
.vscode/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
|
||
|
||
Integration for Blebox devices in Home Assistant. | ||
============= | ||
|
||
This documentation assumes you are familiar with Home Assistant and the Blebox devices. | ||
|
||
How to Add a New Sensor (Based on MultiSensor Illuminance) | ||
-------------------------------------------------------- | ||
|
||
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.**: | ||
|
||
|
||
```python | ||
from homeassistant.components.blebox.sensor import SensorEntityDescription, SensorDeviceClass | ||
from homeassistant.const import LIGHT_LUX | ||
|
||
SENSOR_TYPES = ( | ||
# ... (existing entries) | ||
|
||
SensorEntityDescription( | ||
key="illuminance", | ||
device_class=SensorDeviceClass.ILLUMINANCE, | ||
native_unit_of_measurement=LIGHT_LUX, | ||
), | ||
)``` | ||
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)** | ||
```python | ||
"multiSensor": { | ||
20220114: { | ||
"api_path": "/state", | ||
"extended_state_path": "/state/extended", | ||
"sensors": [ | ||
[ | ||
"multiSensor", | ||
{ | ||
"illuminance": lambda x:f"multiSensor/sensors/[id={x}]/value", | ||
"temperature": lambda x: f"multiSensor/sensors/[id={x}]/value", | ||
"wind": lambda x: f"multiSensor/sensors/[id={x}]/value", | ||
"humidity": lambda x: f"multiSensor/sensors/[id={x}]/value", | ||
}, | ||
] | ||
], | ||
"binary_sensors": [ | ||
[ | ||
"multiSensor", | ||
{ | ||
"rain": lambda x: f"multiSensor/sensors/[id={x}]/value", | ||
"flood": lambda x: f"multiSensor/sensors/[id={x}]/value", | ||
}, | ||
] | ||
], | ||
}, | ||
``` | ||
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** | ||
|
||
```python | ||
class Illuminance(BaseSensor): | ||
def __init__(self, product: "Box", alias: str, methods: dict): | ||
super().__init__(product, alias, methods) | ||
self._unit = "lx" | ||
self._device_class = "illuminance" | ||
|
||
def _read_illuminance(self): | ||
product = self._product | ||
if product.last_data is not None: | ||
raw = self.raw_value("illuminance") | ||
if raw is not None: | ||
alias = self._alias | ||
return round(product.expect_int(alias, raw, 100000, 0)/100.0, 1) | ||
return None | ||
``` | ||
```python | ||
class SensorFactory: | ||
@classmethod | ||
def many_from_config( | ||
cls, product, box_type_config, extended_state | ||
) -> list["BaseSensor"]: | ||
type_class_mapper = { | ||
"airSensor": AirQuality, | ||
"temperature": Temperature, | ||
"humidity": Humidity, | ||
"wind": Wind, | ||
"illuminance" : Illuminance | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters