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
12 changes: 10 additions & 2 deletions homeassistant/components/zwave/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
async_dispatcher_connect, async_dispatcher_send)
from homeassistant.components.frontend import register_built_in_panel

from . import api
from . import const
from .const import DOMAIN
from .node_entity import ZWaveBaseEntity, ZWaveNodeEntity
Expand Down Expand Up @@ -66,6 +67,8 @@
DEFAULT_CONF_REFRESH_DELAY = 5

DATA_ZWAVE_DICT = 'zwave_devices'
OZW_LOG_FILENAME = 'OZW_Log.txt'
URL_API_OZW_LOG = '/api/zwave/ozwlog'
ZWAVE_NETWORK = 'zwave_network'

RENAME_NODE_SCHEMA = vol.Schema({
Expand Down Expand Up @@ -383,7 +386,7 @@ def stop_network(_service_or_event):
def rename_node(service):
"""Rename a node."""
node_id = service.data.get(const.ATTR_NODE_ID)
node = hass.data[ZWAVE_NETWORK].nodes[node_id]
node = network.nodes[node_id]
name = service.data.get(const.ATTR_NAME)
node.name = name
_LOGGER.info(
Expand Down Expand Up @@ -501,7 +504,7 @@ def start_zwave(_service_or_event):
# to be ready.
for i in range(const.NETWORK_READY_WAIT_SECS):
_LOGGER.debug(
"network state: %d %s", hass.data[ZWAVE_NETWORK].state,
"network state: %d %s", network.state,
network.state_str)
if network.state >= network.STATE_AWAKED:
_LOGGER.info("Z-Wave ready after %d seconds", i)
Expand Down Expand Up @@ -607,6 +610,11 @@ def start_zwave(_service_or_event):

if 'frontend' in hass.config.components:
register_built_in_panel(hass, 'zwave', 'Z-Wave', 'mdi:nfc')
hass.http.register_view(api.ZWaveNodeGroupView)
hass.http.register_view(api.ZWaveNodeConfigView)
hass.http.register_view(api.ZWaveUserCodeView)
hass.http.register_static_path(
URL_API_OZW_LOG, hass.config.path(OZW_LOG_FILENAME), False)

return True

Expand Down
95 changes: 95 additions & 0 deletions homeassistant/components/zwave/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"""API class to give info to the Z-Wave panel."""

import logging
import homeassistant.core as ha
from homeassistant.components.http import HomeAssistantView
from homeassistant.const import HTTP_NOT_FOUND
from . import const

_LOGGER = logging.getLogger(__name__)

ZWAVE_NETWORK = 'zwave_network'


class ZWaveNodeGroupView(HomeAssistantView):
"""View to return the nodes group configuration."""

url = r"/api/zwave/groups/{node_id:\d+}"
name = "api:zwave:groups"

@ha.callback
def get(self, request, node_id):
"""Retrieve groups of node."""
nodeid = int(node_id)
hass = request.app['hass']
network = hass.data.get(ZWAVE_NETWORK)
node = network.nodes.get(nodeid)
if node is None:
return self.json_message('Node not found', HTTP_NOT_FOUND)
groupdata = node.groups
groups = {}
for key, value in groupdata.items():
groups[key] = {'associations': value.associations,
'association_instances':
value.associations_instances,
'label': value.label,
'max_associations': value.max_associations}
return self.json(groups)


class ZWaveNodeConfigView(HomeAssistantView):
"""View to return the nodes configuration options."""

url = r"/api/zwave/config/{node_id:\d+}"
name = "api:zwave:config"

@ha.callback
def get(self, request, node_id):
"""Retrieve configurations of node."""
nodeid = int(node_id)
hass = request.app['hass']
network = hass.data.get(ZWAVE_NETWORK)
node = network.nodes.get(nodeid)
if node is None:
return self.json_message('Node not found', HTTP_NOT_FOUND)
config = {}
for value in (
node.get_values(class_id=const.COMMAND_CLASS_CONFIGURATION)
.values()):
config[value.index] = {'label': value.label,
'type': value.type,
'help': value.help,
'data_items': value.data_items,
'data': value.data,
'max': value.max,
'min': value.min}
return self.json(config)


class ZWaveUserCodeView(HomeAssistantView):
"""View to return the nodes usercode configuration."""

url = r"/api/zwave/usercodes/{node_id:\d+}"
name = "api:zwave:usercodes"

@ha.callback
def get(self, request, node_id):
"""Retrieve usercodes of node."""
nodeid = int(node_id)
hass = request.app['hass']
network = hass.data.get(ZWAVE_NETWORK)
node = network.nodes.get(nodeid)
if node is None:
return self.json_message('Node not found', HTTP_NOT_FOUND)
usercodes = {}
if not node.has_command_class(const.COMMAND_CLASS_USER_CODE):
return self.json(usercodes)
for value in (
node.get_values(class_id=const.COMMAND_CLASS_USER_CODE)
.values()):
if value.genre != const.GENRE_USER:
continue
usercodes[value.index] = {'code': value.data,
'label': value.label,
'length': len(value.data)}
return self.json(usercodes)
Loading