Black
This commit is contained in:
1 parent
da05dfe708
commit
4de97abc3a
2676 files changed
+163166
-140084
No files matched your search
@@ -2,43 +2,33 @@
|
||||
import logging
|
||||
|
||||
from homeassistant.components.lock import LockDevice
|
||||
from homeassistant.const import (
|
||||
ATTR_BATTERY_LEVEL, STATE_LOCKED, STATE_UNLOCKED)
|
||||
from homeassistant.const import ATTR_BATTERY_LEVEL, STATE_LOCKED, STATE_UNLOCKED
|
||||
|
||||
from . import KNOWN_DEVICES, HomeKitEntity
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
STATE_JAMMED = 'jammed'
|
||||
STATE_JAMMED = "jammed"
|
||||
|
||||
CURRENT_STATE_MAP = {
|
||||
0: STATE_UNLOCKED,
|
||||
1: STATE_LOCKED,
|
||||
2: STATE_JAMMED,
|
||||
3: None,
|
||||
}
|
||||
CURRENT_STATE_MAP = {0: STATE_UNLOCKED, 1: STATE_LOCKED, 2: STATE_JAMMED, 3: None}
|
||||
|
||||
TARGET_STATE_MAP = {
|
||||
STATE_UNLOCKED: 0,
|
||||
STATE_LOCKED: 1,
|
||||
}
|
||||
TARGET_STATE_MAP = {STATE_UNLOCKED: 0, STATE_LOCKED: 1}
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass, config, async_add_entities, discovery_info=None):
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
"""Legacy set up platform."""
|
||||
pass
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities):
|
||||
"""Set up Homekit lock."""
|
||||
hkid = config_entry.data['AccessoryPairingID']
|
||||
hkid = config_entry.data["AccessoryPairingID"]
|
||||
conn = hass.data[KNOWN_DEVICES][hkid]
|
||||
|
||||
def async_add_service(aid, service):
|
||||
if service['stype'] != 'lock-mechanism':
|
||||
if service["stype"] != "lock-mechanism":
|
||||
return False
|
||||
info = {'aid': aid, 'iid': service['iid']}
|
||||
info = {"aid": aid, "iid": service["iid"]}
|
||||
async_add_entities([HomeKitLock(conn, info)], True)
|
||||
return True
|
||||
|
||||
@@ -58,6 +48,7 @@ class HomeKitLock(HomeKitEntity, LockDevice):
|
||||
"""Define the homekit characteristics the entity cares about."""
|
||||
# pylint: disable=import-error
|
||||
from homekit.model.characteristics import CharacteristicsTypes
|
||||
|
||||
return [
|
||||
CharacteristicsTypes.LOCK_MECHANISM_CURRENT_STATE,
|
||||
CharacteristicsTypes.LOCK_MECHANISM_TARGET_STATE,
|
||||
@@ -85,9 +76,13 @@ class HomeKitLock(HomeKitEntity, LockDevice):
|
||||
|
||||
async def _set_lock_state(self, state):
|
||||
"""Send state command."""
|
||||
characteristics = [{'aid': self._aid,
|
||||
'iid': self._chars['lock-mechanism.target-state'],
|
||||
'value': TARGET_STATE_MAP[state]}]
|
||||
characteristics = [
|
||||
{
|
||||
"aid": self._aid,
|
||||
"iid": self._chars["lock-mechanism.target-state"],
|
||||
"value": TARGET_STATE_MAP[state],
|
||||
}
|
||||
]
|
||||
await self._accessory.put_characteristics(characteristics)
|
||||
|
||||
@property
|
||||
@@ -96,6 +91,4 @@ class HomeKitLock(HomeKitEntity, LockDevice):
|
||||
if self._battery_level is None:
|
||||
return None
|
||||
|
||||
return {
|
||||
ATTR_BATTERY_LEVEL: self._battery_level,
|
||||
}
|
||||
return {ATTR_BATTERY_LEVEL: self._battery_level}
|
||||
Reference in new issue
Block a user