This commit is contained in:
Paulus Schoutsen committed 2019-07-31 12:25:30 -07:00
1 parent da05dfe708
commit 4de97abc3a
2676 files changed
+163166 -140084

No files matched your search

+44 -26
View File
@@ -11,39 +11,56 @@ from .const import DOMAIN as POINT_DOMAIN, POINT_DISCOVERY_NEW, SIGNAL_WEBHOOK
_LOGGER = logging.getLogger(__name__)
EVENTS = {
'battery': # On means low, Off means normal
('battery_low', ''),
'button_press': # On means the button was pressed, Off means normal
('short_button_press', ''),
'cold': # On means cold, Off means normal
('temperature_low', 'temperature_risen_normal'),
'connectivity': # On means connected, Off means disconnected
('device_online', 'device_offline'),
'dry': # On means too dry, Off means normal
('humidity_low', 'humidity_risen_normal'),
'heat': # On means hot, Off means normal
('temperature_high', 'temperature_dropped_normal'),
'moisture': # On means wet, Off means dry
('humidity_high', 'humidity_dropped_normal'),
'sound': # On means sound detected, Off means no sound (clear)
('avg_sound_high', 'sound_level_dropped_normal'),
'tamper': # On means the point was removed or attached
('tamper', ''),
"battery": ("battery_low", ""), # On means low, Off means normal
"button_press": ( # On means the button was pressed, Off means normal
"short_button_press",
"",
),
"cold": ( # On means cold, Off means normal
"temperature_low",
"temperature_risen_normal",
),
"connectivity": ( # On means connected, Off means disconnected
"device_online",
"device_offline",
),
"dry": ( # On means too dry, Off means normal
"humidity_low",
"humidity_risen_normal",
),
"heat": ( # On means hot, Off means normal
"temperature_high",
"temperature_dropped_normal",
),
"moisture": ( # On means wet, Off means dry
"humidity_high",
"humidity_dropped_normal",
),
"sound": ( # On means sound detected, Off means no sound (clear)
"avg_sound_high",
"sound_level_dropped_normal",
),
"tamper": ("tamper", ""), # On means the point was removed or attached
}
async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up a Point's binary sensors based on a config entry."""
async def async_discover_sensor(device_id):
"""Discover and add a discovered sensor."""
client = hass.data[POINT_DOMAIN][config_entry.entry_id]
async_add_entities(
(MinutPointBinarySensor(client, device_id, device_class)
for device_class in EVENTS), True)
(
MinutPointBinarySensor(client, device_id, device_class)
for device_class in EVENTS
),
True,
)
async_dispatcher_connect(
hass, POINT_DISCOVERY_NEW.format(DOMAIN, POINT_DOMAIN),
async_discover_sensor)
hass, POINT_DISCOVERY_NEW.format(DOMAIN, POINT_DOMAIN), async_discover_sensor
)
class MinutPointBinarySensor(MinutPointEntity, BinarySensorDevice):
@@ -61,7 +78,8 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorDevice):
"""Call when entity is added to HOme Assistant."""
await super().async_added_to_hass()
self._async_unsub_hook_dispatcher_connect = async_dispatcher_connect(
self.hass, SIGNAL_WEBHOOK, self._webhook_event)
self.hass, SIGNAL_WEBHOOK, self._webhook_event
)
async def async_will_remove_from_hass(self):
"""Disconnect dispatcher listener when removed."""
@@ -84,8 +102,8 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorDevice):
"""Process new event from the webhook."""
if self.device.webhook != webhook:
return
_type = data.get('event', {}).get('type')
_device_id = data.get('event', {}).get('device_id')
_type = data.get("event", {}).get("type")
_device_id = data.get("event", {}).get("device_id")
if _type not in self._events or _device_id != self.device.device_id:
return
_LOGGER.debug("Recieved webhook: %s", _type)
@@ -98,7 +116,7 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorDevice):
@property
def is_on(self):
"""Return the state of the binary sensor."""
if self.device_class == 'connectivity':
if self.device_class == "connectivity":
# connectivity is the other way around.
return not self._is_on
return self._is_on