1 parent
d73b695e73
commit
80c187f8ea
8 files changed
+299
-245
No files matched your search
@@ -18,31 +18,25 @@ _LOGGER = logging.getLogger(__name__)
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the Verisure platform."""
|
||||
sensors = []
|
||||
hub.update_overview()
|
||||
|
||||
if int(hub.config.get(CONF_THERMOMETERS, 1)):
|
||||
hub.update_climate()
|
||||
sensors.extend([
|
||||
VerisureThermometer(value.id)
|
||||
for value in hub.climate_status.values()
|
||||
if hasattr(value, 'temperature') and value.temperature
|
||||
])
|
||||
VerisureThermometer(device_label)
|
||||
for device_label in hub.get(
|
||||
'$.climateValues[?(@.temperature)].deviceLabel')])
|
||||
|
||||
if int(hub.config.get(CONF_HYDROMETERS, 1)):
|
||||
hub.update_climate()
|
||||
sensors.extend([
|
||||
VerisureHygrometer(value.id)
|
||||
for value in hub.climate_status.values()
|
||||
if hasattr(value, 'humidity') and value.humidity
|
||||
])
|
||||
VerisureHygrometer(device_label)
|
||||
for device_label in hub.get(
|
||||
'$.climateValues[?(@.humidity)].deviceLabel')])
|
||||
|
||||
if int(hub.config.get(CONF_MOUSE, 1)):
|
||||
hub.update_mousedetection()
|
||||
sensors.extend([
|
||||
VerisureMouseDetection(value.deviceLabel)
|
||||
for value in hub.mouse_status.values()
|
||||
# is this if needed?
|
||||
if hasattr(value, 'amountText') and value.amountText
|
||||
])
|
||||
VerisureMouseDetection(device_label)
|
||||
for device_label in hub.get(
|
||||
"$.eventCounts[?(@.deviceType=='MOUSE1')].deviceLabel")])
|
||||
|
||||
add_devices(sensors)
|
||||
|
||||
@@ -50,26 +44,30 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
class VerisureThermometer(Entity):
|
||||
"""Representation of a Verisure thermometer."""
|
||||
|
||||
def __init__(self, device_id):
|
||||
def __init__(self, device_label):
|
||||
"""Initialize the sensor."""
|
||||
self._id = device_id
|
||||
self._device_label = device_label
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the device."""
|
||||
return '{} {}'.format(
|
||||
hub.climate_status[self._id].location, 'Temperature')
|
||||
return hub.get_first(
|
||||
"$.climateValues[?(@.deviceLabel=='%s')].deviceArea",
|
||||
self._device_label) + " temperature"
|
||||
|
||||
@property
|
||||
def state(self):
|
||||
"""Return the state of the device."""
|
||||
# Remove ° character
|
||||
return hub.climate_status[self._id].temperature[:-1]
|
||||
return hub.get_first(
|
||||
"$.climateValues[?(@.deviceLabel=='%s')].temperature",
|
||||
self._device_label)
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return True if entity is available."""
|
||||
return hub.available
|
||||
return hub.get_first(
|
||||
"$.climateValues[?(@.deviceLabel=='%s')].temperature",
|
||||
self._device_label) is not None
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
@@ -78,71 +76,80 @@ class VerisureThermometer(Entity):
|
||||
|
||||
def update(self):
|
||||
"""Update the sensor."""
|
||||
hub.update_climate()
|
||||
hub.update_overview()
|
||||
|
||||
|
||||
class VerisureHygrometer(Entity):
|
||||
"""Representation of a Verisure hygrometer."""
|
||||
|
||||
def __init__(self, device_id):
|
||||
def __init__(self, device_label):
|
||||
"""Initialize the sensor."""
|
||||
self._id = device_id
|
||||
self._device_label = device_label
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return '{} {}'.format(
|
||||
hub.climate_status[self._id].location, 'Humidity')
|
||||
"""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 sensor."""
|
||||
# remove % character
|
||||
return hub.climate_status[self._id].humidity[:-1]
|
||||
"""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.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 sensor."""
|
||||
return "%"
|
||||
"""Return the unit of measurement of this entity."""
|
||||
return '%'
|
||||
|
||||
def update(self):
|
||||
"""Update the sensor."""
|
||||
hub.update_climate()
|
||||
hub.update_overview()
|
||||
|
||||
|
||||
class VerisureMouseDetection(Entity):
|
||||
"""Representation of a Verisure mouse detector."""
|
||||
|
||||
def __init__(self, device_id):
|
||||
def __init__(self, device_label):
|
||||
"""Initialize the sensor."""
|
||||
self._id = device_id
|
||||
self._device_label = device_label
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the sensor."""
|
||||
return '{} {}'.format(
|
||||
hub.mouse_status[self._id].location, 'Mouse')
|
||||
"""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 sensor."""
|
||||
return hub.mouse_status[self._id].count
|
||||
"""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.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 sensor."""
|
||||
return "Mice"
|
||||
"""Return the unit of measurement of this entity."""
|
||||
return 'Mice'
|
||||
|
||||
def update(self):
|
||||
"""Update the sensor."""
|
||||
hub.update_mousedetection()
|
||||
hub.update_overview()
|
||||
Reference in new issue
Block a user