Skip to content

Commit

Permalink
Handle integration settings - initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
farmio committed Aug 13, 2023
1 parent 0bcaa88 commit e7005d8
Show file tree
Hide file tree
Showing 5 changed files with 774 additions and 4 deletions.
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
33 changes: 32 additions & 1 deletion src/services/websocket.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { HomeAssistant } from "@ha/types";
import { KNXInfoData, TelegramDict, GroupMonitorInfoData } from "../types/websocket";
import {
SettingsInfoData,
KNXInfoData,
TelegramDict,
GatewayDescriptor,
GroupMonitorInfoData,
ConfigEntryData,
} from "../types/websocket";

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

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 writeConnectionData = (
hass: HomeAssistant,
changeset: Partial<ConfigEntryData>,
): Promise<void> =>
hass.callWS({
type: "knx/settings/write_config_entry_data",
changeset: changeset,
});

export const getGroupMonitorInfo = (hass: HomeAssistant): Promise<GroupMonitorInfoData> =>
hass.callWS({
type: "knx/group_monitor_info",
Expand Down
68 changes: 68 additions & 0 deletions src/types/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,71 @@ 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[];
}

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 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

0 comments on commit e7005d8

Please sign in to comment.