Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle integration settings from KNX panel #94

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
18 changes: 15 additions & 3 deletions src/knx-router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mdiNetwork, mdiFolderMultipleOutline } from "@mdi/js";
import { mdiCogOutline, mdiNetwork, mdiFolderMultipleOutline } from "@mdi/js";
import { customElement, property, state } from "lit/decorators";

import { HassRouterPage, RouterOptions } from "@ha/layouts/hass-router-page";
Expand All @@ -16,6 +16,11 @@ export const knxMainTabs: PageNavigation[] = [
path: `/knx/info`,
iconPath: mdiFolderMultipleOutline,
},
{
translationKey: "settings_title",
path: `/knx/settings`,
iconPath: mdiCogOutline,
},
{
translationKey: "group_monitor_title",
path: `/knx/group_monitor`,
Expand Down Expand Up @@ -43,14 +48,21 @@ class KnxRouter extends HassRouterPage {
info: {
tag: "knx-info",
load: () => {
logger.info("Importing knx-info");
logger.info("Importing info view");
return import("./views/info");
},
},
settings: {
tag: "knx-settings",
load: () => {
logger.info("Importing settings view");
return import("./views/settings");
},
},
group_monitor: {
tag: "knx-group-monitor",
load: () => {
logger.info("Importing knx-group-monitor");
logger.info("Importing group-monitor view");
return import("./views/group_monitor");
},
},
Expand Down
1 change: 1 addition & 0 deletions src/localize/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"info_issue_tracker_knx_frontend": "the KNX frontend panel",
"info_issue_tracker_xknxproject": "project data parsing",
"info_issue_tracker_xknx": "KNX connection or DPT decoding",
"settings_title": "Settings",
"group_monitor_title": "Group Monitor",
"group_monitor_time": "Time",
"group_monitor_direction": "Direction",
Expand Down
55 changes: 54 additions & 1 deletion src/services/websocket.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { HomeAssistant } from "@ha/types";
import { KNXInfoData, TelegramDict, GroupMonitorInfoData } from "../types/websocket";
import {
SettingsInfoData,
KNXInfoData,
TelegramDict,
GatewayDescriptor,
GroupMonitorInfoData,
ConfigEntryData,
} from "../types/websocket";

// INFO

export const getKnxInfoData = (hass: HomeAssistant): Promise<KNXInfoData> =>
hass.callWS({
Expand All @@ -22,6 +31,50 @@ export const removeProjectFile = (hass: HomeAssistant): Promise<void> =>
type: "knx/project_file_remove",
});

// SETTINGS

export const getSettingsInfoData = (hass: HomeAssistant): Promise<SettingsInfoData> =>
hass.callWS({
type: "knx/settings/info",
});

export const subscribeGatewayScanner = (
hass: HomeAssistant,
local_interface: string | null,
callback: (gateway: GatewayDescriptor) => void,
) =>
hass.connection.subscribeMessage<GatewayDescriptor>(callback, {
type: "knx/settings/subscribe_gateway_scanner",
local_interface: local_interface,
});

export const processKeyringFile = (
hass: HomeAssistant,
file_id: string,
password: string,
): Promise<void> =>
hass.callWS({
type: "knx/settings/keyring_file_process",
file_id: file_id,
password: password,
});

export const removeKeyringFile = (hass: HomeAssistant): Promise<void> =>
hass.callWS({
type: "knx/settings/keyring_file_remove",
});

export const writeConnectionData = (
hass: HomeAssistant,
changeset: Partial<ConfigEntryData>,
): Promise<void> =>
hass.callWS({
type: "knx/settings/write_config_entry_data",
changeset: changeset,
});

// GROUP MONITOR

export const getGroupMonitorInfo = (hass: HomeAssistant): Promise<GroupMonitorInfoData> =>
hass.callWS({
type: "knx/group_monitor_info",
Expand Down
90 changes: 90 additions & 0 deletions src/types/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,93 @@ export interface TelegramDict {
unit: string | null;
value: string | number | boolean | null;
}

export const enum ConnectionType {
Automatic = "automatic",
RoutingPlain = "routing",
RoutingSecure = "routing_secure",
TunnellingUDP = "tunneling",
TunnellingTCP = "tunneling_tcp",
TunnellingSecure = "tunneling_tcp_secure",
}

export interface SettingsInfoData {
config_entry: ConfigEntryData;
local_interfaces: string[];
keyfile_data: KeyfileData | null;
}

export type ConfigEntryData = ConnectionData & IntegrationSettingsData;

export interface ConnectionData {
connection_type: ConnectionType;
individual_address?: string;
local_ip?: string | null; // not required
multicast_group: string | null;
multicast_port: number;
route_back?: boolean | null; // not required
host?: string | null; // only required for tunnelling
port?: number | null; // only required for tunnelling
tunnel_endpoint_ia?: string | null;
// KNX secure
user_id?: number | null; // not required
user_password?: string | null; // not required
device_authentication?: string | null; // not required
knxkeys_filename?: string; // not required
knxkeys_password?: string; // not required
backbone_key?: string | null; // not required
sync_latency_tolerance?: number | null; // not required
}

export interface IntegrationSettingsData {
// OptionsFlow only
state_updater: boolean;
rate_limit?: number;
// Integration only (not forwarded to xknx)
telegram_log_size?: number; // not required
}

export interface KeyfileData {
project_name: string;
timestamp: string;
created_by: string;
secure_backbone: SecureBackbone | null;
tunnel_interfaces: TunnelInterface[];
ds_group_addresses: string[]; // ["1/2/3"]
}

export interface SecureBackbone {
multicast_address: string;
latency: number;
}

export interface TunnelInterface {
host: string; // "1.1.10"
individual_address: string;
user_id: number | null; // no user_id -> plain tunnelling
ds_group_addresses: string[];
}

export interface GatewayDescriptor {
name: string;
ip_addr: string;
port: number;
individual_address: string; // todo convert
local_interface: string;
local_ip: string;
supports_routing: boolean;
supports_tunnelling: boolean;
supports_tunnelling_tcp: boolean;
supports_secure: boolean;
core_version: number;
routing_requires_secure: boolean; // todo unwrap
tunnelling_requires_secure: boolean; // todo unwrap
tunnelling_slots: TunnelingSlot[]; // todo flatten
}

interface TunnelingSlot {
individual_address: string;
authorized: boolean;
free: boolean;
usable: boolean;
}
Loading