Skip to content
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

Added services to beep switches #1

Open
wants to merge 7 commits into
base: konnected
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ omit =
homeassistant/components/knx.py
homeassistant/components/*/knx.py

homeassistant/components/konnected.py
homeassistant/components/*/konnected.py

homeassistant/components/lametric.py
homeassistant/components/*/lametric.py

Expand Down
74 changes: 74 additions & 0 deletions homeassistant/components/binary_sensor/konnected.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
Support for wired binary sensors attached to a Konnected device.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/binary_sensor.konnected/
"""
import asyncio
import logging

from homeassistant.components.binary_sensor import BinarySensorDevice
from homeassistant.components.konnected import (DOMAIN, PIN_TO_ZONE)
from homeassistant.const import (
CONF_DEVICES, CONF_TYPE, CONF_NAME, CONF_SENSORS, ATTR_STATE)

_LOGGER = logging.getLogger(__name__)

DEPENDENCIES = ['konnected']


async def async_setup_platform(hass, config, async_add_devices,
discovery_info=None):
"""Set up binary sensors attached to a Konnected device."""
if discovery_info is None:
return

data = hass.data[DOMAIN]
device_id = discovery_info['device_id']
sensors = [KonnectedBinarySensor(device_id, pin_num, pin_data)
for pin_num, pin_data in
data[CONF_DEVICES][device_id][CONF_SENSORS].items()]
async_add_devices(sensors)


class KonnectedBinarySensor(BinarySensorDevice):
"""Representation of a Konnected binary sensor."""

def __init__(self, device_id, pin_num, data):
"""Initialize the binary sensor."""
self._data = data
self._device_id = device_id
self._pin_num = pin_num
self._state = self._data.get(ATTR_STATE)
self._device_class = self._data.get(CONF_TYPE)
self._name = self._data.get(CONF_NAME, 'Konnected {} Zone {}'.format(
device_id, PIN_TO_ZONE[pin_num]))
self._data['entity'] = self
_LOGGER.debug('Created new Konnected sensor: %s', self._name)

@property
def name(self):
"""Return the name of the sensor."""
return self._name

@property
def is_on(self):
"""Return the state of the sensor."""
return self._state

@property
def should_poll(self):
"""No polling needed."""
return False

@property
def device_class(self):
"""Return the device class."""
return self._device_class

@asyncio.coroutine
def async_set_state(self, state):
"""Update the sensor's state."""
self._state = state
self._data[ATTR_STATE] = state
self.async_schedule_update_ha_state()
3 changes: 3 additions & 0 deletions homeassistant/components/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
SERVICE_XIAOMI_GW = 'xiaomi_gw'
SERVICE_TELLDUSLIVE = 'tellstick'
SERVICE_HUE = 'philips_hue'
SERVICE_KONNECTED = 'konnected'
SERVICE_DECONZ = 'deconz'
SERVICE_DAIKIN = 'daikin'
SERVICE_SAMSUNG_PRINTER = 'samsung_printer'
Expand All @@ -60,6 +61,7 @@
SERVICE_TELLDUSLIVE: ('tellduslive', None),
SERVICE_DAIKIN: ('daikin', None),
SERVICE_SAMSUNG_PRINTER: ('sensor', 'syncthru'),
SERVICE_KONNECTED: ('konnected', None),
'google_cast': ('media_player', 'cast'),
'panasonic_viera': ('media_player', 'panasonic_viera'),
'plex_mediaserver': ('media_player', 'plex'),
Expand Down Expand Up @@ -189,6 +191,7 @@ def _discover(netdisco):
for disc in netdisco.discover():
for service in netdisco.get_info(disc):
results.append((disc, service))

finally:
netdisco.stop()

Expand Down
Loading