Improved Homekit tests (#12800)
* Added test for temperature fahrenheit * Restructured tests to use more mocks * Rearanged homekit constants * Improved 'test_homekit_class' * Added import statements * Fix Pylint Test errors
This commit is contained in:
parent
d3386907a4
commit
168e1f0e2d
11 changed files with 420 additions and 94 deletions
|
@ -64,12 +64,10 @@ def async_setup(hass, config):
|
|||
|
||||
|
||||
def import_types():
|
||||
"""Import all types from files in the HomeKit dir."""
|
||||
"""Import all types from files in the HomeKit directory."""
|
||||
_LOGGER.debug("Import type files.")
|
||||
# pylint: disable=unused-variable
|
||||
from .covers import Window # noqa F401
|
||||
# pylint: disable=unused-variable
|
||||
from .sensors import TemperatureSensor # noqa F401
|
||||
from . import covers, sensors # noqa F401
|
||||
|
||||
|
||||
def get_accessory(hass, state):
|
||||
|
|
|
@ -4,7 +4,7 @@ import logging
|
|||
from pyhap.accessory import Accessory, Bridge, Category
|
||||
|
||||
from .const import (
|
||||
SERV_ACCESSORY_INFO, MANUFACTURER,
|
||||
SERV_ACCESSORY_INFO, SERV_BRIDGING_STATE, MANUFACTURER,
|
||||
CHAR_MODEL, CHAR_MANUFACTURER, CHAR_SERIAL_NUMBER)
|
||||
|
||||
|
||||
|
@ -46,17 +46,24 @@ def override_properties(char, new_properties):
|
|||
class HomeAccessory(Accessory):
|
||||
"""Class to extend the Accessory class."""
|
||||
|
||||
def __init__(self, display_name, model, category='OTHER'):
|
||||
def __init__(self, display_name, model, category='OTHER', **kwargs):
|
||||
"""Initialize a Accessory object."""
|
||||
super().__init__(display_name)
|
||||
super().__init__(display_name, **kwargs)
|
||||
set_accessory_info(self, model)
|
||||
self.category = getattr(Category, category, Category.OTHER)
|
||||
|
||||
def _set_services(self):
|
||||
add_preload_service(self, SERV_ACCESSORY_INFO)
|
||||
|
||||
|
||||
class HomeBridge(Bridge):
|
||||
"""Class to extend the Bridge class."""
|
||||
|
||||
def __init__(self, display_name, model, pincode):
|
||||
def __init__(self, display_name, model, pincode, **kwargs):
|
||||
"""Initialize a Bridge object."""
|
||||
super().__init__(display_name, pincode=pincode)
|
||||
super().__init__(display_name, pincode=pincode, **kwargs)
|
||||
set_accessory_info(self, model)
|
||||
|
||||
def _set_services(self):
|
||||
add_preload_service(self, SERV_ACCESSORY_INFO)
|
||||
add_preload_service(self, SERV_BRIDGING_STATE)
|
||||
|
|
|
@ -1,21 +1,24 @@
|
|||
"""Constants used be the HomeKit component."""
|
||||
MANUFACTURER = 'HomeAssistant'
|
||||
|
||||
# Service: AccessoryInfomation
|
||||
# Services
|
||||
SERV_ACCESSORY_INFO = 'AccessoryInformation'
|
||||
CHAR_MODEL = 'Model'
|
||||
CHAR_MANUFACTURER = 'Manufacturer'
|
||||
CHAR_SERIAL_NUMBER = 'SerialNumber'
|
||||
|
||||
# Service: TemperatureSensor
|
||||
SERV_BRIDGING_STATE = 'BridgingState'
|
||||
SERV_TEMPERATURE_SENSOR = 'TemperatureSensor'
|
||||
CHAR_CURRENT_TEMPERATURE = 'CurrentTemperature'
|
||||
|
||||
# Service: WindowCovering
|
||||
SERV_WINDOW_COVERING = 'WindowCovering'
|
||||
|
||||
# Characteristics
|
||||
CHAR_ACC_IDENTIFIER = 'AccessoryIdentifier'
|
||||
CHAR_CATEGORY = 'Category'
|
||||
CHAR_CURRENT_POSITION = 'CurrentPosition'
|
||||
CHAR_TARGET_POSITION = 'TargetPosition'
|
||||
CHAR_CURRENT_TEMPERATURE = 'CurrentTemperature'
|
||||
CHAR_LINK_QUALITY = 'LinkQuality'
|
||||
CHAR_MANUFACTURER = 'Manufacturer'
|
||||
CHAR_MODEL = 'Model'
|
||||
CHAR_POSITION_STATE = 'PositionState'
|
||||
CHAR_REACHABLE = 'Reachable'
|
||||
CHAR_SERIAL_NUMBER = 'SerialNumber'
|
||||
CHAR_TARGET_POSITION = 'TargetPosition'
|
||||
|
||||
# Properties
|
||||
PROP_CELSIUS = {'minValue': -273, 'maxValue': 999}
|
||||
|
|
|
@ -38,6 +38,9 @@ class Window(HomeAccessory):
|
|||
get_characteristic(CHAR_TARGET_POSITION)
|
||||
self.char_position_state = self.serv_cover. \
|
||||
get_characteristic(CHAR_POSITION_STATE)
|
||||
self.char_current_position.value = 0
|
||||
self.char_target_position.value = 0
|
||||
self.char_position_state.value = 0
|
||||
|
||||
self.char_target_position.setter_callback = self.move_cover
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ class TemperatureSensor(HomeAccessory):
|
|||
self.char_temp = self.serv_temp. \
|
||||
get_characteristic(CHAR_CURRENT_TEMPERATURE)
|
||||
override_properties(self.char_temp, PROP_CELSIUS)
|
||||
self.char_temp.value = 0
|
||||
self.unit = None
|
||||
|
||||
def run(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue