Point updates (#64748)

Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Fredrik Erlandsson 2022-01-24 13:57:29 +01:00 committed by GitHub
parent 73fd19d4e2
commit f23af3455e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 16 deletions

View file

@ -1,4 +1,6 @@
"""Support for Minut Point binary sensors.""" """Support for Minut Point binary sensors."""
from __future__ import annotations
import logging import logging
from pypoint import EVENTS from pypoint import EVENTS
@ -74,7 +76,6 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorEntity):
self._device_name = device_name self._device_name = device_name
self._async_unsub_hook_dispatcher_connect = None self._async_unsub_hook_dispatcher_connect = None
self._events = EVENTS[device_name] self._events = EVENTS[device_name]
self._is_on = None
async def async_added_to_hass(self): async def async_added_to_hass(self):
"""Call when entity is added to HOme Assistant.""" """Call when entity is added to HOme Assistant."""
@ -93,10 +94,11 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorEntity):
"""Update the value of the sensor.""" """Update the value of the sensor."""
if not self.is_updated: if not self.is_updated:
return return
if self._events[0] in self.device.ongoing_events: if self.device_class == BinarySensorDeviceClass.CONNECTIVITY:
self._is_on = True # connectivity is the other way around.
self._attr_is_on = not (self._events[0] in self.device.ongoing_events)
else: else:
self._is_on = None self._attr_is_on = self._events[0] in self.device.ongoing_events
self.async_write_ha_state() self.async_write_ha_state()
@callback @callback
@ -110,18 +112,18 @@ class MinutPointBinarySensor(MinutPointEntity, BinarySensorEntity):
return return
_LOGGER.debug("Received webhook: %s", _type) _LOGGER.debug("Received webhook: %s", _type)
if _type == self._events[0]: if _type == self._events[0]:
self._is_on = True _is_on = True
if _type == self._events[1]: elif _type == self._events[1]:
self._is_on = None _is_on = False
self.async_write_ha_state() else:
return
@property
def is_on(self):
"""Return the state of the binary sensor."""
if self.device_class == BinarySensorDeviceClass.CONNECTIVITY: if self.device_class == BinarySensorDeviceClass.CONNECTIVITY:
# connectivity is the other way around. # connectivity is the other way around.
return not self._is_on self._attr_is_on = not _is_on
return self._is_on else:
self._attr_is_on = _is_on
self.async_write_ha_state()
@property @property
def name(self): def name(self):

View file

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

View file

@ -1767,7 +1767,7 @@ pypjlink2==1.2.1
pyplaato==0.0.15 pyplaato==0.0.15
# homeassistant.components.point # homeassistant.components.point
pypoint==2.2.1 pypoint==2.3.0
# homeassistant.components.profiler # homeassistant.components.profiler
pyprof2calltree==1.4.5 pyprof2calltree==1.4.5

View file

@ -1121,7 +1121,7 @@ pypck==0.7.13
pyplaato==0.0.15 pyplaato==0.0.15
# homeassistant.components.point # homeassistant.components.point
pypoint==2.2.1 pypoint==2.3.0
# homeassistant.components.profiler # homeassistant.components.profiler
pyprof2calltree==1.4.5 pyprof2calltree==1.4.5