core/homeassistant/components/verisure/sensor.py

153 lines
4.4 KiB
Python
Raw Normal View History

"""Support for Verisure sensors."""
2015-08-11 07:28:07 +00:00
import logging
2016-04-20 03:30:44 +00:00
from homeassistant.const import TEMP_CELSIUS
2016-02-19 05:27:50 +00:00
from homeassistant.helpers.entity import Entity
2015-08-11 07:28:07 +00:00
from . import CONF_HYDROMETERS, CONF_MOUSE, CONF_THERMOMETERS, HUB as hub
2015-08-11 07:28:07 +00:00
_LOGGER = logging.getLogger(__name__)
2015-08-12 11:00:47 +00:00
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Verisure platform."""
2015-08-12 11:00:47 +00:00
sensors = []
hub.update_overview()
2015-08-11 07:28:07 +00:00
if int(hub.config.get(CONF_THERMOMETERS, 1)):
2016-02-27 20:50:19 +00:00
sensors.extend([
VerisureThermometer(device_label)
for device_label in hub.get(
'$.climateValues[?(@.temperature)].deviceLabel')])
2016-02-27 20:50:19 +00:00
if int(hub.config.get(CONF_HYDROMETERS, 1)):
2016-02-27 20:50:19 +00:00
sensors.extend([
VerisureHygrometer(device_label)
for device_label in hub.get(
'$.climateValues[?(@.humidity)].deviceLabel')])
2016-02-27 20:50:19 +00:00
if int(hub.config.get(CONF_MOUSE, 1)):
2016-02-27 20:50:19 +00:00
sensors.extend([
VerisureMouseDetection(device_label)
for device_label in hub.get(
"$.eventCounts[?(@.deviceType=='MOUSE1')].deviceLabel")])
add_entities(sensors)
2015-08-11 07:28:07 +00:00
class VerisureThermometer(Entity):
2016-03-08 15:46:34 +00:00
"""Representation of a Verisure thermometer."""
2015-08-11 07:28:07 +00:00
def __init__(self, device_label):
2016-03-08 15:46:34 +00:00
"""Initialize the sensor."""
self._device_label = device_label
2015-08-12 11:00:47 +00:00
2015-08-11 07:28:07 +00:00
@property
def name(self):
2016-03-08 15:46:34 +00:00
"""Return the name of the device."""
return hub.get_first(
"$.climateValues[?(@.deviceLabel=='%s')].deviceArea",
self._device_label) + " temperature"
2015-08-11 07:28:07 +00:00
@property
def state(self):
2016-03-08 15:46:34 +00:00
"""Return the state of the device."""
return hub.get_first(
"$.climateValues[?(@.deviceLabel=='%s')].temperature",
self._device_label)
2015-08-12 11:00:47 +00:00
@property
def available(self):
"""Return True if entity is available."""
return hub.get_first(
"$.climateValues[?(@.deviceLabel=='%s')].temperature",
self._device_label) is not None
2015-08-12 11:00:47 +00:00
@property
def unit_of_measurement(self):
2016-03-08 15:46:34 +00:00
"""Return the unit of measurement of this entity."""
2016-04-20 03:30:44 +00:00
return TEMP_CELSIUS
2015-08-12 11:00:47 +00:00
# pylint: disable=no-self-use
2015-08-12 11:00:47 +00:00
def update(self):
2016-02-23 05:21:49 +00:00
"""Update the sensor."""
hub.update_overview()
class VerisureHygrometer(Entity):
2016-03-08 15:46:34 +00:00
"""Representation of a Verisure hygrometer."""
def __init__(self, device_label):
2016-03-08 15:46:34 +00:00
"""Initialize the sensor."""
self._device_label = device_label
@property
def name(self):
"""Return the name of the device."""
return hub.get_first(
"$.climateValues[?(@.deviceLabel=='%s')].deviceArea",
self._device_label) + " humidity"
@property
def state(self):
"""Return the state of the device."""
return hub.get_first(
"$.climateValues[?(@.deviceLabel=='%s')].humidity",
self._device_label)
@property
def available(self):
"""Return True if entity is available."""
return hub.get_first(
"$.climateValues[?(@.deviceLabel=='%s')].humidity",
self._device_label) is not None
@property
def unit_of_measurement(self):
"""Return the unit of measurement of this entity."""
return '%'
# pylint: disable=no-self-use
def update(self):
2016-02-27 20:50:19 +00:00
"""Update the sensor."""
hub.update_overview()
class VerisureMouseDetection(Entity):
2016-03-08 15:46:34 +00:00
"""Representation of a Verisure mouse detector."""
def __init__(self, device_label):
2016-03-08 15:46:34 +00:00
"""Initialize the sensor."""
self._device_label = device_label
@property
def name(self):
"""Return the name of the device."""
return hub.get_first(
"$.eventCounts[?(@.deviceLabel=='%s')].area",
self._device_label) + " mouse"
@property
def state(self):
"""Return the state of the device."""
return hub.get_first(
"$.eventCounts[?(@.deviceLabel=='%s')].detections",
self._device_label)
@property
def available(self):
"""Return True if entity is available."""
return hub.get_first(
"$.eventCounts[?(@.deviceLabel=='%s')]",
self._device_label) is not None
@property
def unit_of_measurement(self):
"""Return the unit of measurement of this entity."""
return 'Mice'
# pylint: disable=no-self-use
def update(self):
2016-02-23 05:21:49 +00:00
"""Update the sensor."""
hub.update_overview()