Skip to content

Commit

Permalink
Tests for zwave services (home-assistant#6937)
Browse files Browse the repository at this point in the history
* Initial tests for zwave services

* Fix linter issues

* Complete zwave service tests
  • Loading branch information
emlove authored Apr 7, 2017
1 parent 8cff98d commit df77529
Show file tree
Hide file tree
Showing 6 changed files with 452 additions and 36 deletions.
2 changes: 0 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ omit =
homeassistant/components/climate/oem.py
homeassistant/components/climate/proliphix.py
homeassistant/components/climate/radiotherm.py
homeassistant/components/config/zwave.py
homeassistant/components/cover/garadget.py
homeassistant/components/cover/homematic.py
homeassistant/components/cover/myq.py
Expand Down Expand Up @@ -442,7 +441,6 @@ omit =
homeassistant/components/weather/openweathermap.py
homeassistant/components/weather/zamg.py
homeassistant/components/zeroconf.py
homeassistant/components/zwave/__init__.py
homeassistant/components/zwave/util.py


Expand Down
14 changes: 8 additions & 6 deletions homeassistant/components/zwave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ def get_config_value(node, value_index, tries=5):
"""Return the current configuration value for a specific index."""
try:
for value in node.values.values():
# 112 == config command class
if value.command_class == 112 and value.index == value_index:
if (value.command_class == const.COMMAND_CLASS_CONFIGURATION
and value.index == value_index):
return value.data
except RuntimeError:
# If we get an runtime error the dict has changed while
Expand Down Expand Up @@ -384,7 +384,7 @@ def test_network(service):
_LOGGER.info("Zwave test_network have been initialized.")
NETWORK.test()

def stop_zwave(_service_or_event):
def stop_network(_service_or_event):
"""Stop Z-Wave network."""
_LOGGER.info("Stopping ZWave network.")
NETWORK.stop()
Expand Down Expand Up @@ -532,7 +532,7 @@ def start_zwave(_service_or_event):
poll_interval = NETWORK.get_poll_interval()
_LOGGER.info("zwave polling interval set to %d ms", poll_interval)

hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_zwave)
hass.bus.listen_once(EVENT_HOMEASSISTANT_STOP, stop_network)

# Register node services for Z-Wave network
hass.services.register(DOMAIN, const.SERVICE_ADD_NODE, add_node,
Expand All @@ -553,7 +553,8 @@ def start_zwave(_service_or_event):
hass.services.register(DOMAIN, const.SERVICE_TEST_NETWORK,
test_network,
descriptions[const.SERVICE_TEST_NETWORK])
hass.services.register(DOMAIN, const.SERVICE_STOP_NETWORK, stop_zwave,
hass.services.register(DOMAIN, const.SERVICE_STOP_NETWORK,
stop_network,
descriptions[const.SERVICE_STOP_NETWORK])
hass.services.register(DOMAIN, const.SERVICE_START_NETWORK,
start_zwave,
Expand Down Expand Up @@ -840,4 +841,5 @@ def device_state_attributes(self):
def refresh_from_network(self):
"""Refresh all dependent values from zwave network."""
for value in self.values:
self.node.refresh_value(value.value_id)
if value is not None:
self.node.refresh_value(value.value_id)
5 changes: 3 additions & 2 deletions tests/components/climate/test_zwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def device(hass, mock_openzwave):
node = MockNode()
values = MockEntityValues(
primary=MockValue(data=1, node=node),
temperature=MockValue(data=5, node=node),
temperature=MockValue(data=5, node=node, units=None),
mode=MockValue(data=b'test1', data_items=[0, 1, 2], node=node),
fan_mode=MockValue(data=b'test2', data_items=[3, 4, 5], node=node),
operating_state=MockValue(data=6, node=node),
Expand All @@ -30,9 +30,10 @@ def device(hass, mock_openzwave):
def device_zxt_120(hass, mock_openzwave):
"""Fixture to provide a precreated climate device."""
node = MockNode(manufacturer_id='5254', product_id='8377')

values = MockEntityValues(
primary=MockValue(data=1, node=node),
temperature=MockValue(data=5, node=node),
temperature=MockValue(data=5, node=node, units=None),
mode=MockValue(data=b'test1', data_items=[0, 1, 2], node=node),
fan_mode=MockValue(data=b'test2', data_items=[3, 4, 5], node=node),
operating_state=MockValue(data=6, node=node),
Expand Down
Loading

0 comments on commit df77529

Please sign in to comment.