Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/components/homekit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ def get_accessory(hass, state, aid, config):
aid=aid)

elif state.domain == 'alarm_control_panel':
_LOGGER.debug('Add "%s" as "%s"', state.entity_id,
'SecuritySystem')
_LOGGER.debug('Add "%s" as "%s"', state.entity_id, 'SecuritySystem')
return TYPES['SecuritySystem'](hass, state.entity_id, state.name,
alarm_code=config.get(ATTR_CODE),
aid=aid)
Expand All @@ -120,6 +119,7 @@ def get_accessory(hass, state, aid, config):
state.name, support_auto, aid=aid)

elif state.domain == 'light':
_LOGGER.debug('Add "%s" as "%s"', state.entity_id, 'Light')
return TYPES['Light'](hass, state.entity_id, state.name, aid=aid)

elif state.domain == 'switch' or state.domain == 'remote' \
Expand Down
10 changes: 5 additions & 5 deletions homeassistant/components/homekit/accessories.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ def _set_services(self):

def run(self):
"""Method called by accessory after driver is started."""
state = self._hass.states.get(self._entity_id)
state = self.hass.states.get(self.entity_id)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe pass hass and entity_id into the HomeAccesory constructor, then you can remove those assignments from all child classes & you dont need the no-member pylint directive

self.update_state(new_state=state)
async_track_state_change(
self._hass, self._entity_id, self.update_state)
self.hass, self.entity_id, self.update_state)


class HomeBridge(Bridge):
Expand All @@ -79,7 +79,7 @@ def __init__(self, hass, name=BRIDGE_NAME,
"""Initialize a Bridge object."""
super().__init__(name, **kwargs)
set_accessory_info(self, name, model)
self._hass = hass
self.hass = hass

def _set_services(self):
add_preload_service(self, SERV_ACCESSORY_INFO)
Expand All @@ -92,12 +92,12 @@ def setup_message(self):
def add_paired_client(self, client_uuid, client_public):
"""Override super function to dismiss setup message if paired."""
super().add_paired_client(client_uuid, client_public)
dismiss_setup_message(self._hass)
dismiss_setup_message(self.hass)

def remove_paired_client(self, client_uuid):
"""Override super function to show setup message if unpaired."""
super().remove_paired_client(client_uuid)
show_setup_message(self, self._hass)
show_setup_message(self, self.hass)


class HomeDriver(AccessoryDriver):
Expand Down
4 changes: 4 additions & 0 deletions homeassistant/components/homekit/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
MANUFACTURER = 'HomeAssistant'

# #### Categories ####
CATEGORY_ALARM_SYSTEM = 'ALARM_SYSTEM'
CATEGORY_LIGHT = 'LIGHTBULB'
CATEGORY_SENSOR = 'SENSOR'
CATEGORY_SWITCH = 'SWITCH'
CATEGORY_THERMOSTAT = 'THERMOSTAT'
CATEGORY_WINDOW_COVERING = 'WINDOW_COVERING'


# #### Services ####
Expand Down
20 changes: 10 additions & 10 deletions homeassistant/components/homekit/type_covers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from . import TYPES
from .accessories import HomeAccessory, add_preload_service
from .const import (
SERV_WINDOW_COVERING, CHAR_CURRENT_POSITION,
CHAR_TARGET_POSITION, CHAR_POSITION_STATE)
CATEGORY_WINDOW_COVERING, SERV_WINDOW_COVERING,
CHAR_CURRENT_POSITION, CHAR_TARGET_POSITION, CHAR_POSITION_STATE)


