diff --git a/homeassistant/components/point/binary_sensor.py b/homeassistant/components/point/binary_sensor.py index d82ecd096ee..0bcd2a33a2e 100644 --- a/homeassistant/components/point/binary_sensor.py +++ b/homeassistant/components/point/binary_sensor.py @@ -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}" diff --git a/homeassistant/components/point/manifest.json b/homeassistant/components/point/manifest.json index 6c25cdef91a..899e5615b40 100644 --- a/homeassistant/components/point/manifest.json +++ b/homeassistant/components/point/manifest.json @@ -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" diff --git a/requirements_all.txt b/requirements_all.txt index 95691cd3f43..203cecd6525 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -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 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 39d823d4e18..2ce2cac591b 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -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