Implemented the new zwavejs2mqtt features for adding and removing nodes

This commit is contained in:
Fabio Manganiello 2022-10-14 23:28:02 +02:00
parent 5995d045e1
commit 7f575bacaa
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774
4 changed files with 560 additions and 150 deletions

View file

@ -0,0 +1,65 @@
<template>
<Modal ref="modal" :title="title">
<div class="dialog-content">
<slot />
</div>
<div class="buttons">
<button type="button" class="cancel-btn" @click="close" @touch="close">
<i class="fas fa-xmark" /> &nbsp; Close
</button>
</div>
</Modal>
</template>
<script>
import Modal from "@/components/Modal";
export default {
emits: ['input', 'click', 'touch'],
components: {Modal},
props: {
title: {
type: String,
},
},
methods: {
show() {
this.$refs.modal.show()
},
close() {
this.$refs.modal.hide()
},
},
}
</script>
<style lang="scss" scoped>
:deep(.modal) {
.dialog-content {
padding: 1em;
}
.buttons {
display: flex;
flex-direction: row;
justify-content: right;
padding: 1em 0 1em 1em;
border: 0;
border-radius: 0;
box-shadow: 0 -1px $default-shadow-color;
button {
padding: 0.5em 1em;
border: 1px solid $border-color-2;
border-radius: 1em;
&:hover {
background: $hover-bg;
}
}
}
}
</style>

View file

