Skip to content

Commit

Permalink
Moved siren to Wink from switch (#9879)
Browse files Browse the repository at this point in the history
  • Loading branch information
William Scanlon committed Oct 20, 2017
1 parent d16c5f9 commit 41c2bdb
Show file tree
Hide file tree
Showing 6 changed files with 335 additions and 310 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ omit =
homeassistant/components/wemo.py
homeassistant/components/*/wemo.py

homeassistant/components/wink.py
homeassistant/components/wink/*
homeassistant/components/*/wink.py

homeassistant/components/xiaomi_aqara.py
Expand Down
42 changes: 2 additions & 40 deletions homeassistant/components/services.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@


foursquare:
checkin:
description: Check a user into a Foursquare venue
Expand Down Expand Up @@ -542,45 +543,6 @@ input_boolean:
description: Entity id of the input boolean to turn on
example: 'input_boolean.notify_alerts'

wink:
pair_new_device:
description: Pair a new device to a Wink Hub.

fields:
hub_name:
description: The name of the hub to pair a new device to.
example: 'My hub'
pairing_mode:
description: One of ["zigbee", "zwave", "zwave_exclusion", "zwave_network_rediscovery", "lutron", "bluetooth", "kidde"]
example: 'zigbee'
kidde_radio_code:
description: A string of 8 1s and 0s one for each dip switch on the kidde device left --> right = 1 --> 8
example: '10101010'

rename_wink_device:
description: Rename the provided device.

fields:
entity_id:
description: The entity_id of the device to rename.
example: binary_sensor.front_door_opened
name:
description: The name to change it to.
example: back_door

delete_wink_device:
description: Remove/unpair device from Wink.

fields:
entity_id:
description: The entity_id of the device to delete.

pull_newly_added_devices_from_wink:
description: Pull newly pair devices from Wink.

refresh_state_from_wink:
description: Pull the latest states for every device.

homeassistant:
check_config:
description: Check the Home Assistant configuration files for errors. Errors will be displayed in the Home Assistant log.
Expand All @@ -607,4 +569,4 @@ homeassistant:
fields:
entity_id:
description: The entity_id of the device to turn off
example: light.living_room
example: light.living_room
76 changes: 0 additions & 76 deletions homeassistant/components/switch/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,79 +35,3 @@ mysensors_send_ir_code:
V_IR_SEND:
description: IR code to send
example: '0xC284'

wink_set_chime_volume:
description: Set the volume of the chime for a Dome siren/chime.

fields:
entity_id:
description: Name(s) of the entities to set
example: 'switch.dome_siren'
volume:
description: Volume level. One of ["low", "medium", "high"]
example: "low"


wink_set_siren_volume:
description: Set the volume of the siren for a Dome siren/chime.

fields:
entity_id:
description: Name(s) of the entities to set
example: 'switch.dome_siren'
volume:
description: Volume level. One of ["low", "medium", "high"]
example: "high"

wink_enable_chime:
description: Enable the chime of a Dome siren with the provided sound.

fields:
entity_id:
description: Name(s) of the entities to set
example: 'switch.dome_siren'
tone:
description: The tone to use for the chime. One of ["doorbell", "fur_elise", "doorbell_extended", "alert", "william_tell", "rondo_alla_turca", "police_siren", "evacuation", "beep_beep", "beep", "inactive"]
example: "doorbell"

wink_set_siren_tone:
description: Set the sound to use when the siren is enabled. (This doesn't enable the siren)

fields:
entity_id:
description: Name(s) of the entities to set
example: 'switch.dome_siren'
tone:
description: The tone to use for the chime. One of ["doorbell", "fur_elise", "doorbell_extended", "alert", "william_tell", "rondo_alla_turca", "police_siren", "evacuation", "beep_beep", "beep", "inactive"]
example: "alert"

wink_siren_set_auto_shutoff:
description: How long to sound the siren before turning off.

fields:
entity_id:
description: Name(s) of the entities to set
example: 'switch.dome_siren'
auto_shutoff:
description: The time in seconds to sound the siren. One of [None, -1, 30, 60, 120] (None and -1 are forever. Use None for gocontrol, and -1 for Dome)
example: 60

wink_set_siren_strobe_enabled:
description: Enable or disable the strobe light when the siren is sounding.

fields:
entity_id:
description: Name(s) of the entities to set
example: 'switch.dome_siren'
enabled:
description: "True or False"

wink_set_chime_strobe_enabled:
description: Enable or disable the strobe light when the chime is sounding.

fields:
entity_id:
description: Name(s) of the entities to set
example: 'switch.dome_siren'
enabled:
description: "True or False"
189 changes: 0 additions & 189 deletions homeassistant/components/switch/wink.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,109 +6,19 @@
"""
import asyncio
import logging
from os import path

import voluptuous as vol

from homeassistant.components.wink import WinkDevice, DOMAIN
from homeassistant.helpers.entity import ToggleEntity
import homeassistant.helpers.config_validation as cv
from homeassistant.const import ATTR_ENTITY_ID
from homeassistant.config import load_yaml_config_file

DEPENDENCIES = ['wink']

_LOGGER = logging.getLogger(__name__)

SERVICE_SET_CHIME_VOLUME = "wink_set_chime_volume"
SERVICE_SET_SIREN_VOLUME = "wink_set_siren_volume"
SERVICE_ENABLE_CHIME = "wink_enable_chime"
SERVICE_SET_SIREN_TONE = "wink_set_siren_tone"
SERVICE_SET_SIREN_AUTO_SHUTOFF = "wink_siren_set_auto_shutoff"
SERVICE_SET_SIREN_STROBE_ENABLED = "wink_set_siren_strobe_enabled"
SERVICE_SET_CHIME_STROBE_ENABLED = "wink_set_chime_strobe_enabled"

ATTR_VOLUME = "volume"
ATTR_TONE = "tone"
ATTR_ENABLED = "enabled"
ATTR_AUTO_SHUTOFF = "auto_shutoff"

VOLUMES = ["low", "medium", "high"]
TONES = ["doorbell", "fur_elise", "doorbell_extended", "alert",
"william_tell", "rondo_alla_turca", "police_siren",
"evacuation", "beep_beep", "beep"]
CHIME_TONES = TONES + ["inactive"]
AUTO_SHUTOFF_TIMES = [None, -1, 30, 60, 120]


SET_VOLUME_SCHEMA = vol.Schema({
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
vol.Required(ATTR_VOLUME): vol.In(VOLUMES)
})

SET_SIREN_TONE_SCHEMA = vol.Schema({
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
vol.Required(ATTR_TONE): vol.In(TONES)
})

SET_CHIME_MODE_SCHEMA = vol.Schema({
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
vol.Required(ATTR_TONE): vol.In(CHIME_TONES)
})

SET_AUTO_SHUTOFF_SCHEMA = vol.Schema({
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
vol.Required(ATTR_AUTO_SHUTOFF): vol.In(AUTO_SHUTOFF_TIMES)
})

SET_STROBE_ENABLED_SCHEMA = vol.Schema({
vol.Optional(ATTR_ENTITY_ID): cv.entity_ids,
vol.Required(ATTR_ENABLED): cv.boolean
})


def setup_platform(hass, config, add_devices, discovery_info=None):
"""Set up the Wink platform."""
import pywink

def service_handle(service):
"""Handler for services."""
entity_ids = service.data.get('entity_id')
all_sirens = []
for switch in hass.data[DOMAIN]['entities']['switch']:
if isinstance(switch, WinkSirenDevice):
all_sirens.append(switch)
sirens_to_set = []
if entity_ids is None:
sirens_to_set = all_sirens
else:
for siren in all_sirens:
if siren.entity_id in entity_ids:
sirens_to_set.append(siren)

for siren in sirens_to_set:
if service.service != SERVICE_SET_SIREN_AUTO_SHUTOFF:
if siren.wink.device_manufacturer() != 'dome':
_LOGGER.error("Service only valid for Dome sirens.")
return
if service.service == SERVICE_SET_CHIME_VOLUME:
siren.wink.set_chime_volume(service.data.get(ATTR_VOLUME))
elif service.service == SERVICE_SET_SIREN_VOLUME:
siren.wink.set_siren_volume(service.data.get(ATTR_VOLUME))
elif service.service == SERVICE_SET_SIREN_TONE:
siren.wink.set_siren_sound(service.data.get(ATTR_TONE))
elif service.service == SERVICE_ENABLE_CHIME:
siren.wink.set_chime(service.data.get(ATTR_TONE))
elif service.service == SERVICE_SET_SIREN_STROBE_ENABLED:
siren.wink.set_siren_strobe_enabled(
service.data.get(ATTR_ENABLED))
elif service.service == SERVICE_SET_CHIME_STROBE_ENABLED:
siren.wink.set_chime_strobe_enabled(
service.data.get(ATTR_ENABLED))
else:
siren.wink.set_auto_shutoff(
service.data.get(ATTR_AUTO_SHUTOFF))

for switch in pywink.get_switches():
_id = switch.object_id() + switch.name()
if _id not in hass.data[DOMAIN]['unique_ids']:
Expand All @@ -117,10 +27,6 @@ def service_handle(service):
_id = switch.object_id() + switch.name()
if _id not in hass.data[DOMAIN]['unique_ids']:
add_devices([WinkToggleDevice(switch, hass)])
for siren in pywink.get_sirens():
_id = siren.object_id() + siren.name()
if _id not in hass.data[DOMAIN]['unique_ids']:
add_devices([WinkSirenDevice(siren, hass)])
for sprinkler in pywink.get_sprinklers():
_id = sprinkler.object_id() + sprinkler.name()
if _id not in hass.data[DOMAIN]['unique_ids']:
Expand All @@ -130,44 +36,6 @@ def service_handle(service):
if _id not in hass.data[DOMAIN]['unique_ids']:
add_devices([WinkToggleDevice(switch, hass)])

descriptions = load_yaml_config_file(
path.join(path.dirname(__file__), 'services.yaml'))

hass.services.register(DOMAIN, SERVICE_SET_SIREN_TONE,
service_handle,
descriptions.get(SERVICE_SET_SIREN_TONE),
schema=SET_SIREN_TONE_SCHEMA)

hass.services.register(DOMAIN, SERVICE_ENABLE_CHIME,
service_handle,
descriptions.get(SERVICE_ENABLE_CHIME),
schema=SET_CHIME_MODE_SCHEMA)

hass.services.register(DOMAIN, SERVICE_SET_SIREN_VOLUME,
service_handle,
descriptions.get(SERVICE_SET_SIREN_VOLUME),
schema=SET_VOLUME_SCHEMA)

hass.services.register(DOMAIN, SERVICE_SET_CHIME_VOLUME,
service_handle,
descriptions.get(SERVICE_SET_CHIME_VOLUME),
schema=SET_VOLUME_SCHEMA)

hass.services.register(DOMAIN, SERVICE_SET_SIREN_STROBE_ENABLED,
service_handle,
descriptions.get(SERVICE_SET_SIREN_STROBE_ENABLED),
schema=SET_STROBE_ENABLED_SCHEMA)

hass.services.register(DOMAIN, SERVICE_SET_CHIME_STROBE_ENABLED,
service_handle,
descriptions.get(SERVICE_SET_CHIME_STROBE_ENABLED),
schema=SET_STROBE_ENABLED_SCHEMA)

hass.services.register(DOMAIN, SERVICE_SET_SIREN_AUTO_SHUTOFF,
service_handle,
descriptions.get(SERVICE_SET_SIREN_AUTO_SHUTOFF),
schema=SET_AUTO_SHUTOFF_SCHEMA)


class WinkToggleDevice(WinkDevice, ToggleEntity):
"""Representation of a Wink toggle device."""
Expand Down Expand Up @@ -201,60 +69,3 @@ def device_state_attributes(self):
except AttributeError:
pass
return attributes


class WinkSirenDevice(WinkDevice, ToggleEntity):
"""Representation of a Wink siren device."""

@asyncio.coroutine
def async_added_to_hass(self):
"""Callback when entity is added to hass."""
self.hass.data[DOMAIN]['entities']['switch'].append(self)

@property
def is_on(self):
"""Return true if device is on."""
return self.wink.state()

def turn_on(self, **kwargs):
"""Turn the device on."""
self.wink.set_state(True)

def turn_off(self):
"""Turn the device off."""
self.wink.set_state(False)

@property
def device_state_attributes(self):
"""Return the state attributes."""
attributes = super(WinkSirenDevice, self).device_state_attributes

auto_shutoff = self.wink.auto_shutoff()
if auto_shutoff is not None:
attributes["auto_shutoff"] = auto_shutoff

siren_volume = self.wink.siren_volume()
if siren_volume is not None:
attributes["siren_volume"] = siren_volume

chime_volume = self.wink.chime_volume()
if chime_volume is not None:
attributes["chime_volume"] = chime_volume

strobe_enabled = self.wink.strobe_enabled()
if strobe_enabled is not None:
attributes["siren_strobe_enabled"] = strobe_enabled

chime_strobe_enabled = self.wink.chime_strobe_enabled()
if chime_strobe_enabled is not None:
attributes["chime_strobe_enabled"] = chime_strobe_enabled

siren_sound = self.wink.siren_sound()
if siren_sound is not None:
attributes["siren_sound"] = siren_sound

chime_mode = self.wink.chime_mode()
if chime_mode is not None:
attributes["chime_mode"] = chime_mode

return attributes
Loading

0 comments on commit 41c2bdb

Please sign in to comment.