Skip to content
Merged
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
1 change: 1 addition & 0 deletions homeassistant/components/config/zwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def get(self, request, node_id):
'label': entity_values.primary.label,
'index': entity_values.primary.index,
'instance': entity_values.primary.instance,
'poll_intensity': entity_values.primary.poll_intensity,
}
return self.json(values_data)

Expand Down
36 changes: 34 additions & 2 deletions homeassistant/components/zwave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@
vol.Optional(const.ATTR_CONFIG_SIZE, default=2): vol.Coerce(int)
})

SET_POLL_INTENSITY_SCHEMA = vol.Schema({
vol.Required(const.ATTR_NODE_ID): vol.Coerce(int),
vol.Required(const.ATTR_VALUE_ID): vol.Coerce(int),
vol.Required(const.ATTR_POLL_INTENSITY): vol.Coerce(int),
})

PRINT_CONFIG_PARAMETER_SCHEMA = vol.Schema({
vol.Required(const.ATTR_NODE_ID): vol.Coerce(int),
vol.Required(const.ATTR_CONFIG_PARAMETER): vol.Coerce(int),
Expand Down Expand Up @@ -415,6 +421,29 @@ def rename_value(service):
"Renamed Z-Wave value (Node %d Value %d) to %s",
node_id, value_id, name)

def set_poll_intensity(service):
"""Set the polling intensity of a node value."""
node_id = service.data.get(const.ATTR_NODE_ID)
value_id = service.data.get(const.ATTR_VALUE_ID)
node = network.nodes[node_id]
value = node.values[value_id]
intensity = service.data.get(const.ATTR_POLL_INTENSITY)
if intensity == 0:
if value.disable_poll():
_LOGGER.info("Polling disabled (Node %d Value %d)",
node_id, value_id)
return
_LOGGER.info("Polling disabled failed (Node %d Value %d)",
node_id, value_id)
else:
if value.enable_poll(intensity):
_LOGGER.info(
"Set polling intensity (Node %d Value %d) to %s",
node_id, value_id, intensity)
return
_LOGGER.info("Set polling intensity failed (Node %d Value %d)",
node_id, value_id)

def remove_failed_node(service):
"""Remove failed node."""
node_id = service.data.get(const.ATTR_NODE_ID)
Expand Down Expand Up @@ -651,6 +680,10 @@ def start_zwave(_service_or_event):
descriptions[
const.SERVICE_RESET_NODE_METERS],
schema=RESET_NODE_METERS_SCHEMA)
hass.services.register(DOMAIN, const.SERVICE_SET_POLL_INTENSITY,
set_poll_intensity,
descriptions[const.SERVICE_SET_POLL_INTENSITY],
schema=SET_POLL_INTENSITY_SCHEMA)

# Setup autoheal
if autoheal:
Expand Down Expand Up @@ -775,8 +808,6 @@ def _check_entity_ready(self):
node_config.get(CONF_POLLING_INTENSITY), int)
if polling_intensity:
self.primary.enable_poll(polling_intensity)
else:
self.primary.disable_poll()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Is polling disabled by default, and that's why this was removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polling is always set to 0 by OZW unless it is set to something different by user to the value_id.
So if there is no entry for polling, in either the homeassistant config or the zwcfg, no polling is set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Just checking.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate it 🥇


platform = get_platform(component, DOMAIN)
device = platform.get_device(
Expand Down Expand Up @@ -887,6 +918,7 @@ def device_state_attributes(self):
const.ATTR_NODE_ID: self.node_id,
const.ATTR_VALUE_INDEX: self.values.primary.index,
const.ATTR_VALUE_INSTANCE: self.values.primary.instance,
const.ATTR_VALUE_ID: str(self.values.primary.value_id),
'old_entity_id': self.old_entity_id,
'new_entity_id': self.new_entity_id,
}
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/zwave/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ATTR_CONFIG_PARAMETER = "parameter"
ATTR_CONFIG_SIZE = "size"
ATTR_CONFIG_VALUE = "value"
ATTR_POLL_INTENSITY = "poll_intensity"
ATTR_VALUE_INDEX = "value_index"
ATTR_VALUE_INSTANCE = "value_instance"
NETWORK_READY_WAIT_SECS = 30
Expand All @@ -38,6 +39,7 @@
SERVICE_PRINT_NODE = "print_node"
SERVICE_REMOVE_FAILED_NODE = "remove_failed_node"
SERVICE_REPLACE_FAILED_NODE = "replace_failed_node"
SERVICE_SET_POLL_INTENSITY = "set_poll_intensity"
SERVICE_SET_WAKEUP = "set_wakeup"
SERVICE_STOP_NETWORK = "stop_network"
SERVICE_START_NETWORK = "start_network"
Expand Down
14 changes: 14 additions & 0 deletions homeassistant/components/zwave/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ set_config_parameter:
size:
description: (Optional) Set the size of the parameter value. Only needed if no parameters are available.

