Compare commits

..

4 Commits

Author SHA1 Message Date
Bram Kragten
e9fe90a873 Bump version to 0.99.0b3 2019-09-17 15:47:39 +02:00
Bram Kragten
7d79d281c1 Updated frontend to 20190917.1 (#26691) 2019-09-17 15:43:14 +02:00
Pascal Vizeli
d8ccc7751f Bump connect-box library to fix logging (#26690) 2019-09-17 15:43:14 +02:00
Pascal Vizeli
6853f99e30 Fix Nuki issues (#26689)
* Fix Nuki issues

* remove stale code

* Add comments

* Fix lint
2019-09-17 15:43:13 +02:00
10 changed files with 42 additions and 74 deletions

View File

@@ -195,7 +195,7 @@ homeassistant/components/notify/* @home-assistant/core
homeassistant/components/notion/* @bachya
homeassistant/components/nsw_fuel_station/* @nickw444
homeassistant/components/nsw_rural_fire_service_feed/* @exxamalte
homeassistant/components/nuki/* @pschmitt
homeassistant/components/nuki/* @pvizeli
homeassistant/components/nws/* @MatthewFlamm
homeassistant/components/obihai/* @dshokouhi
homeassistant/components/ohmconnect/* @robbiet480

View File

@@ -3,7 +3,7 @@
"name": "Home Assistant Frontend",
"documentation": "https://www.home-assistant.io/components/frontend",
"requirements": [
"home-assistant-frontend==20190917.0"
"home-assistant-frontend==20190917.1"
],
"dependencies": [
"api",

View File

@@ -1 +1,3 @@
"""The nuki component."""
DOMAIN = "nuki"

View File

@@ -1,20 +1,18 @@
"""Nuki.io lock platform."""
from datetime import timedelta
import logging
import requests
from pynuki import NukiBridge
from requests.exceptions import RequestException
import voluptuous as vol
from homeassistant.components.lock import (
DOMAIN,
PLATFORM_SCHEMA,
LockDevice,
SUPPORT_OPEN,
)
from homeassistant.components.lock import PLATFORM_SCHEMA, SUPPORT_OPEN, LockDevice
from homeassistant.const import ATTR_ENTITY_ID, CONF_HOST, CONF_PORT, CONF_TOKEN
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.service import extract_entity_ids
from . import DOMAIN
_LOGGER = logging.getLogger(__name__)
DEFAULT_PORT = 8080
@@ -30,7 +28,8 @@ MIN_TIME_BETWEEN_SCANS = timedelta(seconds=30)
NUKI_DATA = "nuki"
SERVICE_LOCK_N_GO = "lock_n_go"
SERVICE_CHECK_CONNECTION = "check_connection"
ERROR_STATES = (0, 254, 255)
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
@@ -47,48 +46,30 @@ LOCK_N_GO_SERVICE_SCHEMA = vol.Schema(
}
)
CHECK_CONNECTION_SERVICE_SCHEMA = vol.Schema(
{vol.Optional(ATTR_ENTITY_ID): cv.entity_ids}
)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Nuki lock platform."""
from pynuki import NukiBridge
bridge = NukiBridge(
config[CONF_HOST], config[CONF_TOKEN], config[CONF_PORT], DEFAULT_TIMEOUT
)
add_entities([NukiLock(lock) for lock in bridge.locks])
devices = [NukiLock(lock) for lock in bridge.locks]
def service_handler(service):
"""Service handler for nuki services."""
entity_ids = extract_entity_ids(hass, service)
all_locks = hass.data[NUKI_DATA][DOMAIN]
target_locks = []
if not entity_ids:
target_locks = all_locks
else:
for lock in all_locks:
if lock.entity_id in entity_ids:
target_locks.append(lock)
for lock in target_locks:
if service.service == SERVICE_LOCK_N_GO:
unlatch = service.data[ATTR_UNLATCH]
lock.lock_n_go(unlatch=unlatch)
elif service.service == SERVICE_CHECK_CONNECTION:
lock.check_connection()
unlatch = service.data[ATTR_UNLATCH]
for lock in devices:
if lock.entity_id not in entity_ids:
continue
lock.lock_n_go(unlatch=unlatch)
hass.services.register(
"nuki", SERVICE_LOCK_N_GO, service_handler, schema=LOCK_N_GO_SERVICE_SCHEMA
)
hass.services.register(
"nuki",
SERVICE_CHECK_CONNECTION,
service_handler,
schema=CHECK_CONNECTION_SERVICE_SCHEMA,
DOMAIN, SERVICE_LOCK_N_GO, service_handler, schema=LOCK_N_GO_SERVICE_SCHEMA
)
add_entities(devices)
class NukiLock(LockDevice):
"""Representation of a Nuki lock."""
@@ -99,15 +80,7 @@ class NukiLock(LockDevice):
self._locked = nuki_lock.is_locked
self._name = nuki_lock.name
self._battery_critical = nuki_lock.battery_critical
self._available = nuki_lock.state != 255
async def async_added_to_hass(self):
"""Call when entity is added to hass."""
if NUKI_DATA not in self.hass.data:
self.hass.data[NUKI_DATA] = {}
if DOMAIN not in self.hass.data[NUKI_DATA]:
self.hass.data[NUKI_DATA][DOMAIN] = []
self.hass.data[NUKI_DATA][DOMAIN].append(self)
self._available = nuki_lock.state not in ERROR_STATES
@property
def name(self):
@@ -140,13 +113,19 @@ class NukiLock(LockDevice):
def update(self):
"""Update the nuki lock properties."""
try:
self._nuki_lock.update(aggressive=False)
except requests.exceptions.RequestException:
self._available = False
return
for level in (False, True):
try:
self._nuki_lock.update(aggressive=level)
except RequestException:
_LOGGER.warning("Network issues detect with %s", self.name)
self._available = False
return
# If in error state, we force an update and repoll data
self._available = self._nuki_lock.state not in ERROR_STATES
if self._available:
break
self._available = True
self._name = self._nuki_lock.name
self._locked = self._nuki_lock.is_locked
self._battery_critical = self._nuki_lock.battery_critical
@@ -170,12 +149,3 @@ class NukiLock(LockDevice):
amount of time depending on the lock settings) and relock.
"""
self._nuki_lock.lock_n_go(unlatch, kwargs)
def check_connection(self, **kwargs):
"""Update the nuki lock properties."""
try:
self._nuki_lock.update(aggressive=True)
except requests.exceptions.RequestException:
self._available = False
else:
self._available = self._nuki_lock.state != 255

View File

@@ -2,11 +2,7 @@
"domain": "nuki",
"name": "Nuki",
"documentation": "https://www.home-assistant.io/components/nuki",
"requirements": [
"pynuki==1.3.3"
],
"requirements": ["pynuki==1.3.3"],
"dependencies": [],
"codeowners": [
"@pschmitt"
]
"codeowners": ["@pvizeli"]
}

View File

@@ -2,7 +2,7 @@
"domain": "upc_connect",
"name": "Upc connect",
"documentation": "https://www.home-assistant.io/components/upc_connect",
"requirements": ["connect-box==0.2.3"],
"requirements": ["connect-box==0.2.4"],
"dependencies": [],
"codeowners": ["@pvizeli"]
}

View File

@@ -2,7 +2,7 @@
"""Constants used by Home Assistant components."""
MAJOR_VERSION = 0
MINOR_VERSION = 99
PATCH_VERSION = "0b2"
PATCH_VERSION = "0b3"
__short_version__ = "{}.{}".format(MAJOR_VERSION, MINOR_VERSION)
__version__ = "{}.{}".format(__short_version__, PATCH_VERSION)
REQUIRED_PYTHON_VER = (3, 6, 0)

View File

@@ -11,7 +11,7 @@ contextvars==2.4;python_version<"3.7"
cryptography==2.7
distro==1.4.0
hass-nabucasa==0.17
home-assistant-frontend==20190917.0
home-assistant-frontend==20190917.1
importlib-metadata==0.19
jinja2>=2.10.1
netdisco==2.6.0

View File

@@ -355,7 +355,7 @@ colorlog==4.0.2
concord232==0.15
# homeassistant.components.upc_connect
connect-box==0.2.3
connect-box==0.2.4
# homeassistant.components.eddystone_temperature
# homeassistant.components.eq3btsmart
@@ -639,7 +639,7 @@ hole==0.5.0
holidays==0.9.11
# homeassistant.components.frontend
home-assistant-frontend==20190917.0
home-assistant-frontend==20190917.1
# homeassistant.components.zwave
homeassistant-pyozw==0.1.4

View File

@@ -178,7 +178,7 @@ hole==0.5.0
holidays==0.9.11
# homeassistant.components.frontend
home-assistant-frontend==20190917.0
home-assistant-frontend==20190917.1
# homeassistant.components.homekit_controller
homekit[IP]==0.15.0