-
-
Notifications
You must be signed in to change notification settings - Fork 29.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for Point component (#17466)
* Minut Point support * tox tests for Point * config flow fixes * fixes requested by @MartinHjelmare * swedish translation :) * fix tests
- Loading branch information
Showing
13 changed files
with
935 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
""" | ||
Support for Minut Point. | ||
For more details about this platform, please refer to the documentation at | ||
https://home-assistant.io/components/binary_sensor.point/ | ||
""" | ||
|
||
import logging | ||
|
||
from homeassistant.components.point import MinutPointEntity | ||
from homeassistant.components.point.const import ( | ||
DOMAIN as POINT_DOMAIN, NEW_DEVICE, SIGNAL_WEBHOOK) | ||
from homeassistant.core import callback | ||
from homeassistant.helpers.dispatcher import async_dispatcher_connect | ||
|
||
_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', ''), | ||
} | ||
|
||
|
||
async def async_setup_entry(hass, config_entry, async_add_entities): | ||
"""Set up a Point's binary sensors based on a config entry.""" | ||
device_id = config_entry.data[NEW_DEVICE] | ||
client = hass.data[POINT_DOMAIN][config_entry.entry_id] | ||
async_add_entities((MinutPointBinarySensor(client, device_id, device_class) | ||
for device_class in EVENTS), True) | ||
|
||
|
||
class MinutPointBinarySensor(MinutPointEntity): | ||
"""The platform class required by Home Assistant.""" | ||
|
||
def __init__(self, point_client, device_id, device_class): | ||
"""Initialize the entity.""" | ||
super().__init__(point_client, device_id, device_class) | ||
|
||
self._async_unsub_hook_dispatcher_connect = None | ||
self._events = EVENTS[device_class] | ||
self._is_on = None | ||
|
||
async def async_added_to_hass(self): | ||
"""Call when entity is added to hass.""" | ||
await super().async_added_to_hass() | ||
self._async_unsub_hook_dispatcher_connect = async_dispatcher_connect( | ||
self.hass, SIGNAL_WEBHOOK, self._webhook_event) | ||
|
||
async def async_will_remove_from_hass(self): | ||
"""Disconnect dispatcher listener when removed.""" | ||
await super().async_will_remove_from_hass() | ||
if self._async_unsub_hook_dispatcher_connect: | ||
self._async_unsub_hook_dispatcher_connect() | ||
|
||
@callback | ||
def _update_callback(self): | ||
"""Update the value of the sensor.""" | ||
if not self.is_updated: | ||
return | ||
if self._events[0] in self.device.ongoing_events: | ||
self._is_on = True | ||
else: | ||
self._is_on = None | ||
self.async_schedule_update_ha_state() | ||
|
||
@callback | ||
def _webhook_event(self, data, webhook): | ||
"""Process new event from the webhook.""" | ||
if self.device.webhook != webhook: | ||
return | ||
_type = data.get('event', {}).get('type') | ||
if _type not in self._events: | ||
return | ||
_LOGGER.debug("Recieved webhook: %s", _type) | ||
if _type == self._events[0]: | ||
self._is_on = True | ||
if _type == self._events[1]: | ||
self._is_on = None | ||
self.async_schedule_update_ha_state() | ||
|
||
@property | ||
def is_on(self): | ||
"""Return the state of the binary sensor.""" | ||
if self.device_class == 'connectivity': | ||
# connectivity is the other way around. | ||
return not self._is_on | ||
return self._is_on |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"config": { | ||
"title": "Minut Point", | ||
"step": { | ||
"user": { | ||
"title": "Authentication Provider", | ||
"description": "Pick via which authentication provider you want to authenticate with Point.", | ||
"data": { | ||
"flow_impl": "Provider" | ||
} | ||
}, | ||
"auth": { | ||
"title": "Authenticate Point", | ||
"description": "Please follow the link below and <b>Accept</b> access to your Minut account, then come back and press <b>Submit</b> below.\n\n[Link]({authorization_url})" | ||
} | ||
}, | ||
"create_entry": { | ||
"default": "Successfully authenticated with Minut for your Point device(s)" | ||
}, | ||
"error": { | ||
"no_token": "Not authenticated with Minut", | ||
"follow_link": "Please follow the link and authenticate before pressing Submit" | ||
}, | ||
"abort": { | ||
"already_setup": "You can only configure a Point account.", | ||
"external_setup": "Point successfully configured from another flow.", | ||
"no_flows": "You need to configure Point before being able to authenticate with it. [Please read the instructions](https://www.home-assistant.io/components/point/).", | ||
"authorize_url_timeout": "Timeout generating authorize url.", | ||
"authorize_url_fail": "Unknown error generating an authorize url." | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"config": { | ||
"title": "Minut Point", | ||
"step": { | ||
"user": { | ||
"title": "Autentiseringsleverant\u00f6r", | ||
"description": "V\u00e4lj den autentiseringsleverant\u00f6r som du vill autentisera med mot Point.", | ||
"data": { | ||
"flow_impl": "Leverant\u00f6r" | ||
} | ||
}, | ||
"auth": { | ||
"title": "Autentisera Point", | ||
"description": "F\u00f6lj l\u00e4nken nedan och klicka p\u00e5 <b>Accept</b> f\u00f6r att tilll\u00e5ta tillg\u00e5ng till ditt Minut konto, kom d\u00f6refter tillbaka hit och kicka p\u00e5 <b>Submit</b> nedan.\n\n[L\u00e4nk]({authorization_url})" | ||
} | ||
}, | ||
"create_entry": { | ||
"default": "Autentiserad med Minut f\u00f6r era Point enheter." | ||
}, | ||
"error": { | ||
"no_token": "Inte autentiserad hos Minut", | ||
"follow_link": "F\u00f6lj l\u00e4nken och autentisera innan du kickar på Submit" | ||
}, | ||
"abort": { | ||
"already_setup": "Du kan endast konfigurera ett Point-konto.", | ||
"external_setup": "Point har lyckats konfigureras fr\u00e5n ett annat fl\u00f6de.", | ||
"no_flows": "Du m\u00e5ste konfigurera Nest innan du kan autentisera med det. [V\u00e4nligen l\u00e4s instruktionerna] (https://www.home-assistant.io/components/point/).", | ||
"authorize_url_timeout": "Timeout vid generering av en autentisieringsadress.", | ||
"authorize_url_fail": "Ok\u00e4nt fel vid generering av autentisieringsadress." | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.