set_poll_intensity:
description: Set the polling interval to a nodes value
fields:
node_id:
description: ID of the node to set polling to.
example: 10
value_id:
description: ID of the value to set polling to.
example: 72037594255792737
poll_intensity:
description: The intensity to poll, 0 = disabled, 1 = Every time through list, 2 = Every second time through list...
example: 2


print_config_parameter:
description: Prints a Z-Wave node config parameter value to log.
fields:
Expand Down
3 changes: 2 additions & 1 deletion tests/components/config/test_zwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_get_values(hass, test_client):

node = MockNode(node_id=1)
value = MockValue(value_id=123456, node=node, label='Test Label',
instance=1, index=2)
instance=1, index=2, poll_intensity=4)
values = MockEntityValues(primary=value)
node2 = MockNode(node_id=2)
value2 = MockValue(value_id=234567, node=node2, label='Test Label 2')
Expand All @@ -162,6 +162,7 @@ def test_get_values(hass, test_client):
'label': 'Test Label',
'instance': 1,
'index': 2,
'poll_intensity': 4,
}
}

Expand Down
81 changes: 79 additions & 2 deletions tests/components/zwave/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,6 @@ def test_entity_existing_values(self, discovery, get_platform):
assert args[3] == {const.DISCOVERY_DEVICE: id(values)}
assert args[4] == self.zwave_config
assert not self.primary.enable_poll.called
assert self.primary.disable_poll.called

@patch.object(zwave, 'get_platform')
@patch.object(zwave, 'discovery')
Expand Down Expand Up @@ -742,7 +741,6 @@ def test_config_polling_intensity(self, discovery, get_platform):
assert self.primary.enable_poll.called
assert len(self.primary.enable_poll.mock_calls) == 1
assert self.primary.enable_poll.mock_calls[0][1][0] == 123
assert not self.primary.disable_poll.called


class TestZwave(unittest.TestCase):
Expand Down Expand Up @@ -887,6 +885,85 @@ def test_rename_value(self):

assert value.label == "New Label"

def test_set_poll_intensity_enable(self):
"""Test zwave set_poll_intensity service, succsessful set."""
node = MockNode(node_id=14)
value = MockValue(index=12, value_id=123456, poll_intensity=0)
node.values = {123456: value}
self.zwave_network.nodes = {11: node}

assert value.poll_intensity == 0
self.hass.services.call('zwave', 'set_poll_intensity', {
const.ATTR_NODE_ID: 11,
const.ATTR_VALUE_ID: 123456,
const.ATTR_POLL_INTENSITY: 4,
})
self.hass.block_till_done()

enable_poll = value.enable_poll
assert value.enable_poll.called
assert len(enable_poll.mock_calls) == 2
assert enable_poll.mock_calls[0][1][0] == 4

def test_set_poll_intensity_enable_failed(self):
"""Test zwave set_poll_intensity service, failed set."""
node = MockNode(node_id=14)
value = MockValue(index=12, value_id=123456, poll_intensity=0)
value.enable_poll.return_value = False
node.values = {123456: value}
self.zwave_network.nodes = {11: node}

assert value.poll_intensity == 0
self.hass.services.call('zwave', 'set_poll_intensity', {
const.ATTR_NODE_ID: 11,
const.ATTR_VALUE_ID: 123456,
const.ATTR_POLL_INTENSITY: 4,
})
self.hass.block_till_done()

enable_poll = value.enable_poll
assert value.enable_poll.called
assert len(enable_poll.mock_calls) == 1

def test_set_poll_intensity_disable(self):
"""Test zwave set_poll_intensity service, successful disable."""
node = MockNode(node_id=14)
value = MockValue(index=12, value_id=123456, poll_intensity=4)
node.values = {123456: value}
self.zwave_network.nodes = {11: node}

assert value.poll_intensity == 4
self.hass.services.call('zwave', 'set_poll_intensity', {
const.ATTR_NODE_ID: 11,
const.ATTR_VALUE_ID: 123456,
const.ATTR_POLL_INTENSITY: 0,
})
self.hass.block_till_done()

disable_poll = value.disable_poll
assert value.disable_poll.called
assert len(disable_poll.mock_calls) == 2

def test_set_poll_intensity_disable_failed(self):
"""Test zwave set_poll_intensity service, failed disable."""
node = MockNode(node_id=14)
value = MockValue(index=12, value_id=123456, poll_intensity=4)
value.disable_poll.return_value = False
node.values = {123456: value}
self.zwave_network.nodes = {11: node}

assert value.poll_intensity == 4
self.hass.services.call('zwave', 'set_poll_intensity', {
const.ATTR_NODE_ID: 11,
const.ATTR_VALUE_ID: 123456,
const.ATTR_POLL_INTENSITY: 0,
})
self.hass.block_till_done()

disable_poll = value.disable_poll
assert value.disable_poll.called
assert len(disable_poll.mock_calls) == 1

def test_remove_failed_node(self):
"""Test zwave remove_failed_node service."""
self.hass.services.call('zwave', 'remove_failed_node', {
Expand Down