Refactor zwave discovery to entity schema (#6445)
* Refactor zwave discovery to entity schema * Address PR concerns * Split DISCOVERY_SCHEMAS into separate file * Only check cover reverse workaround once
This commit is contained in:
parent
55d60a6a13
commit
56abc7f9b4
11 changed files with 658 additions and 565 deletions
|
@ -15,29 +15,30 @@ from homeassistant.components.zwave import workaround, async_setup_platform # n
|
|||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_device(value, **kwargs):
|
||||
def get_device(values, **kwargs):
|
||||
"""Create zwave entity device."""
|
||||
return ZwaveSwitch(value)
|
||||
return ZwaveSwitch(values)
|
||||
|
||||
|
||||
class ZwaveSwitch(zwave.ZWaveDeviceEntity, SwitchDevice):
|
||||
"""Representation of a Z-Wave switch."""
|
||||
|
||||
def __init__(self, value):
|
||||
def __init__(self, values):
|
||||
"""Initialize the Z-Wave switch device."""
|
||||
zwave.ZWaveDeviceEntity.__init__(self, value, DOMAIN)
|
||||
self.refresh_on_update = (workaround.get_device_mapping(value) ==
|
||||
workaround.WORKAROUND_REFRESH_NODE_ON_UPDATE)
|
||||
zwave.ZWaveDeviceEntity.__init__(self, values, DOMAIN)
|
||||
self.refresh_on_update = (
|
||||
workaround.get_device_mapping(values.primary) ==
|
||||
workaround.WORKAROUND_REFRESH_NODE_ON_UPDATE)
|
||||
self.last_update = time.perf_counter()
|
||||
self._state = self._value.data
|
||||
self._state = self.values.primary.data
|
||||
|
||||
def update_properties(self):
|
||||
"""Callback on data changes for node values."""
|
||||
self._state = self._value.data
|
||||
self._state = self.values.primary.data
|
||||
if self.refresh_on_update and \
|
||||
time.perf_counter() - self.last_update > 30:
|
||||
self.last_update = time.perf_counter()
|
||||
self._value.node.request_state()
|
||||
self.node.request_state()
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
|
@ -46,8 +47,8 @@ class ZwaveSwitch(zwave.ZWaveDeviceEntity, SwitchDevice):
|
|||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the device on."""
|
||||
self._value.node.set_switch(self._value.value_id, True)
|
||||
self.node.set_switch(self.values.primary.value_id, True)
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn the device off."""
|
||||
self._value.node.set_switch(self._value.value_id, False)
|
||||
self.node.set_switch(self.values.primary.value_id, False)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue