Skip to content

Commit

Permalink
work started
Browse files Browse the repository at this point in the history
  • Loading branch information
Joachim Lusiardi committed Apr 7, 2020
1 parent cd08284 commit 4b568f3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
16 changes: 11 additions & 5 deletions homekit/controller/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from homekit.model.characteristics.characteristic_types import CharacteristicsTypes
from homekit.protocol.opcodes import HapBleOpCodes
from homekit.tools import IP_TRANSPORT_SUPPORTED, BLE_TRANSPORT_SUPPORTED
from homekit.controller.tools import DummyPairing
from homekit.controller.additional_pairing import AdditionalPairing

if BLE_TRANSPORT_SUPPORTED:
Expand Down Expand Up @@ -256,7 +257,6 @@ def load_data(self, filename):
with open(filename, 'r') as input_fp:
data = json.load(input_fp)
for pairing_id in data:

if 'Connection' not in data[pairing_id]:
# This is a pre BLE entry in the file with the pairing data, hence it is for an IP based
# accessory. So we set the connection type (in case save data is used everything will be fine)
Expand All @@ -267,12 +267,18 @@ def load_data(self, filename):

if data[pairing_id]['Connection'] == 'IP':
if not IP_TRANSPORT_SUPPORTED:
raise TransportNotSupportedError('IP')
self.pairings[pairing_id] = IpPairing(data[pairing_id])
self.logger.debug(
'setting pairing "%s" to dummy implementation because IP is not supported', pairing_id)
self.pairings[pairing_id] = DummyPairing(data[pairing_id], 'IP')
else:
self.pairings[pairing_id] = IpPairing(data[pairing_id])
elif data[pairing_id]['Connection'] == 'BLE':
if not BLE_TRANSPORT_SUPPORTED:
raise TransportNotSupportedError('BLE')
self.pairings[pairing_id] = BlePairing(data[pairing_id], self.ble_adapter)
self.logger.debug(
'setting pairing "%s" to dummy implementation because BLE is not supported', pairing_id)
self.pairings[pairing_id] = DummyPairing(data[pairing_id], 'BLE')
else:
self.pairings[pairing_id] = BlePairing(data[pairing_id], self.ble_adapter)
elif data[pairing_id]['Connection'] == 'ADDITIONAL_PAIRING':
self.pairings[pairing_id] = AdditionalPairing(data[pairing_id])
else:
Expand Down
38 changes: 38 additions & 0 deletions homekit/controller/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,44 @@ def add_pairing(self, additional_controller_pairing_identifier, ios_device_ltpk,
pass


class DummyPairing(AbstractPairing):
def __init__(self, pairing_data, connection_type):
self.pairing_data = pairing_data
self.connection_type = connection_type

def close(self):
pass

def list_accessories_and_characteristics(self):
raise NotImplementedError(
'Connection type "{}" is not supported in this setup!'.format(self.connection_type))

def list_pairings(self):
raise NotImplementedError(
'Connection type "{}" is not supported in this setup!'.format(self.connection_type))

def get_characteristics(self, characteristics, include_meta=False, include_perms=False, include_type=False,
include_events=False):
raise NotImplementedError(
'Connection type "{}" is not supported in this setup!'.format(self.connection_type))

def put_characteristics(self, characteristics, do_conversion=False):
raise NotImplementedError(
'Connection type "{}" is not supported in this setup!'.format(self.connection_type))

def get_events(self, characteristics, callback_fun, max_events=-1, max_seconds=-1):
raise NotImplementedError(
'Connection type "{}" is not supported in this setup!'.format(self.connection_type))

def identify(self):
raise NotImplementedError(
'Connection type "{}" is not supported in this setup!'.format(self.connection_type))

def add_pairing(self, additional_controller_pairing_identifier, ios_device_ltpk, permissions):
raise NotImplementedError(
'Connection type "{}" is not supported in this setup!'.format(self.connection_type))


def check_convert_value(val, target_type):
"""
Checks if the given value is of the given type or is convertible into the type. If the value is not convertible, a
Expand Down

0 comments on commit 4b568f3

Please sign in to comment.