_LOGGER = logging.getLogger(__name__)
Expand All @@ -20,13 +20,13 @@ class WindowCovering(HomeAccessory):
The cover entity must support: set_cover_position.
"""

def __init__(self, hass, entity_id, display_name, *args, **kwargs):
def __init__(self, hass, entity_id, display_name, **kwargs):
"""Initialize a WindowCovering accessory object."""
super().__init__(display_name, entity_id, 'WINDOW_COVERING',
*args, **kwargs)
super().__init__(display_name, entity_id,
CATEGORY_WINDOW_COVERING, **kwargs)

self._hass = hass
self._entity_id = entity_id
self.hass = hass
self.entity_id = entity_id

self.current_position = None
self.homekit_target = None
Expand All @@ -48,14 +48,14 @@ def move_cover(self, value):
"""Move cover to value if call came from HomeKit."""
self.char_target_position.set_value(value, should_callback=False)
if value != self.current_position:
_LOGGER.debug('%s: Set position to %d', self._entity_id, value)
_LOGGER.debug('%s: Set position to %d', self.entity_id, value)
self.homekit_target = value
if value > self.current_position:
self.char_position_state.set_value(1)
elif value < self.current_position:
self.char_position_state.set_value(0)
self._hass.components.cover.set_cover_position(
value, self._entity_id)
self.hass.components.cover.set_cover_position(
value, self.entity_id)

def update_state(self, entity_id=None, old_state=None, new_state=None):
"""Update cover position after state changed."""
Expand Down
34 changes: 17 additions & 17 deletions homeassistant/components/homekit/type_lights.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ class Light(HomeAccessory):
Currently supports: state, brightness, rgb_color.
"""

def __init__(self, hass, entity_id, name, *args, **kwargs):
def __init__(self, hass, entity_id, name, **kwargs):
"""Initialize a new Light accessory object."""
super().__init__(name, entity_id, CATEGORY_LIGHT, *args, **kwargs)
super().__init__(name, entity_id, CATEGORY_LIGHT, **kwargs)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your parent class constructor signature does not have entity_id, but you seem to include it here?

def __init__(self, name=ACCESSORY_NAME, model=ACCESSORY_MODEL,
           category='OTHER', **kwargs):


self._hass = hass
self._entity_id = entity_id
self.hass = hass
self.entity_id = entity_id
self._flag = {CHAR_ON: False, CHAR_BRIGHTNESS: False,
CHAR_HUE: False, CHAR_SATURATION: False,
RGB_COLOR: False}
self._state = 0

self.chars = []
self._features = self._hass.states.get(self._entity_id) \
self._features = self.hass.states.get(self.entity_id) \
.attributes.get(ATTR_SUPPORTED_FEATURES)
if self._features & SUPPORT_BRIGHTNESS:
self.chars.append(CHAR_BRIGHTNESS)
Expand Down Expand Up @@ -70,37 +70,37 @@ def set_state(self, value):
if self._state == value:
return

_LOGGER.debug('%s: Set state to %d', self._entity_id, value)
_LOGGER.debug('%s: Set state to %d', self.entity_id, value)
self._flag[CHAR_ON] = True
self.char_on.set_value(value, should_callback=False)

if value == 1:
self._hass.components.light.turn_on(self._entity_id)
self.hass.components.light.turn_on(self.entity_id)
elif value == 0:
self._hass.components.light.turn_off(self._entity_id)
self.hass.components.light.turn_off(self.entity_id)

def set_brightness(self, value):
"""Set brightness if call came from HomeKit."""
_LOGGER.debug('%s: Set brightness to %d', self._entity_id, value)
_LOGGER.debug('%s: Set brightness to %d', self.entity_id, value)
self._flag[CHAR_BRIGHTNESS] = True
self.char_brightness.set_value(value, should_callback=False)
if value != 0:
self._hass.components.light.turn_on(
self._entity_id, brightness_pct=value)
self.hass.components.light.turn_on(
self.entity_id, brightness_pct=value)
else:
self._hass.components.light.turn_off(self._entity_id)
self.hass.components.light.turn_off(self.entity_id)

def set_saturation(self, value):
"""Set saturation if call came from HomeKit."""
_LOGGER.debug('%s: Set saturation to %d', self._entity_id, value)
_LOGGER.debug('%s: Set saturation to %d', self.entity_id, value)
self._flag[CHAR_SATURATION] = True
self.char_saturation.set_value(value, should_callback=False)
self._saturation = value
self.set_color()

