-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade insteonplm to 0.8.2 (required refactoring) #12534
Changes from 87 commits
064c893
edb9a6b
e000735
9fb4604
06a0eac
dd346d9
9336f3e
2d4d53a
0b2efe1
d4e20e7
0aebd2b
88e8bb5
5a823e8
49afc27
d7cf3ec
d6e6f06
69dba29
ca1d91d
8de7260
06e60fd
967ed03
6a8936d
c7c0534
39003dc
ae7b8f3
c51ae4b
b1c1b2b
24c1883
75481d3
aad0fa4
7aaf294
9b50e90
b6b19a9
c05bf26
b72d015
e84ff33
6de2339
ab2ee0d
13ae2a7
c804b5f
dd50660
a00c9f6
e3f9fde
9736890
701ba7b
e87c117
a3455fd
6d4701f
2810351
7037b08
2a7cc56
6c55846
8a2b0c7
4cda478
a7a718f
e077806
5bef1fc
15e9eef
fd3240e
9367a17
9de6960
4a2d320
0d8fb99
1836baf
c46cca1
94b390a
6d11c42
65656cc
92623c4
0453d9f
12c5651
22cadff
4963a25
07814b4
55fb724
ec30677
4bd0832
96baad0
5ef044a
d217668
452619f
9fcdfc5
1e5ddc2
8819294
39046c9
e17f2f1
36230de
a0b7c25
22b69fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,86 +2,56 @@ | |
Support for INSTEON dimmers via PowerLinc Modem. | ||
|
||
For more details about this component, please refer to the documentation at | ||
https://home-assistant.io/components/insteon_plm/ | ||
https://home-assistant.io/components/binary_sensor.insteon_plm/ | ||
""" | ||
import logging | ||
import asyncio | ||
import logging | ||
|
||
from homeassistant.core import callback | ||
from homeassistant.components.binary_sensor import BinarySensorDevice | ||
from homeassistant.loader import get_component | ||
from homeassistant.components.insteon_plm import InsteonPLMEntity | ||
|
||
DEPENDENCIES = ['insteon_plm'] | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
SENSOR_TYPES = {'openClosedSensor': 'opening', | ||
'motionSensor': 'motion', | ||
'doorSensor': 'door', | ||
'leakSensor': 'moisture'} | ||
|
||
|
||
@asyncio.coroutine | ||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): | ||
"""Set up the INSTEON PLM device class for the hass platform.""" | ||
plm = hass.data['insteon_plm'] | ||
|
||
device_list = [] | ||
for device in discovery_info: | ||
name = device.get('address') | ||
address = device.get('address_hex') | ||
|
||
_LOGGER.info('Registered %s with binary_sensor platform.', name) | ||
|
||
device_list.append( | ||
InsteonPLMBinarySensorDevice(hass, plm, address, name) | ||
) | ||
address = discovery_info['address'] | ||
device = plm.devices[address] | ||
state_key = discovery_info['state_key'] | ||
|
||
async_add_devices(device_list) | ||
_LOGGER.debug('Adding device %s entity %s to Binary Sensor platform.', | ||
device.address.hex, device.states[state_key].name) | ||
|
||
new_entity = InsteonPLMBinarySensor(device, state_key) | ||
|
||
class InsteonPLMBinarySensorDevice(BinarySensorDevice): | ||
"""A Class for an Insteon device.""" | ||
async_add_devices([new_entity]) | ||
|
||
def __init__(self, hass, plm, address, name): | ||
"""Initialize the binarysensor.""" | ||
self._hass = hass | ||
self._plm = plm.protocol | ||
self._address = address | ||
self._name = name | ||
|
||
self._plm.add_update_callback( | ||
self.async_binarysensor_update, {'address': self._address}) | ||
class InsteonPLMBinarySensor(InsteonPLMEntity, BinarySensorDevice): | ||
"""A Class for an Insteon device entity.""" | ||
|
||
@property | ||
def should_poll(self): | ||
"""No polling needed.""" | ||
return False | ||
|
||
@property | ||
def address(self): | ||
"""Return the address of the node.""" | ||
return self._address | ||
def __init__(self, device, state_key): | ||
"""Initialize the INSTEON PLM binary sensor.""" | ||
InsteonPLMEntity.__init__(self, device, state_key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super().__init__(device, state_key) |
||
self._sensor_type = SENSOR_TYPES.get(self._insteon_device_state.name) | ||
|
||
@property | ||
def name(self): | ||
"""Return the name of the node.""" | ||
return self._name | ||
def device_class(self): | ||
"""Return the class of this sensor.""" | ||
return self._sensor_type | ||
|
||
@property | ||
def is_on(self): | ||
"""Return the boolean response if the node is on.""" | ||
sensorstate = self._plm.get_device_attr(self._address, 'sensorstate') | ||
_LOGGER.info("Sensor state for %s is %s", self._address, sensorstate) | ||
sensorstate = self._insteon_device_state.value | ||
return bool(sensorstate) | ||
|
||
@property | ||
def device_state_attributes(self): | ||
"""Provide attributes for display on device card.""" | ||
insteon_plm = get_component('insteon_plm') | ||
return insteon_plm.common_attributes(self) | ||
|
||
def get_attr(self, key): | ||
"""Return specified attribute for this device.""" | ||
return self._plm.get_device_attr(self.address, key) | ||
|
||
@callback | ||
def async_binarysensor_update(self, message): | ||
"""Receive notification from transport that new data exists.""" | ||
_LOGGER.info("Received update callback from PLM for %s", self._address) | ||
self._hass.async_add_job(self.async_update_ha_state()) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
""" | ||
Support for INSTEON fans via PowerLinc Modem. | ||
|
||
For more details about this component, please refer to the documentation at | ||
https://home-assistant.io/components/fan.insteon_plm/ | ||
""" | ||
import asyncio | ||
import logging | ||
|
||
from homeassistant.components.fan import (SPEED_OFF, | ||
SPEED_LOW, | ||
SPEED_MEDIUM, | ||
SPEED_HIGH, | ||
FanEntity, | ||
SUPPORT_SET_SPEED) | ||
from homeassistant.const import STATE_OFF | ||
from homeassistant.components.insteon_plm import InsteonPLMEntity | ||
|
||
DEPENDENCIES = ['insteon_plm'] | ||
|
||
SPEED_TO_HEX = {SPEED_OFF: 0x00, | ||
SPEED_LOW: 0x3f, | ||
SPEED_MEDIUM: 0xbe, | ||
SPEED_HIGH: 0xff} | ||
|
||
FAN_SPEEDS = [STATE_OFF, SPEED_LOW, SPEED_MEDIUM, SPEED_HIGH] | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
@asyncio.coroutine | ||
def async_setup_platform(hass, config, async_add_devices, discovery_info=None): | ||
"""Set up the INSTEON PLM device class for the hass platform.""" | ||
plm = hass.data['insteon_plm'] | ||
|
||
address = discovery_info['address'] | ||
device = plm.devices[address] | ||
state_key = discovery_info['state_key'] | ||
|
||
_LOGGER.debug('Adding device %s entity %s to Fan platform.', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove period at the end. |
||
device.address.hex, device.states[state_key].name) | ||
|
||
new_entity = InsteonPLMFan(device, state_key) | ||
|
||
async_add_devices([new_entity]) | ||
|
||
|
||
class InsteonPLMFan(InsteonPLMEntity, FanEntity): | ||
"""An INSTEON fan component.""" | ||
|
||
@property | ||
def speed(self) -> str: | ||
"""Return the current speed.""" | ||
return self._hex_to_speed(self._insteon_device_state.value) | ||
|
||
@property | ||
def speed_list(self) -> list: | ||
"""Get the list of available speeds.""" | ||
return FAN_SPEEDS | ||
|
||
@property | ||
def supported_features(self) -> int: | ||
"""Flag supported features.""" | ||
return SUPPORT_SET_SPEED | ||
|
||
@asyncio.coroutine | ||
def async_turn_on(self, speed: str = None, **kwargs) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The methods should be annotated with |
||
"""Turn on the entity.""" | ||
if speed is None: | ||
speed = SPEED_MEDIUM | ||
self.async_set_speed(speed) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be addressed. |
||
|
||
@asyncio.coroutine | ||
def async_turn_off(self, **kwargs) -> None: | ||
"""Turn off the entity.""" | ||
self.async_set_speed(SPEED_OFF) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be a coroutine so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somewhat related question. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, |
||
|
||
@asyncio.coroutine | ||
def async_set_speed(self, speed: str) -> None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should also be annotated with |
||
"""Set the speed of the fan.""" | ||
fan_speed = SPEED_TO_HEX[speed] | ||
if fan_speed == 0x00: | ||
self._insteon_device_state.off() | ||
else: | ||
self._insteon_device_state.set_level(fan_speed) | ||
|
||
@staticmethod | ||
def _hex_to_speed(speed: int): | ||
hex_speed = SPEED_OFF | ||
if speed > 0xfe: | ||
hex_speed = SPEED_HIGH | ||
elif speed > 0x7f: | ||
hex_speed = SPEED_MEDIUM | ||
elif speed > 0: | ||
hex_speed = SPEED_LOW | ||
return hex_speed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't end the log message with a period.