deCONZ - Add support for sirens (#15896)
* Add support for sirenes * Too quick... * Fix test * Use siren instead of sirene
This commit is contained in:
parent
a0e9f9f218
commit
81604a9326
3 changed files with 55 additions and 10 deletions
|
@ -15,4 +15,6 @@ CONF_ALLOW_DECONZ_GROUPS = 'allow_deconz_groups'
|
|||
ATTR_DARK = 'dark'
|
||||
ATTR_ON = 'on'
|
||||
|
||||
SWITCH_TYPES = ["On/Off plug-in unit", "Smart plug"]
|
||||
POWER_PLUGS = ["On/Off plug-in unit", "Smart plug"]
|
||||
SIRENS = ["Warning device"]
|
||||
SWITCH_TYPES = POWER_PLUGS + SIRENS
|
||||
|
|
|
@ -5,7 +5,8 @@ For more details about this platform, please refer to the documentation at
|
|||
https://home-assistant.io/components/switch.deconz/
|
||||
"""
|
||||
from homeassistant.components.deconz.const import (
|
||||
DOMAIN as DATA_DECONZ, DATA_DECONZ_ID, DATA_DECONZ_UNSUB, SWITCH_TYPES)
|
||||
DOMAIN as DATA_DECONZ, DATA_DECONZ_ID, DATA_DECONZ_UNSUB,
|
||||
POWER_PLUGS, SIRENS)
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
@ -29,8 +30,10 @@ async def async_setup_entry(hass, config_entry, async_add_devices):
|
|||
"""Add switch from deCONZ."""
|
||||
entities = []
|
||||
for light in lights:
|
||||
if light.type in SWITCH_TYPES:
|
||||
entities.append(DeconzSwitch(light))
|
||||
if light.type in POWER_PLUGS:
|
||||
entities.append(DeconzPowerPlug(light))
|
||||
elif light.type in SIRENS:
|
||||
entities.append(DeconzSiren(light))
|
||||
async_add_devices(entities, True)
|
||||
|
||||
hass.data[DATA_DECONZ_UNSUB].append(
|
||||
|
@ -56,11 +59,6 @@ class DeconzSwitch(SwitchDevice):
|
|||
"""Update the switch's state."""
|
||||
self.async_schedule_update_ha_state()
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if switch is on."""
|
||||
return self._switch.state
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
"""Return the name of the switch."""
|
||||
|
@ -71,6 +69,25 @@ class DeconzSwitch(SwitchDevice):
|
|||
"""Return a unique identifier for this switch."""
|
||||
return self._switch.uniqueid
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Return True if light is available."""
|
||||
return self._switch.reachable
|
||||
|
||||
@property
|
||||
def should_poll(self):
|
||||
"""No polling needed."""
|
||||
return False
|
||||
|
||||
|
||||
class DeconzPowerPlug(DeconzSwitch):
|
||||
"""Representation of power plugs from deCONZ."""
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if switch is on."""
|
||||
return self._switch.state
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn on switch."""
|
||||
data = {'on': True}
|
||||
|
@ -80,3 +97,22 @@ class DeconzSwitch(SwitchDevice):
|
|||
"""Turn off switch."""
|
||||
data = {'on': False}
|
||||
await self._switch.async_set_state(data)
|
||||
|
||||
|
||||
class DeconzSiren(DeconzSwitch):
|
||||
"""Representation of sirens from deCONZ."""
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if switch is on."""
|
||||
return self._switch.alert == 'lselect'
|
||||
|
||||
async def async_turn_on(self, **kwargs):
|
||||
"""Turn on switch."""
|
||||
data = {'alert': 'lselect'}
|
||||
await self._switch.async_set_state(data)
|
||||
|
||||
async def async_turn_off(self, **kwargs):
|
||||
"""Turn off switch."""
|
||||
data = {'alert': 'none'}
|
||||
await self._switch.async_set_state(data)
|
||||
|
|
|
@ -20,6 +20,12 @@ SUPPORTED_SWITCHES = {
|
|||
"name": "Switch 2 name",
|
||||
"type": "Smart plug",
|
||||
"state": {}
|
||||
},
|
||||
"3": {
|
||||
"id": "Switch 3 id",
|
||||
"name": "Switch 3 name",
|
||||
"type": "Warning device",
|
||||
"state": {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,8 +73,9 @@ async def test_switch(hass):
|
|||
await setup_bridge(hass, {"lights": SUPPORTED_SWITCHES})
|
||||
assert "switch.switch_1_name" in hass.data[deconz.DATA_DECONZ_ID]
|
||||
assert "switch.switch_2_name" in hass.data[deconz.DATA_DECONZ_ID]
|
||||
assert "switch.switch_3_name" in hass.data[deconz.DATA_DECONZ_ID]
|
||||
assert len(SUPPORTED_SWITCHES) == len(SWITCH_TYPES)
|
||||
assert len(hass.states.async_all()) == 3
|
||||
assert len(hass.states.async_all()) == 4
|
||||
|
||||
|
||||
async def test_add_new_switch(hass):
|
||||
|
|
Loading…
Add table
Reference in a new issue