@ -53,6 +53,31 @@
</div> </div>
</Modal> </Modal>
<Alert title="" ref="noNodeNameModal">
No node name specified
</Alert>
<Modal title="Add new node" ref="addNodeModal">
<div class="node-add">
<div class="body">
<form class="add-node-form" ref="addNodeForm" @submit.prevent="addNode()">
<div class="fields">
<input type="text" name="name" placeholder="Node name">
<input type="text" name="location" placeholder="Node location (optional)">
<input type="number" name="timeout" value="30" placeholder="Timeout (in seconds)">
</div>
<div class="buttons">
<input type="submit" class="btn btn-primary" value="OK" :disabled="commandRunning">
<button class="btn btn-default" @click.prevent="closeAddNodeModal()">
Cancel
</button>
</div>
</form>
</div>
</div>
</Modal>
<div class="view-options"> <div class="view-options">
<div class="view-selector col-s-6 col-m-8 col-l-9"> <div class="view-selector col-s-6 col-m-8 col-l-9">
<label> <label>
@ -73,7 +98,8 @@
<DropdownItem text="Network Info" :disabled="commandRunning" @click="networkInfoModalOpen" /> <DropdownItem text="Network Info" :disabled="commandRunning" @click="networkInfoModalOpen" />
<DropdownItem text="Start Network" :disabled="commandRunning" @click="startNetwork" /> <DropdownItem text="Start Network" :disabled="commandRunning" @click="startNetwork" />
<DropdownItem text="Stop Network" :disabled="commandRunning" @click="stopNetwork" /> <DropdownItem text="Stop Network" :disabled="commandRunning" @click="stopNetwork" />
<DropdownItem text="Add Node" :disabled="commandRunning" @click="addNode" v-if="selected.view === 'nodes'" /> <DropdownItem text="Add Node" :disabled="commandRunning"
@click="openAddNodeModal()" v-if="selected.view === 'nodes'" />
<DropdownItem text="Remove Node" :disabled="commandRunning" @click="removeNode" <DropdownItem text="Remove Node" :disabled="commandRunning" @click="removeNode"
v-if="selected.view === 'nodes'" /> v-if="selected.view === 'nodes'" />
<DropdownItem text="Switch All On" :disabled="commandRunning" @click="switchAll(true)" /> <DropdownItem text="Switch All On" :disabled="commandRunning" @click="switchAll(true)" />
@ -224,6 +250,7 @@
import Group from "@/components/panels/Zwave/Group"; import Group from "@/components/panels/Zwave/Group";
import Node from "@/components/panels/Zwave/Node"; import Node from "@/components/panels/Zwave/Node";
import Modal from "@/components/Modal"; import Modal from "@/components/Modal";
import Alert from "@/components/elements/Alert";
import Dropdown from "@/components/elements/Dropdown"; import Dropdown from "@/components/elements/Dropdown";
import DropdownItem from "@/components/elements/DropdownItem"; import DropdownItem from "@/components/elements/DropdownItem";
import Loading from "@/components/Loading"; import Loading from "@/components/Loading";
@ -233,8 +260,18 @@ import mixin from "@/components/panels/Zwave/mixin";
export default { export default {
name: "Zwave", name: "Zwave",
components: {Value, ToggleSwitch, Loading, DropdownItem, Dropdown, Modal, Group, Node},
mixins: [mixin], mixins: [mixin],
components: {
Alert,
Dropdown,
DropdownItem,
Group,
Loading,
Modal,
Node,
ToggleSwitch,
Value,
},
data() { data() {
return { return {
@ -438,10 +475,44 @@ export default {
} }
}, },
resetAddNodeModal() {
[...this.$refs.addNodeModal.$el.querySelectorAll('.fields input')].forEach(
(el) => { el.value = (el.attributes.name.value === 'timeout') ? 30 : '' }
)
},
openAddNodeModal() {
this.resetAddNodeModal()
this.$refs.addNodeModal.show()
},
closeAddNodeModal() {
this.resetAddNodeModal()
this.$refs.addNodeModal.close()
},
async addNode() { async addNode() {
const form = this.$refs.addNodeForm
const name = form.querySelector('input[name=name]').value?.trim()
const location = form.querySelector('input[name=location]').value?.trim()
const timeout = parseInt(
form.querySelector('input[name=location]').value?.trim() || 30
)
if (!name?.length) {
this.$refs.noNodeNameModal.show()
return
}
this.commandRunning = true this.commandRunning = true
try { try {
await this.zrequest('add_node') await this.zrequest('add_node', {
name: name,
location: location,
timeout: timeout,
})
this.closeAddNodeModal()
} finally { } finally {
this.commandRunning = false this.commandRunning = false
} }
@ -739,5 +810,22 @@ export default {
.network-info { .network-info {
margin: -1em; margin: -1em;
} }
.add-node-form, .fields {
display: flex;
flex-direction: column;
justify-content: center;
input {
margin: 0.5em;
}
.buttons {
box-shadow: 0 -1px $default-shadow-color;
margin-top: 0.75em;
padding-top: 0.75em;
justify-content: right;
}
}
} }
</style> </style>

View file

@ -33,6 +33,7 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
if not backend.network: if not backend.network:
backend.start_network() backend.start_network()
assert backend.network
return backend.network return backend.network
@classmethod @classmethod
@ -67,7 +68,7 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
} }
@action @action
def add_node(self, do_security=False): def add_node(self, do_security=False, **_):
""" """
Start the inclusion process to add a node to the network. Start the inclusion process to add a node to the network.
@ -77,7 +78,7 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
controller.add_node(do_security) controller.add_node(do_security)
@action @action
def remove_node(self): def remove_node(self, **_):
""" """
Remove a node from the network. Remove a node from the network.
""" """
@ -86,7 +87,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
self.write_config() self.write_config()
@action @action
def remove_failed_node(self, node_id: Optional[int] = None, node_name: Optional[str] = None): def remove_failed_node(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
):
""" """
Remove a failed node from the network. Remove a failed node from the network.
@ -99,7 +102,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
self.write_config() self.write_config()
@action @action
def replace_failed_node(self, node_id: Optional[int] = None, node_name: Optional[str] = None): def replace_failed_node(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
):
""" """
Replace a failed node on the network. Replace a failed node on the network.
@ -112,7 +117,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
self.write_config() self.write_config()
@action @action
def replication_send(self, node_id: Optional[int] = None, node_name: Optional[str] = None): def replication_send(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
):
""" """
Send node information from the primary to the secondary controller. Send node information from the primary to the secondary controller.
@ -124,7 +131,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
controller.replication_send(node.node_id) controller.replication_send(node.node_id)
@action @action
def request_network_update(self, node_id: Optional[int] = None, node_name: Optional[str] = None): def request_network_update(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
):
""" """
Request a network update to a node. Request a network update to a node.
@ -136,7 +145,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
controller.request_network_update(node.node_id) controller.request_network_update(node.node_id)
@action @action
def request_node_neighbour_update(self, node_id: Optional[int] = None, node_name: Optional[str] = None): def request_node_neighbour_update(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
):
""" """
Request a neighbours list update to a node. Request a neighbours list update to a node.
@ -154,15 +165,22 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
return { return {
'command_class': value.node.get_command_class_as_string(value.command_class) 'command_class': value.node.get_command_class_as_string(value.command_class)
if value.command_class else None, if value.command_class
else None,
'data': value.data, 'data': value.data,
'data_as_string': value.data_as_string, 'data_as_string': value.data_as_string,
'data_items': list(value.data_items) if isinstance(value.data_items, set) else value.data_items, 'data_items': list(value.data_items)
if isinstance(value.data_items, set)
else value.data_items,
'genre': value.genre, 'genre': value.genre,
'help': value.help, 'help': value.help,
'home_id': value.home_id, 'home_id': value.home_id,
'id_on_network': value.id_on_network if value.parent_id is not None and value.command_class is not None 'id_on_network': value.id_on_network
and value.instance is not None and value.index is not None else None, if value.parent_id is not None
and value.command_class is not None
and value.instance is not None
and value.index is not None
else None,
'index': value.index, 'index': value.index,
'instance': value.instance, 'instance': value.instance,
'is_polled': value.is_polled, 'is_polled': value.is_polled,
@ -206,8 +224,13 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
'node_id': node.node_id, 'node_id': node.node_id,
'home_id': node.home_id, 'home_id': node.home_id,
'capabilities': list(node.capabilities), 'capabilities': list(node.capabilities),
'command_classes': [node.get_command_class_as_string(cc) for cc in node.command_classes if cc] 'command_classes': [
if hasattr(node, 'command_classes') else [], node.get_command_class_as_string(cc)
for cc in node.command_classes
if cc
]
if hasattr(node, 'command_classes')
else [],
'device_type': node.device_type if hasattr(node, 'device_type') else '', 'device_type': node.device_type if hasattr(node, 'device_type') else '',
'groups': { 'groups': {
group_id: cls.group_to_dict(group) group_id: cls.group_to_dict(group)
@ -215,27 +238,50 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
}, },
'is_awake': node.is_awake if hasattr(node, 'is_awake') else False, 'is_awake': node.is_awake if hasattr(node, 'is_awake') else False,
'is_failed': node.is_failed if hasattr(node, 'is_failed') else False, 'is_failed': node.is_failed if hasattr(node, 'is_failed') else False,
'is_beaming_device': node.is_beaming_device if hasattr(node, 'is_beaming_device') else False, 'is_beaming_device': node.is_beaming_device
if hasattr(node, 'is_beaming_device')
else False,
'is_frequent_listening_device': node.is_frequent_listening_device 'is_frequent_listening_device': node.is_frequent_listening_device
if hasattr(node, 'is_frequent_listening_device') else False, if hasattr(node, 'is_frequent_listening_device')
'is_info_received': node.is_info_received if hasattr(node, 'is_info_received') else False, else False,
'is_listening_device': node.is_listening_device if hasattr(node, 'is_listening_device') else False, 'is_info_received': node.is_info_received
if hasattr(node, 'is_info_received')
else False,
'is_listening_device': node.is_listening_device
if hasattr(node, 'is_listening_device')
else False,
'is_locked': node.is_locked if hasattr(node, 'is_locked') else False, 'is_locked': node.is_locked if hasattr(node, 'is_locked') else False,
'is_ready': node.is_ready if hasattr(node, 'is_ready') else False, 'is_ready': node.is_ready if hasattr(node, 'is_ready') else False,
'is_routing_device': node.is_routing_device if hasattr(node, 'is_routing_device') else False, 'is_routing_device': node.is_routing_device
'is_security_device': node.is_security_device if hasattr(node, 'is_security_device') else False, if hasattr(node, 'is_routing_device')
else False,
'is_security_device': node.is_security_device
if hasattr(node, 'is_security_device')
else False,
'is_sleeping': node.is_sleeping if hasattr(node, 'is_sleeping') else False, 'is_sleeping': node.is_sleeping if hasattr(node, 'is_sleeping') else False,
'last_update': node.last_update if hasattr(node, 'last_update') else None, 'last_update': node.last_update if hasattr(node, 'last_update') else None,
'location': node.location if hasattr(node, 'location') else None, 'location': node.location if hasattr(node, 'location') else None,
'manufacturer_id': node.manufacturer_id if hasattr(node, 'manufacturer_id') else None, 'manufacturer_id': node.manufacturer_id
'manufacturer_name': node.manufacturer_name if hasattr(node, 'manufacturer_name') else None, if hasattr(node, 'manufacturer_id')
'max_baud_rate': node.max_baud_rate if hasattr(node, 'max_baud_rate') else None, else None,
'neighbours': [node_id for node_id in node.neighbors] if hasattr(node, 'neighbours') else [], 'manufacturer_name': node.manufacturer_name
if hasattr(node, 'manufacturer_name')
else None,
'max_baud_rate': node.max_baud_rate
if hasattr(node, 'max_baud_rate')
else None,
'neighbours': list(node.neighbors or [])
if hasattr(node, 'neighbours')
else [],
'name': node.name if hasattr(node, 'name') else None, 'name': node.name if hasattr(node, 'name') else None,
'outdated': node.outdated if hasattr(node, 'outdated') else False, 'outdated': node.outdated if hasattr(node, 'outdated') else False,
'product_id': node.product_id if hasattr(node, 'product_id') else None, 'product_id': node.product_id if hasattr(node, 'product_id') else None,
'product_name': node.product_name if hasattr(node, 'product_name') else None, 'product_name': node.product_name
'product_type': node.product_type if hasattr(node, 'product_type') else None, if hasattr(node, 'product_name')
else None,
'product_type': node.product_type
if hasattr(node, 'product_type')
else None,
'query_stage': node.query_stage if hasattr(node, 'query_stage') else None, 'query_stage': node.query_stage if hasattr(node, 'query_stage') else None,
'role': node.role if hasattr(node, 'role') else None, 'role': node.role if hasattr(node, 'role') else None,
'security': node.security if hasattr(node, 'security') else None, 'security': node.security if hasattr(node, 'security') else None,
@ -245,19 +291,23 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
'version': node.version if hasattr(node, 'version') else None, 'version': node.version if hasattr(node, 'version') else None,
'values': { 'values': {
value.id_on_network: cls.value_to_dict(value) value.id_on_network: cls.value_to_dict(value)
for value_id, value in (node.values or {}).items() for _, value in (node.values or {}).items()
if value.index is not None if value.index is not None
and value.instance is not None and value.instance is not None
and value.command_class and value.command_class
and value.parent_id is not None and value.parent_id is not None
and value._network and value._network
and value._network.home_id is not None and value._network.home_id is not None
} if hasattr(node, 'values') else {}, }
if hasattr(node, 'values')
else {},
} }
def _get_node(self, node_id: Optional[int] = None, node_name: Optional[str] = None): def _get_node(self, node_id: Optional[int] = None, node_name: Optional[str] = None):
assert node_id is not None or node_name is not None, 'Specify either node_id or name' assert (
nodes = self._get_backend().network.nodes node_id is not None or node_name is not None
), 'Specify either node_id or name'
nodes = self._get_network().nodes
if node_id is not None: if node_id is not None:
assert node_id in nodes, 'No such node_id: {}'.format(node_id) assert node_id in nodes, 'No such node_id: {}'.format(node_id)
@ -270,12 +320,16 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
def _get_groups(self) -> dict: def _get_groups(self) -> dict:
return { return {
group_index: group group_index: group
for node in self._get_backend().network.nodes.values() for node in self._get_network().nodes.values()
for group_index, group in node.groups.items() for group_index, group in node.groups.items()
} }
def _get_group(self, group_index: Optional[int] = None, group_label: Optional[str] = None): def _get_group(
assert group_index is not None or group_label is not None, 'Specify either group_index or label' self, group_index: Optional[int] = None, group_label: Optional[str] = None
):
assert (
group_index is not None or group_label is not None
), 'Specify either group_index or label'
groups = self._get_groups() groups = self._get_groups()
if group_index is not None: if group_index is not None:
@ -286,9 +340,13 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
assert groups, 'No such group label: {}'.format(group_label) assert groups, 'No such group label: {}'.format(group_label)
return groups[0] return groups[0]
def _get_scene(self, scene_id: Optional[int] = None, scene_label: Optional[str] = None): def _get_scene(
assert scene_id is not None or scene_label is not None, 'Specify either scene_id or label' self, scene_id: Optional[int] = None, scene_label: Optional[str] = None
scenes = self._get_backend().network.get_scenes() ):
assert (
scene_id is not None or scene_label is not None
), 'Specify either scene_id or label'
scenes = self._get_network().get_scenes()
if scene_id is not None: if scene_id is not None:
assert scene_id in scenes, 'No such scene_id: {}'.format(scene_id) assert scene_id in scenes, 'No such scene_id: {}'.format(scene_id)
@ -299,7 +357,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
return scenes[0] return scenes[0]
@action @action
def get_nodes(self, node_id: Optional[int] = None, node_name: Optional[str] = None) -> Dict[str, Any]: def get_nodes(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
) -> Dict[str, Any]:
""" """
Get the nodes associated to the network. Get the nodes associated to the network.
@ -307,15 +367,19 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
:param node_name: Filter by node name. :param node_name: Filter by node name.
""" """
if node_id is not None or node_name is not None: if node_id is not None or node_name is not None:
return self.node_to_dict(self._get_node(node_id=node_id, node_name=node_name)) return self.node_to_dict(
self._get_node(node_id=node_id, node_name=node_name)
)
return { return {
node_id: self.node_to_dict(node) node_id: self.node_to_dict(node)
for node_id, node in self._get_backend().network.nodes.items() for node_id, node in self._get_network().nodes.items()
} }
@action @action
def get_node_stats(self, node_id: Optional[int] = None, node_name: Optional[str] = None) -> Dict[str, Any]: def get_node_stats(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
) -> Dict[str, Any]:
""" """
Get the statistics of a node on the network. Get the statistics of a node on the network.
@ -326,7 +390,12 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
return node.stats return node.stats
@action @action
def set_node_name(self, new_name: str, node_id: Optional[int] = None, node_name: Optional[str] = None): def set_node_name(
self,
new_name: str,
node_id: Optional[int] = None,
node_name: Optional[str] = None,
):
""" """
Rename a node on the network. Rename a node on the network.
@ -339,7 +408,12 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
self.write_config() self.write_config()
@action @action
def set_node_product_name(self, product_name: str, node_id: Optional[int] = None, node_name: Optional[str] = None): def set_node_product_name(
self,
product_name: str,
node_id: Optional[int] = None,
node_name: Optional[str] = None,
):
""" """
Set the product name of a node. Set the product name of a node.
@ -352,8 +426,12 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
self.write_config() self.write_config()
@action @action
def set_node_manufacturer_name(self, manufacturer_name: str, node_id: Optional[int] = None, def set_node_manufacturer_name(
node_name: Optional[str] = None): self,
manufacturer_name: str,
node_id: Optional[int] = None,
node_name: Optional[str] = None,
):
""" """
Set the manufacturer name of a node. Set the manufacturer name of a node.
@ -366,7 +444,12 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
self.write_config() self.write_config()
@action @action
def set_node_location(self, location: str, node_id: Optional[int] = None, node_name: Optional[str] = None): def set_node_location(
self,
location: str,
node_id: Optional[int] = None,
node_name: Optional[str] = None,
):
""" """
Set the location of a node. Set the location of a node.
@ -451,19 +534,27 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
""" """
self._get_network().test(count) self._get_network().test(count)
def _get_value(self, value_id: Optional[int] = None, id_on_network: Optional[str] = None, def _get_value(
node_id: Optional[int] = None, node_name: Optional[str] = None, value_label: Optional[str] = None): self,
assert (value_id is not None or id_on_network is not None) or \ value_id: Optional[int] = None,
((node_id is not None or node_name is not None) and value_label is not None), \ id_on_network: Optional[str] = None,
'Specify either value_id, id_on_network, or [node_id/node_name, value_label]' node_id: Optional[int] = None,
node_name: Optional[str] = None,
value_label: Optional[str] = None,
):
assert (value_id is not None or id_on_network is not None) or (
(node_id is not None or node_name is not None) and value_label is not None
), 'Specify either value_id, id_on_network, or [node_id/node_name, value_label]'
if value_id is not None: if value_id is not None:
return self._get_network().get_value(value_id) return self._get_network().get_value(value_id)
if id_on_network is not None: if id_on_network is not None:
values = [value values = [
value
for node in self._get_network().nodes.values() for node in self._get_network().nodes.values()
for value in node.values.values() for value in node.values.values()
if value.id_on_network == id_on_network] if value.id_on_network == id_on_network
]
assert values, 'No such value ID: {}'.format(id_on_network) assert values, 'No such value ID: {}'.format(id_on_network)
return values[0] return values[0]
@ -474,9 +565,14 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
return values[0] return values[0]
@action @action
def get_value(self, value_id: Optional[int] = None, id_on_network: Optional[str] = None, def get_value(
value_label: Optional[str] = None, node_id: Optional[int] = None, node_name: Optional[str] = None) \ self,
-> Dict[str, Any]: value_id: Optional[int] = None,
id_on_network: Optional[str] = None,
value_label: Optional[str] = None,
node_id: Optional[int] = None,
node_name: Optional[str] = None,
) -> Dict[str, Any]:
""" """
Get a value on the network. Get a value on the network.
@ -486,12 +582,24 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
:param node_id: Select value by [node_id/node_name, value_label] :param node_id: Select value by [node_id/node_name, value_label]
:param node_name: Select value by [node_id/node_name, value_label] :param node_name: Select value by [node_id/node_name, value_label]
""" """
return self._get_value(value_id=value_id, id_on_network=id_on_network, return self._get_value(
node_id=node_id, node_name=node_name, value_label=value_label).to_dict() value_id=value_id,
id_on_network=id_on_network,
node_id=node_id,
node_name=node_name,
value_label=value_label,
).to_dict()
@action @action
def set_value(self, data, value_id: Optional[int] = None, id_on_network: Optional[str] = None, def set_value(
value_label: Optional[str] = None, node_id: Optional[int] = None, node_name: Optional[str] = None): self,
data,
value_id: Optional[int] = None,
id_on_network: Optional[str] = None,
value_label: Optional[str] = None,
node_id: Optional[int] = None,
node_name: Optional[str] = None,
):
""" """
Set a value. Set a value.
@ -503,8 +611,14 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
:param node_name: Select value by [node_id/node_name, value_label] :param node_name: Select value by [node_id/node_name, value_label]
""" """
from openzwave.node import ZWaveNode from openzwave.node import ZWaveNode
value = self._get_value(value_id=value_id, id_on_network=id_on_network,
node_id=node_id, node_name=node_name, value_label=value_label) value = self._get_value(
value_id=value_id,
id_on_network=id_on_network,
node_id=node_id,
node_name=node_name,
value_label=value_label,
)
new_val = value.check_data(data) new_val = value.check_data(data)
assert new_val is not None, 'Invalid value passed to the property' assert new_val is not None, 'Invalid value passed to the property'
node: ZWaveNode = self._get_network().nodes[value.node.node_id] node: ZWaveNode = self._get_network().nodes[value.node.node_id]
@ -512,9 +626,15 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
self.write_config() self.write_config()
@action @action
def set_value_label(self, new_label: str, value_id: Optional[int] = None, id_on_network: Optional[str] = None, def set_value_label(
value_label: Optional[str] = None, node_id: Optional[int] = None, self,
node_name: Optional[str] = None): new_label: str,
value_id: Optional[int] = None,
id_on_network: Optional[str] = None,
value_label: Optional[str] = None,
node_id: Optional[int] = None,
node_name: Optional[str] = None,
):
""" """
Change the label/name of a value. Change the label/name of a value.
@ -525,15 +645,25 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
:param node_id: Select value by [node_id/node_name, value_label] :param node_id: Select value by [node_id/node_name, value_label]
:param node_name: Select value by [node_id/node_name, value_label] :param node_name: Select value by [node_id/node_name, value_label]
""" """
value = self._get_value(value_id=value_id, id_on_network=id_on_network, value = self._get_value(
node_id=node_id, node_name=node_name, value_label=value_label) value_id=value_id,
id_on_network=id_on_network,
node_id=node_id,
node_name=node_name,
value_label=value_label,
)
value.label = new_label value.label = new_label
self.write_config() self.write_config()
@action @action
def node_add_value(self, value_id: Optional[int] = None, id_on_network: Optional[str] = None, def node_add_value(
value_label: Optional[str] = None, node_id: Optional[int] = None, self,
node_name: Optional[str] = None): value_id: Optional[int] = None,
id_on_network: Optional[str] = None,
value_label: Optional[str] = None,
node_id: Optional[int] = None,
node_name: Optional[str] = None,
):
""" """
Add a value to a node. Add a value to a node.
@ -544,15 +674,24 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
:param node_name: Select node by label. :param node_name: Select node by label.
""" """
node = self._get_node(node_id=node_id, node_name=node_name) node = self._get_node(node_id=node_id, node_name=node_name)
value = self._get_value(value_id=value_id, id_on_network=id_on_network, node_id=node.node_id, value = self._get_value(
value_label=value_label) value_id=value_id,
id_on_network=id_on_network,
node_id=node.node_id,
value_label=value_label,
)
node.add_value(value.value_id) node.add_value(value.value_id)
self.write_config() self.write_config()
@action @action
def node_remove_value(self, value_id: Optional[int] = None, id_on_network: Optional[str] = None, def node_remove_value(
value_label: Optional[str] = None, node_id: Optional[int] = None, self,
node_name: Optional[str] = None): value_id: Optional[int] = None,
id_on_network: Optional[str] = None,
value_label: Optional[str] = None,
node_id: Optional[int] = None,
node_name: Optional[str] = None,
):
""" """
Remove a value from a node. Remove a value from a node.
@ -563,13 +702,22 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
:param node_name: Select node by label. :param node_name: Select node by label.
""" """
node = self._get_node(node_id=node_id, node_name=node_name) node = self._get_node(node_id=node_id, node_name=node_name)
value = self._get_value(value_id=value_id, id_on_network=id_on_network, node_id=node.node_id, value = self._get_value(
value_label=value_label) value_id=value_id,
id_on_network=id_on_network,
node_id=node.node_id,
value_label=value_label,
)
node.remove_value(value.value_id) node.remove_value(value.value_id)
self.write_config() self.write_config()
@action @action
def node_heal(self, node_id: Optional[int] = None, node_name: Optional[str] = None, refresh_routes: bool = False): def node_heal(
self,
node_id: Optional[int] = None,
node_name: Optional[str] = None,
refresh_routes: bool = False,
):
""" """
Heal network node by requesting the node to rediscover their neighbours. Heal network node by requesting the node to rediscover their neighbours.
@ -581,7 +729,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
node.heal(refresh_routes) node.heal(refresh_routes)
@action @action
def node_update_neighbours(self, node_id: Optional[int] = None, node_name: Optional[str] = None): def node_update_neighbours(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
):
""" """
Ask a node to update its neighbours table. Ask a node to update its neighbours table.
@ -592,7 +742,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
node.neighbor_update() node.neighbor_update()
@action @action
def node_network_update(self, node_id: Optional[int] = None, node_name: Optional[str] = None): def node_network_update(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
):
""" """
Update the controller with network information. Update the controller with network information.
@ -603,7 +755,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
node.network_update() node.network_update()
@action @action
def node_refresh_info(self, node_id: Optional[int] = None, node_name: Optional[str] = None): def node_refresh_info(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
):
""" """
Fetch up-to-date information about the node. Fetch up-to-date information about the node.
@ -613,22 +767,29 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
node = self._get_node(node_id=node_id, node_name=node_name) node = self._get_node(node_id=node_id, node_name=node_name)
node.refresh_info() node.refresh_info()
def _get_values(self, item: str, node_id: Optional[int] = None, node_name: Optional[str] = None) -> Dict[int, Any]: def _get_values(
nodes = [self._get_node(node_id=node_id, node_name=node_name)] if node_id or node_name \ self, item: str, node_id: Optional[int] = None, node_name: Optional[str] = None
) -> Dict[int, Any]:
nodes = (
[self._get_node(node_id=node_id, node_name=node_name)]
if node_id or node_name
else self._get_network().nodes.values() else self._get_network().nodes.values()
)
return { return {
value.id_on_network: { value.id_on_network: {
'node_id': node.node_id, 'node_id': node.node_id,
'node_name': node.name, 'node_name': node.name,
**self.value_to_dict(value) **self.value_to_dict(value),
} }
for node in nodes for node in nodes
for value_id, value in getattr(node, 'get_' + item)().items() for value in getattr(node, 'get_' + item)().values()
} }
@action @action
def get_dimmers(self, node_id: Optional[int] = None, node_name: Optional[str] = None) -> Dict[int, Any]: def get_dimmers(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
) -> Dict[int, Any]:
""" """
Get the dimmers on the network or associated to a node. Get the dimmers on the network or associated to a node.
@ -638,7 +799,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
return self._get_values('dimmers', node_id=node_id, node_name=node_name) return self._get_values('dimmers', node_id=node_id, node_name=node_name)
@action @action
def get_node_config(self, node_id: Optional[int] = None, node_name: Optional[str] = None) -> Dict[int, Any]: def get_node_config(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
) -> Dict[int, Any]:
""" """
Get the configuration values of a node or of all the nodes on the network. Get the configuration values of a node or of all the nodes on the network.
@ -648,7 +811,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
return self._get_values('configs', node_id=node_id, node_name=node_name) return self._get_values('configs', node_id=node_id, node_name=node_name)
@action @action
def get_battery_levels(self, node_id: Optional[int] = None, node_name: Optional[str] = None) -> Dict[int, Any]: def get_battery_levels(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
) -> Dict[int, Any]:
""" """
Get the battery levels of a node or of all the nodes on the network. Get the battery levels of a node or of all the nodes on the network.
@ -658,7 +823,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
return self._get_values('battery_levels', node_id=node_id, node_name=node_name) return self._get_values('battery_levels', node_id=node_id, node_name=node_name)
@action @action
def get_power_levels(self, node_id: Optional[int] = None, node_name: Optional[str] = None) -> Dict[int, Any]: def get_power_levels(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
) -> Dict[int, Any]:
""" """
Get the power levels of this node. Get the power levels of this node.
@ -668,7 +835,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
return self._get_values('power_levels', node_id=node_id, node_name=node_name) return self._get_values('power_levels', node_id=node_id, node_name=node_name)
@action @action
def get_bulbs(self, node_id: Optional[int] = None, node_name: Optional[str] = None) -> Dict[int, Any]: def get_bulbs(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
) -> Dict[int, Any]:
""" """
Get the bulbs/LEDs on the network or associated to a node. Get the bulbs/LEDs on the network or associated to a node.
@ -678,7 +847,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
return self._get_values('rgbbulbs', node_id=node_id, node_name=node_name) return self._get_values('rgbbulbs', node_id=node_id, node_name=node_name)
@action @action
def get_switches(self, node_id: Optional[int] = None, node_name: Optional[str] = None) -> Dict[int, Any]: def get_switches(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
) -> Dict[int, Any]:
""" """
Get the switches on the network or associated to a node. Get the switches on the network or associated to a node.
@ -688,7 +859,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
return self._get_values('switches', node_id=node_id, node_name=node_name) return self._get_values('switches', node_id=node_id, node_name=node_name)
@action @action
def get_sensors(self, node_id: Optional[int] = None, node_name: Optional[str] = None) -> Dict[int, Any]: def get_sensors(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
) -> Dict[int, Any]:
""" """
Get the sensors on the network or associated to a node. Get the sensors on the network or associated to a node.
@ -698,7 +871,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
return self._get_values('sensors', node_id=node_id, node_name=node_name) return self._get_values('sensors', node_id=node_id, node_name=node_name)
@action @action
def get_doorlocks(self, node_id: Optional[int] = None, node_name: Optional[str] = None) -> Dict[int, Any]: def get_doorlocks(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
) -> Dict[int, Any]:
""" """
Get the doorlocks on the network or associated to a node. Get the doorlocks on the network or associated to a node.
@ -708,7 +883,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
return self._get_values('doorlocks', node_id=node_id, node_name=node_name) return self._get_values('doorlocks', node_id=node_id, node_name=node_name)
@action @action
def get_usercodes(self, node_id: Optional[int] = None, node_name: Optional[str] = None) -> Dict[int, Any]: def get_usercodes(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
) -> Dict[int, Any]:
""" """
Get the usercodes on the network or associated to a node. Get the usercodes on the network or associated to a node.
@ -718,7 +895,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
return self._get_values('usercodes', node_id=node_id, node_name=node_name) return self._get_values('usercodes', node_id=node_id, node_name=node_name)
@action @action
def get_thermostats(self, node_id: Optional[int] = None, node_name: Optional[str] = None) -> Dict[int, Any]: def get_thermostats(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
) -> Dict[int, Any]:
""" """
Get the thermostats on the network or associated to a node. Get the thermostats on the network or associated to a node.
@ -728,7 +907,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
return self._get_values('thermostats', node_id=node_id, node_name=node_name) return self._get_values('thermostats', node_id=node_id, node_name=node_name)
@action @action
def get_protections(self, node_id: Optional[int] = None, node_name: Optional[str] = None) -> Dict[int, Any]: def get_protections(
self, node_id: Optional[int] = None, node_name: Optional[str] = None
) -> Dict[int, Any]:
""" """
Get the protection-compatible devices on the network or associated to a node. Get the protection-compatible devices on the network or associated to a node.
@ -769,7 +950,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
self.write_config() self.write_config()
@action @action
def remove_scene(self, scene_id: Optional[int] = None, scene_label: Optional[str] = None): def remove_scene(
self, scene_id: Optional[int] = None, scene_label: Optional[str] = None
):
""" """
Remove a scene. Remove a scene.
@ -781,7 +964,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
self.write_config() self.write_config()
@action @action
def activate_scene(self, scene_id: Optional[int] = None, scene_label: Optional[str] = None): def activate_scene(
self, scene_id: Optional[int] = None, scene_label: Optional[str] = None
):
""" """
Activate a scene. Activate a scene.
@ -792,7 +977,12 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
scene.activate() scene.activate()
@action @action
def set_scene_label(self, new_label: str, scene_id: Optional[int] = None, scene_label: Optional[str] = None): def set_scene_label(
self,
new_label: str,
scene_id: Optional[int] = None,
scene_label: Optional[str] = None,
):
""" """
Rename a scene/set the scene label. Rename a scene/set the scene label.
@ -805,16 +995,23 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
self.write_config() self.write_config()
@action @action
def scene_add_value(self, data: Optional[Any] = None, def scene_add_value(
value_id: Optional[int] = None, id_on_network: Optional[str] = None, self,
value_label: Optional[str] = None, scene_id: Optional[int] = None, data: Optional[Any] = None,
scene_label: Optional[str] = None, node_id: Optional[int] = None, value_id: Optional[int] = None,
node_name: Optional[str] = None): id_on_network: Optional[str] = None,
value_label: Optional[str] = None,
scene_id: Optional[int] = None,
scene_label: Optional[str] = None,
node_id: Optional[int] = None,
node_name: Optional[str] = None,
):
""" """
Add a value to a scene. Add a value to a scene.
WARNING: This method actually doesn't work, by own admission of the WARNING: This method actually doesn't work, by own admission of the
`OpenZWave developer <https://github.com/OpenZWave/python-openzwave/blob/master/src-lib/libopenzwave/libopenzwave.pyx#L4730>`_. `OpenZWave developer
<https://github.com/OpenZWave/python-openzwave/blob/master/src-lib/libopenzwave/libopenzwave.pyx#L4730>`_.
:param data: Data to set for the value (default: current value data). :param data: Data to set for the value (default: current value data).
@ -826,8 +1023,13 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
:param scene_id: Select scene by scene_id. :param scene_id: Select scene by scene_id.
:param scene_label: Select scene by scene label. :param scene_label: Select scene by scene label.
""" """
value = self._get_value(value_id=value_id, id_on_network=id_on_network, node_id=node_id, node_name=node_name, value = self._get_value(
value_label=value_label) value_id=value_id,
id_on_network=id_on_network,
node_id=node_id,
node_name=node_name,
value_label=value_label,
)
scene = self._get_scene(scene_id=scene_id, scene_label=scene_label) scene = self._get_scene(scene_id=scene_id, scene_label=scene_label)
data = data if data is not None else value.data data = data if data is not None else value.data
data = value.check_data(data) data = value.check_data(data)
@ -837,10 +1039,16 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
self.write_config() self.write_config()
@action @action
def scene_remove_value(self, value_id: Optional[int] = None, id_on_network: Optional[str] = None, def scene_remove_value(
value_label: Optional[str] = None, scene_id: Optional[int] = None, self,
scene_label: Optional[str] = None, node_id: Optional[int] = None, value_id: Optional[int] = None,
node_name: Optional[str] = None): id_on_network: Optional[str] = None,
value_label: Optional[str] = None,
scene_id: Optional[int] = None,
scene_label: Optional[str] = None,
node_id: Optional[int] = None,
node_name: Optional[str] = None,
):
""" """
Remove a value from a scene. Remove a value from a scene.
@ -852,14 +1060,21 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
:param scene_id: Select scene by scene_id. :param scene_id: Select scene by scene_id.
:param scene_label: Select scene by scene label. :param scene_label: Select scene by scene label.
""" """
value = self._get_value(value_id=value_id, id_on_network=id_on_network, node_id=node_id, node_name=node_name, value = self._get_value(
value_label=value_label) value_id=value_id,
id_on_network=id_on_network,
node_id=node_id,
node_name=node_name,
value_label=value_label,
)
scene = self._get_scene(scene_id=scene_id, scene_label=scene_label) scene = self._get_scene(scene_id=scene_id, scene_label=scene_label)
scene.remove_value(value.value_id) scene.remove_value(value.value_id)
self.write_config() self.write_config()
@action @action
def get_scene_values(self, scene_id: Optional[int] = None, scene_label: Optional[str] = None) -> dict: def get_scene_values(
self, scene_id: Optional[int] = None, scene_label: Optional[str] = None
) -> dict:
""" """
Get the values associated to a scene. Get the values associated to a scene.
@ -871,18 +1086,12 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
return {v.value_id: v.to_dict() for v in scene.get_values().items()} return {v.value_id: v.to_dict() for v in scene.get_values().items()}
@action @action
def get_scene_values(self, scene_id: Optional[int] = None, scene_label: Optional[str] = None) -> dict: def create_button(
""" self,
Get the values associated to a scene. button_id: Union[int, str],
node_id: Optional[int] = None,
:param scene_id: Select by scene_id. node_name: Optional[str] = None,
:param scene_label: Select by scene label. ):
"""
scene = self._get_scene(scene_id=scene_id, scene_label=scene_label)
return {v.value_id: v.to_dict() for v in scene.get_values().items()}
@action
def create_button(self, button_id: Union[int, str], node_id: Optional[int] = None, node_name: Optional[str] = None):
""" """
Create a handheld button on a device. Only intended for bridge firmware controllers. Create a handheld button on a device. Only intended for bridge firmware controllers.
@ -895,7 +1104,12 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
self.write_config() self.write_config()
@action @action
def delete_button(self, button_id: Union[int, str], node_id: Optional[int] = None, node_name: Optional[str] = None): def delete_button(
self,
button_id: Union[int, str],
node_id: Optional[int] = None,
node_name: Optional[str] = None,
):
""" """
Delete a button association from a device. Only intended for bridge firmware controllers. Delete a button association from a device. Only intended for bridge firmware controllers.
@ -908,8 +1122,13 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
self.write_config() self.write_config()
@action @action
def add_node_to_group(self, group_index: Optional[int] = None, group_label: Optional[str] = None, def add_node_to_group(
node_id: Optional[int] = None, node_name: Optional[str] = None): self,
group_index: Optional[int] = None,
group_label: Optional[str] = None,
node_id: Optional[int] = None,
node_name: Optional[str] = None,
):
""" """
Add a node to a group. Add a node to a group.
@ -925,8 +1144,13 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
self.write_config() self.write_config()
@action @action
def remove_node_from_group(self, group_index: Optional[int] = None, group_label: Optional[str] = None, def remove_node_from_group(
node_id: Optional[int] = None, node_name: Optional[str] = None): self,
group_index: Optional[int] = None,
group_label: Optional[str] = None,
node_id: Optional[int] = None,
node_name: Optional[str] = None,
):
""" """
Remove a node from a group. Remove a node from a group.
@ -973,7 +1197,7 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
self._get_network().write_config() self._get_network().write_config()
@action @action
def on(self, device: str, *args, **kwargs): def on(self, device: str, *_, **__):
""" """
Turn on a switch on a device. Turn on a switch on a device.
@ -981,11 +1205,13 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
""" """
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
switches = self.get_switches().output switches = self.get_switches().output
assert device in switches, 'No such id_on_network associated to a switch: {}'.format(device) assert (
device in switches
), 'No such id_on_network associated to a switch: {}'.format(device)
return self.set_value(data=True, id_on_network=device) return self.set_value(data=True, id_on_network=device)
@action @action
def off(self, device: str, *args, **kwargs): def off(self, device: str, *_, **__):
""" """
Turn off a switch on a device. Turn off a switch on a device.
@ -993,11 +1219,13 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
""" """
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
switches = self.get_switches().output switches = self.get_switches().output
assert device in switches, 'No such id_on_network associated to a switch: {}'.format(device) assert (
device in switches
), 'No such id_on_network associated to a switch: {}'.format(device)
return self.set_value(data=False, id_on_network=device) return self.set_value(data=False, id_on_network=device)
@action @action
def toggle(self, device: str, *args, **kwargs): def toggle(self, device: str, *_, **__):
""" """
Toggle a switch on a device. Toggle a switch on a device.
@ -1005,7 +1233,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
""" """
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
switches = self.get_switches().output switches = self.get_switches().output
assert device in switches, 'No such id_on_network associated to a switch: {}'.format(device) assert (
device in switches
), 'No such id_on_network associated to a switch: {}'.format(device)
data = switches[device]['data'] data = switches[device]['data']
return self.set_value(data=not data, id_on_network=device) return self.set_value(data=not data, id_on_network=device)
@ -1015,7 +1245,9 @@ class ZwavePlugin(ZwaveBasePlugin, SwitchPlugin):
devices = self.get_switches().output.values() devices = self.get_switches().output.values()
return [ return [
{ {
'name': '{} - {}'.format(dev.get('node_name', '[No Name]'), dev.get('label', '[No Label]')), 'name': '{} - {}'.format(
dev.get('node_name', '[No Name]'), dev.get('label', '[No Label]')
),
'on': dev.get('data'), 'on': dev.get('data'),
'id': dev.get('id_on_network'), 'id': dev.get('id_on_network'),
} }

View file

@ -148,6 +148,9 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin):
return response return response
def _api_request(self, api: str, *args, **kwargs): def _api_request(self, api: str, *args, **kwargs):
if len(args) == 1 and isinstance(args[0], dict):
args = args[0]
payload = json.dumps({'args': args}) payload = json.dumps({'args': args})
ret = self._parse_response( ret = self._parse_response(
self.publish( self.publish(
@ -280,11 +283,11 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin):
@classmethod @classmethod
def node_to_dict(cls, node: dict) -> dict: def node_to_dict(cls, node: dict) -> dict:
capabilities = [] capabilities = []
if node['supportsBeaming']: if node.get('supportsBeaming'):
capabilities += ['beaming'] capabilities += ['beaming']
if node['supportsSecurity']: if node.get('supportsSecurity'):
capabilities += ['security'] capabilities += ['security']
if node['isRouting']: if node.get('isRouting'):
capabilities += ['routing'] capabilities += ['routing']
if node.get('zwavePlusVersion'): if node.get('zwavePlusVersion'):
capabilities += ['zwave_plus'] capabilities += ['zwave_plus']
@ -623,29 +626,51 @@ class ZwaveMqttPlugin(MqttPlugin, ZwaveBasePlugin):
} }
@action @action
def add_node(self, do_security: bool = False, timeout: int = 60, **kwargs): def add_node(
self,
name: str,
location: str = '',
do_security: bool = False,
timeout: int = 30,
**kwargs,
):
""" """
Start the inclusion process to add a node to the network. Start the inclusion process to add a node to the network.
:param name: Name of the node to be added.
:param location: Location of the node (default: empty).
:param do_security: Whether to initialize the Network Key on the device if it supports the Security CC :param do_security: Whether to initialize the Network Key on the device if it supports the Security CC
:param timeout: How long the inclusion process should last, in seconds (default: 60). Specify zero or null :param timeout: How long the inclusion process should last, in seconds (default: 30). Specify zero or null
for no timeout. for no timeout.
:param kwargs: Extra arguments to be passed to :meth:`platypush.plugins.mqtt.MqttPlugin.publish`` :param kwargs: Extra arguments to be passed to :meth:`platypush.plugins.mqtt.MqttPlugin.publish``
(default: query the default configured device). (default: query the default configured device).
""" """
self._api_request('startInclusion', **kwargs) self._api_request(
'startInclusion',
0,
{
'name': name,
'location': location,
'force_security': do_security,
},
**kwargs,
)
if timeout: if timeout:
Timer(timeout, lambda: self._api_request('stopInclusion', **kwargs)).start() Timer(timeout, lambda: self._api_request('stopInclusion', **kwargs)).start()
@action @action
def remove_node(self, **kwargs): def remove_node(self, timeout: int = 30, **kwargs):
""" """
Remove a node from the network (not implemented on zwavejs2mqtt). Remove a node from the network (or, better, start the exclusion process).
:param timeout: How long the exclusion process should last, in seconds (default: 30).
:param kwargs: Extra arguments to be passed to :meth:`platypush.plugins.mqtt.MqttPlugin.publish`` :param kwargs: Extra arguments to be passed to :meth:`platypush.plugins.mqtt.MqttPlugin.publish``
(default: query the default configured device). (default: query the default configured device).
""" """
raise _NOT_IMPLEMENTED_ERR self._api_request('startExclusion', **kwargs)
if timeout:
Timer(timeout, lambda: self._api_request('stopExclusion', **kwargs)).start()
@action @action
def remove_failed_node( def remove_failed_node(