async def async_get_node_func( opp: OpenPeerPower, connection: ActiveConnection, msg: dict, entry: ConfigEntry, client: Client, ) -> None: """Provide user specific data and store to function.""" node_id = msg[NODE_ID] node = client.driver.controller.nodes.get(node_id) if node is None: connection.send_error(msg[ID], ERR_NOT_FOUND, f"Node {node_id} not found") return await orig_func(opp, connection, msg, node)
async def websocket_refresh_node_cc_values( opp: OpenPeerPower, connection: ActiveConnection, msg: dict, node: Node, ) -> None: """Refresh node values for a particular CommandClass.""" command_class_id = msg[COMMAND_CLASS_ID] try: command_class = CommandClass(command_class_id) except ValueError: connection.send_error( msg[ID], ERR_NOT_FOUND, f"Command class {command_class_id} not found" ) return await node.async_refresh_cc_values(command_class) connection.send_result(msg[ID])
async def async_get_entry_func( opp: OpenPeerPower, connection: ActiveConnection, msg: dict ) -> None: """Provide user specific data and store to function.""" entry_id = msg[ENTRY_ID] entry = opp.config_entries.async_get_entry(entry_id) if entry is None: connection.send_error( msg[ID], ERR_NOT_FOUND, f"Config entry {entry_id} not found" ) return if entry.state is not ConfigEntryState.LOADED: connection.send_error( msg[ID], ERR_NOT_LOADED, f"Config entry {entry_id} not loaded" ) return client = opp.data[DOMAIN][entry_id][DATA_CLIENT] await orig_func(opp, connection, msg, entry, client)
async def websocket_supervisor_api(opp: OpenPeerPower, connection: ActiveConnection, msg: dict): """Websocket handler to call Supervisor API.""" supervisor: OppIO = opp.data[DOMAIN] try: result = await supervisor.send_command( msg[ATTR_ENDPOINT], method=msg[ATTR_METHOD], timeout=msg.get(ATTR_TIMEOUT, 10), payload=msg.get(ATTR_DATA, {}), ) if result.get(ATTR_RESULT) == "error": raise opp.components.oppio.OppioAPIError(result.get("message")) except opp.components.oppio.OppioAPIError as err: _LOGGER.error("Failed to to call %s - %s", msg[ATTR_ENDPOINT], err) connection.send_error(msg[WS_ID], code=websocket_api.ERR_UNKNOWN_ERROR, message=str(err)) else: connection.send_result(msg[WS_ID], result.get(ATTR_DATA, {}))
async def websocket_set_config_parameter( opp: OpenPeerPower, connection: ActiveConnection, msg: dict, node: Node, ) -> None: """Set a config parameter value for a Z-Wave node.""" property_ = msg[PROPERTY] property_key = msg.get(PROPERTY_KEY) value = msg[VALUE] try: zwave_value, cmd_status = await async_set_config_parameter( node, value, property_, property_key=property_key ) except (InvalidNewValue, NotFoundError, NotImplementedError, SetValueFailed) as err: code = ERR_UNKNOWN_ERROR if isinstance(err, NotFoundError): code = ERR_NOT_FOUND elif isinstance(err, (InvalidNewValue, NotImplementedError)): code = ERR_NOT_SUPPORTED connection.send_error( msg[ID], code, str(err), ) return connection.send_result( msg[ID], { VALUE_ID: zwave_value.value_id, STATUS: cmd_status, }, )