2019-02-13 20:21:14 +00:00
|
|
|
"""Support for rebranded Quby thermostat as provided by Eneco."""
|
2017-10-19 15:59:57 +00:00
|
|
|
import logging
|
2018-07-18 09:54:27 +00:00
|
|
|
import datetime
|
2017-10-19 15:59:57 +00:00
|
|
|
|
|
|
|
from homeassistant.helpers.entity import Entity
|
|
|
|
import homeassistant.components.toon as toon_main
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2017-10-24 16:36:08 +00:00
|
|
|
STATE_ATTR_DEVICE_TYPE = 'device_type'
|
|
|
|
STATE_ATTR_LAST_CONNECTED_CHANGE = 'last_connected_change'
|
2017-10-19 15:59:57 +00:00
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-10-24 16:36:08 +00:00
|
|
|
"""Set up the Toon sensors."""
|
2017-10-19 15:59:57 +00:00
|
|
|
_toon_main = hass.data[toon_main.TOON_HANDLE]
|
|
|
|
|
|
|
|
sensor_items = []
|
2017-10-24 16:36:08 +00:00
|
|
|
sensor_items.extend([
|
|
|
|
ToonSensor(hass, 'Power_current', 'power-plug', 'Watt'),
|
|
|
|
ToonSensor(hass, 'Power_today', 'power-plug', 'kWh'),
|
|
|
|
])
|
2017-10-19 15:59:57 +00:00
|
|
|
|
|
|
|
if _toon_main.gas:
|
2017-10-24 16:36:08 +00:00
|
|
|
sensor_items.extend([
|
|
|
|
ToonSensor(hass, 'Gas_current', 'gas-cylinder', 'CM3'),
|
|
|
|
ToonSensor(hass, 'Gas_today', 'gas-cylinder', 'M3'),
|
|
|
|
])
|
2017-10-19 15:59:57 +00:00
|
|
|
|
|
|
|
for plug in _toon_main.toon.smartplugs:
|
|
|
|
sensor_items.extend([
|
2017-10-24 16:36:08 +00:00
|
|
|
FibaroSensor(hass, '{}_current_power'.format(plug.name),
|
|
|
|
plug.name, 'power-socket-eu', 'Watt'),
|
|
|
|
FibaroSensor(hass, '{}_today_energy'.format(plug.name),
|
|
|
|
plug.name, 'power-socket-eu', 'kWh'),
|
|
|
|
])
|
2017-10-19 15:59:57 +00:00
|
|
|
|
|
|
|
if _toon_main.toon.solar.produced or _toon_main.solar:
|
|
|
|
sensor_items.extend([
|
|
|
|
SolarSensor(hass, 'Solar_maximum', 'kWh'),
|
|
|
|
SolarSensor(hass, 'Solar_produced', 'kWh'),
|
|
|
|
SolarSensor(hass, 'Solar_value', 'Watt'),
|
|
|
|
SolarSensor(hass, 'Solar_average_produced', 'kWh'),
|
|
|
|
SolarSensor(hass, 'Solar_meter_reading_low_produced', 'kWh'),
|
|
|
|
SolarSensor(hass, 'Solar_meter_reading_produced', 'kWh'),
|
2017-10-24 16:36:08 +00:00
|
|
|
SolarSensor(hass, 'Solar_daily_cost_produced', 'Euro'),
|
2017-10-19 15:59:57 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
for smokedetector in _toon_main.toon.smokedetectors:
|
|
|
|
sensor_items.append(
|
2017-10-24 16:36:08 +00:00
|
|
|
FibaroSmokeDetector(
|
|
|
|
hass, '{}_smoke_detector'.format(smokedetector.name),
|
|
|
|
smokedetector.device_uuid, 'alarm-bell', '%')
|
|
|
|
)
|
2017-10-19 15:59:57 +00:00
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(sensor_items)
|
2017-10-19 15:59:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ToonSensor(Entity):
|
2017-10-24 16:36:08 +00:00
|
|
|
"""Representation of a Toon sensor."""
|
2017-10-19 15:59:57 +00:00
|
|
|
|
|
|
|
def __init__(self, hass, name, icon, unit_of_measurement):
|
2017-10-24 16:36:08 +00:00
|
|
|
"""Initialize the Toon sensor."""
|
2017-10-19 15:59:57 +00:00
|
|
|
self._name = name
|
|
|
|
self._state = None
|
2017-10-24 16:36:08 +00:00
|
|
|
self._icon = 'mdi:{}'.format(icon)
|
2017-10-19 15:59:57 +00:00
|
|
|
self._unit_of_measurement = unit_of_measurement
|
|
|
|
self.thermos = hass.data[toon_main.TOON_HANDLE]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the sensor."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Return the mdi icon of the sensor."""
|
|
|
|
return self._icon
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the sensor."""
|
|
|
|
return self.thermos.get_data(self.name.lower())
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit this state is expressed in."""
|
|
|
|
return self._unit_of_measurement
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Get the latest data from the sensor."""
|
|
|
|
self.thermos.update()
|
|
|
|
|
|
|
|
|
|
|
|
class FibaroSensor(Entity):
|
2017-10-24 16:36:08 +00:00
|
|
|
"""Representation of a Fibaro sensor."""
|
2017-10-19 15:59:57 +00:00
|
|
|
|
|
|
|
def __init__(self, hass, name, plug_name, icon, unit_of_measurement):
|
2017-10-24 16:36:08 +00:00
|
|
|
"""Initialize the Fibaro sensor."""
|
2017-10-19 15:59:57 +00:00
|
|
|
self._name = name
|
|
|
|
self._plug_name = plug_name
|
|
|
|
self._state = None
|
2017-10-24 16:36:08 +00:00
|
|
|
self._icon = 'mdi:{}'.format(icon)
|
2017-10-19 15:59:57 +00:00
|
|
|
self._unit_of_measurement = unit_of_measurement
|
|
|
|
self.toon = hass.data[toon_main.TOON_HANDLE]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the sensor."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Return the mdi icon of the sensor."""
|
|
|
|
return self._icon
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the sensor."""
|
|
|
|
value = '_'.join(self.name.lower().split('_')[1:])
|
|
|
|
return self.toon.get_data(value, self._plug_name)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit this state is expressed in."""
|
|
|
|
return self._unit_of_measurement
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Get the latest data from the sensor."""
|
|
|
|
self.toon.update()
|
|
|
|
|
|
|
|
|
|
|
|
class SolarSensor(Entity):
|
2017-10-24 16:36:08 +00:00
|
|
|
"""Representation of a Solar sensor."""
|
2017-10-19 15:59:57 +00:00
|
|
|
|
|
|
|
def __init__(self, hass, name, unit_of_measurement):
|
2017-10-24 16:36:08 +00:00
|
|
|
"""Initialize the Solar sensor."""
|
2017-10-19 15:59:57 +00:00
|
|
|
self._name = name
|
|
|
|
self._state = None
|
2017-10-24 16:36:08 +00:00
|
|
|
self._icon = 'mdi:weather-sunny'
|
2017-10-19 15:59:57 +00:00
|
|
|
self._unit_of_measurement = unit_of_measurement
|
|
|
|
self.toon = hass.data[toon_main.TOON_HANDLE]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the sensor."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Return the mdi icon of the sensor."""
|
|
|
|
return self._icon
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the sensor."""
|
|
|
|
return self.toon.get_data(self.name.lower())
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit this state is expressed in."""
|
|
|
|
return self._unit_of_measurement
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Get the latest data from the sensor."""
|
|
|
|
self.toon.update()
|
|
|
|
|
|
|
|
|
|
|
|
class FibaroSmokeDetector(Entity):
|
2017-10-24 16:36:08 +00:00
|
|
|
"""Representation of a Fibaro smoke detector."""
|
2017-10-19 15:59:57 +00:00
|
|
|
|
|
|
|
def __init__(self, hass, name, uid, icon, unit_of_measurement):
|
2017-10-24 16:36:08 +00:00
|
|
|
"""Initialize the Fibaro smoke sensor."""
|
2017-10-19 15:59:57 +00:00
|
|
|
self._name = name
|
|
|
|
self._uid = uid
|
|
|
|
self._state = None
|
2017-10-24 16:36:08 +00:00
|
|
|
self._icon = 'mdi:{}'.format(icon)
|
2017-10-19 15:59:57 +00:00
|
|
|
self._unit_of_measurement = unit_of_measurement
|
|
|
|
self.toon = hass.data[toon_main.TOON_HANDLE]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
|
|
|
"""Return the name of the sensor."""
|
|
|
|
return self._name
|
|
|
|
|
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Return the mdi icon of the sensor."""
|
|
|
|
return self._icon
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state_attributes(self):
|
|
|
|
"""Return the state attributes of the smoke detectors."""
|
|
|
|
value = datetime.datetime.fromtimestamp(
|
|
|
|
int(self.toon.get_data('last_connected_change', self.name))
|
|
|
|
).strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
|
|
|
|
return {
|
2017-10-24 16:36:08 +00:00
|
|
|
STATE_ATTR_DEVICE_TYPE:
|
|
|
|
self.toon.get_data('device_type', self.name),
|
|
|
|
STATE_ATTR_LAST_CONNECTED_CHANGE: value,
|
2017-10-19 15:59:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@property
|
|
|
|
def state(self):
|
|
|
|
"""Return the state of the sensor."""
|
|
|
|
value = self.name.lower().split('_', 1)[1]
|
|
|
|
return self.toon.get_data(value, self.name)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unit_of_measurement(self):
|
|
|
|
"""Return the unit this state is expressed in."""
|
|
|
|
return self._unit_of_measurement
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
"""Get the latest data from the sensor."""
|
|
|
|
self.toon.update()
|