def set_hue(self, value):
"""Set hue if call came from HomeKit."""
_LOGGER.debug('%s: Set hue to %d', self._entity_id, value)
_LOGGER.debug('%s: Set hue to %d', self.entity_id, value)
self._flag[CHAR_HUE] = True
self.char_hue.set_value(value, should_callback=False)
self._hue = value
Expand All @@ -112,11 +112,11 @@ def set_color(self):
if self._features & SUPPORT_COLOR and self._flag[CHAR_HUE] and \
self._flag[CHAR_SATURATION]:
color = (self._hue, self._saturation)
_LOGGER.debug('%s: Set hs_color to %s', self._entity_id, color)
_LOGGER.debug('%s: Set hs_color to %s', self.entity_id, color)
self._flag.update({
CHAR_HUE: False, CHAR_SATURATION: False, RGB_COLOR: True})
self._hass.components.light.turn_on(
self._entity_id, hs_color=color)
self.hass.components.light.turn_on(
self.entity_id, hs_color=color)

def update_state(self, entity_id=None, old_state=None, new_state=None):
"""Update light after state change."""
Expand Down
23 changes: 11 additions & 12 deletions homeassistant/components/homekit/type_security_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from . import TYPES
from .accessories import HomeAccessory, add_preload_service
from .const import (
SERV_SECURITY_SYSTEM, CHAR_CURRENT_SECURITY_STATE,
CHAR_TARGET_SECURITY_STATE)
CATEGORY_ALARM_SYSTEM, SERV_SECURITY_SYSTEM,
CHAR_CURRENT_SECURITY_STATE, CHAR_TARGET_SECURITY_STATE)

_LOGGER = logging.getLogger(__name__)

Expand All @@ -27,14 +27,13 @@
class SecuritySystem(HomeAccessory):
"""Generate an SecuritySystem accessory for an alarm control panel."""

def __init__(self, hass, entity_id, display_name,
alarm_code, *args, **kwargs):
def __init__(self, hass, entity_id, display_name, alarm_code, **kwargs):
"""Initialize a SecuritySystem accessory object."""
super().__init__(display_name, entity_id, 'ALARM_SYSTEM',
*args, **kwargs)
super().__init__(display_name, entity_id,
CATEGORY_ALARM_SYSTEM, **kwargs)

self._hass = hass
self._entity_id = entity_id
self.hass = hass
self.entity_id = entity_id
self._alarm_code = alarm_code

self.flag_target_state = False
Expand All @@ -52,16 +51,16 @@ def __init__(self, hass, entity_id, display_name,
def set_security_state(self, value):
"""Move security state to value if call came from HomeKit."""
_LOGGER.debug('%s: Set security state to %d',
self._entity_id, value)
self.entity_id, value)
self.flag_target_state = True
self.char_target_state.set_value(value, should_callback=False)
hass_value = HOMEKIT_TO_HASS[value]
service = STATE_TO_SERVICE[hass_value]

params = {ATTR_ENTITY_ID: self._entity_id}
params = {ATTR_ENTITY_ID: self.entity_id}
if self._alarm_code:
params[ATTR_CODE] = self._alarm_code
self._hass.services.call('alarm_control_panel', service, params)
self.hass.services.call('alarm_control_panel', service, params)

def update_state(self, entity_id=None, old_state=None, new_state=None):
"""Update security state after state changed."""
Expand All @@ -76,7 +75,7 @@ def update_state(self, entity_id=None, old_state=None, new_state=None):
self.char_current_state.set_value(current_security_state,
should_callback=False)
_LOGGER.debug('%s: Updated current state to %s (%d)',
self._entity_id, hass_state, current_security_state)
self.entity_id, hass_state, current_security_state)

