Update pypoint to 2.1.0 (#48223)

* update pypoint to 2.1.0

* Add properties and device_classes to constant

* Fix unique_ids for binary_sensors

* Update device icon

* Fallback to device_class icon.

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Just use known events

* Use DEVICE_CLASS_SOUND

Co-authored-by: Erik Montnemery <erik@montnemery.com>
pull/48268/head
Fredrik Erlandsson 2021-03-23 20:03:54 +01:00 committed by GitHub
parent cc73cbcace
commit d129b8e1e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 40 deletions

View File

@ -1,8 +1,16 @@
"""Support for Minut Point binary sensors."""
import logging
from pypoint import EVENTS
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_BATTERY,
DEVICE_CLASS_COLD,
DEVICE_CLASS_CONNECTIVITY,
DEVICE_CLASS_HEAT,
DEVICE_CLASS_MOISTURE,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_SOUND,
DOMAIN,
BinarySensorEntity,
)
@ -14,37 +22,22 @@ from .const import DOMAIN as POINT_DOMAIN, POINT_DISCOVERY_NEW, SIGNAL_WEBHOOK
_LOGGER = logging.getLogger(__name__)
EVENTS = {
"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
DEVICES = {
"alarm": {"icon": "mdi:alarm-bell"},
"battery": {"device_class": DEVICE_CLASS_BATTERY},
"button_press": {"icon": "mdi:gesture-tap-button"},
"cold": {"device_class": DEVICE_CLASS_COLD},
"connectivity": {"device_class": DEVICE_CLASS_CONNECTIVITY},
"dry": {"icon": "mdi:water"},
"glass": {"icon": "mdi:window-closed-variant"},
"heat": {"device_class": DEVICE_CLASS_HEAT},
"moisture": {"device_class": DEVICE_CLASS_MOISTURE},
"motion": {"device_class": DEVICE_CLASS_MOTION},
"noise": {"icon": "mdi:volume-high"},
"sound": {"device_class": DEVICE_CLASS_SOUND},
"tamper_old": {"icon": "mdi:shield-alert"},
"tamper": {"icon": "mdi:shield-alert"},
}
@ -56,8 +49,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
client = hass.data[POINT_DOMAIN][config_entry.entry_id]
async_add_entities(
(
MinutPointBinarySensor(client, device_id, device_class)
for device_class in EVENTS
MinutPointBinarySensor(client, device_id, device_name)
for device_name in DEVICES
if device_name in EVENTS
),
True,
)
@ -70,12 +64,16 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
class MinutPointBinarySensor(MinutPointEntity, BinarySensorEntity):
"""The platform class required by Home Assistant."""
def __init__(self, point_client, device_id, device_class):
def __init__(self, point_client, device_id, device_name):
"""Initialize the binary sensor."""
super().__init__(point_client, device_id, device_class)
super().__init__(
point_client,
device_id,
DEVICES[device_name].get("device_class"),
)
self._device_name = device_name
self._async_unsub_hook_dispatcher_connect = None
self._events = EVENTS[device_class]
self._events = EVENTS[device_name]
self._is_on = None
async def async_added_to_hass(self):
@ -124,3 +122,18 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorEntity):
# connectivity is the other way around.
return not self._is_on
return self._is_on
@property
def name(self):
"""Return the display name of this device."""
return f"{self._name} {self._device_name.capitalize()}"
@property
def icon(self):
"""Return the icon to use in the frontend, if any."""
return DEVICES[self._device_name].get("icon")
@property
def unique_id(self):
"""Return the unique id of the sensor."""
return f"point.{self._id}-{self._device_name}"

View File

@ -3,7 +3,7 @@
"name": "Minut Point",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/point",
"requirements": ["pypoint==2.0.0"],
"requirements": ["pypoint==2.1.0"],
"dependencies": ["webhook", "http"],
"codeowners": ["@fredrike"],
"quality_scale": "gold"

View File

@ -1622,7 +1622,7 @@ pypjlink2==1.2.1
pyplaato==0.0.15
# homeassistant.components.point
pypoint==2.0.0
pypoint==2.1.0
# homeassistant.components.profiler
pyprof2calltree==1.4.5

View File

@ -867,7 +867,7 @@ pypck==0.7.9
pyplaato==0.0.15
# homeassistant.components.point
pypoint==2.0.0
pypoint==2.1.0
# homeassistant.components.profiler
pyprof2calltree==1.4.5