* Fibaro HC connection, initial commit Very first steps working, connects, fetches devices, represents sensors, binary_sensors and lights towards HA. * Cover, switch, bugfixes Initial support for covers Initial support for switches Bugfixes * Some cleanup and improved lights pylint based cleanup light switches handled properly light features reported correctly * Added status updates and actions Lights, Blinds, Switches are mostly working now * Code cleanup, fiblary3 req Fiblary3 is now in pypi, set it as req Cleanup based on pylint * Included in .coveragerc and added how to use guide Included the fibaro component in coveragerc Added usage instructions to file header * PyLint inspired fixes Fixed pylint warnings * PyLint inspired fixes PyLint inspired fixes * updated to fiblary3 0.1.5 * Minor fixes to finally pass pull req Fixed fiblary3 to work with python 3.5 Updated fiblary3 to 0.1.6 (added energy and batteryLevel dummies) * module import and flake8 fixes Finally (hopefully) figured out what lint is complaining about * Fixed color support for lights, simplified callback Fixed color support for lights Simplified callback for updates Uses updated fiblary3 for color light handling * Lean and mean refactor While waiting for a brave reviewer, I've been making the code smaller and easier to understand. * Minor fixes to please HoundCI * Removed unused component Scenes are not implemented yet * Nicer comments. * DEVICE_CLASS, ignore plugins, improved mapping Added support for device class and icons in sensors and binary_sensors Improved mapping of sensors and added heuristic matching Added support for hidden devices Fixed conversion to float in sensors * Fixed dimming Fibaro apparently does not need, nor like the extra turnOn commands for dimmers * flake8 * Cleanup, Light fixes, switch power Cleanup of the component to separate init from connect, handle connection error better Improved light handling, especially for RGBW strips and working around Fibaro quirks Added energy and power reporting to switches * Missing comment added Missing comment added to please flake8 * Removed everything but bin.sensors Stripdown, hoping for a review * better aligned comments OMG * Fixes based on code review Fixes based on code review * Implemented stopping Implemented stopping of StateHandler thread Cleanup for clarity * Minor fix Removed unnecessary list copying * Nicer wording on shutdown * Minor changes based on code review * minor fixes based on code review * removed extra line break
74 lines
2.3 KiB
Python
74 lines
2.3 KiB
Python
"""
|
|
Support for Fibaro binary sensors.
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
https://home-assistant.io/components/binary_sensor.fibaro/
|
|
"""
|
|
import logging
|
|
|
|
from homeassistant.components.binary_sensor import (
|
|
BinarySensorDevice, ENTITY_ID_FORMAT)
|
|
from homeassistant.components.fibaro import (
|
|
FIBARO_CONTROLLER, FIBARO_DEVICES, FibaroDevice)
|
|
|
|
DEPENDENCIES = ['fibaro']
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
SENSOR_TYPES = {
|
|
'com.fibaro.doorSensor': ['Door', 'mdi:window-open', 'door'],
|
|
'com.fibaro.windowSensor': ['Window', 'mdi:window-open', 'window'],
|
|
'com.fibaro.smokeSensor': ['Smoke', 'mdi:smoking', 'smoke'],
|
|
'com.fibaro.FGMS001': ['Motion', 'mdi:run', 'motion'],
|
|
'com.fibaro.heatDetector': ['Heat', 'mdi:fire', 'heat'],
|
|
}
|
|
|
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
|
"""Perform the setup for Fibaro controller devices."""
|
|
if discovery_info is None:
|
|
return
|
|
|
|
add_entities(
|
|
[FibaroBinarySensor(device, hass.data[FIBARO_CONTROLLER])
|
|
for device in hass.data[FIBARO_DEVICES]['binary_sensor']], True)
|
|
|
|
|
|
class FibaroBinarySensor(FibaroDevice, BinarySensorDevice):
|
|
"""Representation of a Fibaro Binary Sensor."""
|
|
|
|
def __init__(self, fibaro_device, controller):
|
|
"""Initialize the binary_sensor."""
|
|
self._state = None
|
|
super().__init__(fibaro_device, controller)
|
|
self.entity_id = ENTITY_ID_FORMAT.format(self.ha_id)
|
|
stype = None
|
|
if fibaro_device.type in SENSOR_TYPES:
|
|
stype = fibaro_device.type
|
|
elif fibaro_device.baseType in SENSOR_TYPES:
|
|
stype = fibaro_device.baseType
|
|
if stype:
|
|
self._device_class = SENSOR_TYPES[stype][2]
|
|
self._icon = SENSOR_TYPES[stype][1]
|
|
else:
|
|
self._device_class = None
|
|
self._icon = None
|
|
|
|
@property
|
|
def icon(self):
|
|
"""Icon to use in the frontend, if any."""
|
|
return self._icon
|
|
|
|
@property
|
|
def device_class(self):
|
|
"""Return the device class of the sensor."""
|
|
return self._device_class
|
|
|
|
@property
|
|
def is_on(self):
|
|
"""Return true if sensor is on."""
|
|
return self._state
|
|
|
|
def update(self):
|
|
"""Get the latest data and update the state."""
|
|
self._state = self.current_binary_state
|