if not self.flag_target_state:
self.char_target_state.set_value(current_security_state,
Expand Down
16 changes: 8 additions & 8 deletions homeassistant/components/homekit/type_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class TemperatureSensor(HomeAccessory):
Sensor entity must return temperature in °C, °F.
"""

def __init__(self, hass, entity_id, name, *args, **kwargs):
def __init__(self, hass, entity_id, name, **kwargs):
"""Initialize a TemperatureSensor accessory object."""
super().__init__(name, entity_id, CATEGORY_SENSOR, *args, **kwargs)
super().__init__(name, entity_id, CATEGORY_SENSOR, **kwargs)

self._hass = hass
self._entity_id = entity_id
self.hass = hass
self.entity_id = entity_id

serv_temp = add_preload_service(self, SERV_TEMPERATURE_SENSOR)
self.char_temp = serv_temp.get_characteristic(CHAR_CURRENT_TEMPERATURE)
Expand All @@ -47,7 +47,7 @@ def update_state(self, entity_id=None, old_state=None, new_state=None):
temperature = temperature_to_homekit(temperature, unit)
self.char_temp.set_value(temperature, should_callback=False)
_LOGGER.debug('%s: Current temperature set to %d°C',
self._entity_id, temperature)
self.entity_id, temperature)


@TYPES.register('HumiditySensor')
Expand All @@ -58,8 +58,8 @@ def __init__(self, hass, entity_id, name, *args, **kwargs):
"""Initialize a HumiditySensor accessory object."""
super().__init__(name, entity_id, CATEGORY_SENSOR, *args, **kwargs)

self._hass = hass
self._entity_id = entity_id
self.hass = hass
self.entity_id = entity_id

serv_humidity = add_preload_service(self, SERV_HUMIDITY_SENSOR)
self.char_humidity = serv_humidity \
Expand All @@ -75,4 +75,4 @@ def update_state(self, entity_id=None, old_state=None, new_state=None):
if humidity:
self.char_humidity.set_value(humidity, should_callback=False)
_LOGGER.debug('%s: Percent set to %d%%',
self._entity_id, humidity)
self.entity_id, humidity)
18 changes: 9 additions & 9 deletions homeassistant/components/homekit/type_switches.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from . import TYPES
from .accessories import HomeAccessory, add_preload_service
from .const import SERV_SWITCH, CHAR_ON
from .const import CATEGORY_SWITCH, SERV_SWITCH, CHAR_ON

_LOGGER = logging.getLogger(__name__)

Expand All @@ -16,12 +16,12 @@
class Switch(HomeAccessory):
"""Generate a Switch accessory."""

def __init__(self, hass, entity_id, display_name, *args, **kwargs):
def __init__(self, hass, entity_id, display_name, **kwargs):
"""Initialize a Switch accessory object to represent a remote."""
super().__init__(display_name, entity_id, 'SWITCH', *args, **kwargs)
super().__init__(display_name, entity_id, CATEGORY_SWITCH, **kwargs)

self._hass = hass
self._entity_id = entity_id
self.hass = hass
self.entity_id = entity_id
self._domain = split_entity_id(entity_id)[0]

self.flag_target_state = False
Expand All @@ -34,12 +34,12 @@ def __init__(self, hass, entity_id, display_name, *args, **kwargs):
def set_state(self, value):
"""Move switch state to value if call came from HomeKit."""
_LOGGER.debug('%s: Set switch state to %s',
self._entity_id, value)
self.entity_id, value)
self.flag_target_state = True
self.char_on.set_value(value, should_callback=False)
service = SERVICE_TURN_ON if value else SERVICE_TURN_OFF
self._hass.services.call(self._domain, service,
{ATTR_ENTITY_ID: self._entity_id})
self.hass.services.call(self._domain, service,
{ATTR_ENTITY_ID: self.entity_id})

def update_state(self, entity_id=None, old_state=None, new_state=None):
"""Update switch state after state changed."""
Expand All @@ -49,7 +49,7 @@ def update_state(self, entity_id=None, old_state=None, new_state=None):
current_state = (new_state.state == STATE_ON)
if not self.flag_target_state:
_LOGGER.debug('%s: Set current state to %s',
self._entity_id, current_state)
self.entity_id, current_state)
self.char_on.set_value(current_state, should_callback=False)

self.flag_target_state = False
Loading