Use binary sensors
See original GitHub issueProblem description Follow up of discussion in #159
MCCQ02HL and WX08ZM sensors are currently discovered as sensors
with on/off state. However, these sensors are actually binary_sensors
, not sensors
. This causes that the sensors are only able to show on/off
and not e.g. closed/open
.
(Possible) Solution This issue is to discuss how to solve this. The final goal should be that binary sensors are discovered with the proper device class, and show their appropriate state.
Proposal for device classes
MCCQ02HL --> open/close
(DEVICE_CLASS: opening)
MCCQ02HL --> light/dark
(DEVICE_CLASS: light)
WX08ZM --> power detected/no power
(DEVICE_CLASS: power)
To Do
To achieve this, we should
- move the monitoring to
__init__.py
(integration level) - keep the add_enties in
sensor.py
andbinary_sensor.py
at platform level) - move BLE ADV parser to HCIdump thread because this is the only way we can sort messages (see next task)
- split the incoming messages into two separate queues (one for each platform)?
- move the
SwitchingSensors
tobinary_sensor.py
Findings of other examples that could help I think the smarty can be used as an base example, although it has part of the code in a pypi package (pysmarty).
What I found in the smarty component, is that there are two links between __init__.py
and e.g. sensor.py
Data
- in
__init__.py
, data is collected insmarty
and this is passed tohass.data[DOMAIN]
smarty = Smarty(host=host)
hass.data[DOMAIN] = {"api": smarty, "name": name}
- in
sensor.py
it gets the data viasmarty = hass.data[DOMAIN]["api"]
Updating
- It uses
dispatcher_send(hass, SIGNAL_UPDATE_SMARTY)
in__init__.py
after receiving data - In
sensor.py
it uses this in the entity.
async def async_added_to_hass(self):
"""Call to update."""
async_dispatcher_connect(self.hass, SIGNAL_UPDATE_SMARTY, self._update_callback)
@callback
def _update_callback(self):
"""Call update method."""
self.async_schedule_update_ha_state(True)
Not entirely sure how this update link exactly works.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:16
Request done - https://github.com/custom-components/ble_monitor/issues/176 😃
Please make this as a separate issue. I agree it’s worth doing. Or maybe a separate option per device…