From c8e00ba160b6867e062daeffeaf4b2ca0467c788 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Fri, 4 Dec 2020 11:37:55 +0100 Subject: [PATCH] Adds vlan_struct (#2337) * Return VLAN ID instead of wifistruct for VLAN * Use vlan_struct * fix typing Co-authored-by: Pascal Vizeli --- supervisor/api/network.py | 18 ++++++++++++++---- supervisor/const.py | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/supervisor/api/network.py b/supervisor/api/network.py index e49f0e9b4..5595d2a66 100644 --- a/supervisor/api/network.py +++ b/supervisor/api/network.py @@ -18,6 +18,7 @@ from ..const import ( ATTR_FREQUENCY, ATTR_GATEWAY, ATTR_HOST_INTERNET, + ATTR_ID, ATTR_INTERFACE, ATTR_INTERFACES, ATTR_IPV4, @@ -26,6 +27,7 @@ from ..const import ( ATTR_METHOD, ATTR_MODE, ATTR_NAMESERVERS, + ATTR_PARENT, ATTR_PRIMARY, ATTR_PSK, ATTR_SIGNAL, @@ -80,7 +82,7 @@ SCHEMA_UPDATE = vol.Schema( ) -def ipconfig_struct(config: IpConfig) -> dict: +def ipconfig_struct(config: IpConfig) -> Dict[str, Any]: """Return a dict with information about ip configuration.""" return { ATTR_METHOD: config.method, @@ -90,7 +92,7 @@ def ipconfig_struct(config: IpConfig) -> dict: } -def wifi_struct(config: WifiConfig) -> dict: +def wifi_struct(config: WifiConfig) -> Dict[str, Any]: """Return a dict with information about wifi configuration.""" return { ATTR_MODE: config.mode, @@ -100,7 +102,15 @@ def wifi_struct(config: WifiConfig) -> dict: } -def interface_struct(interface: Interface) -> dict: +def vlan_struct(config: VlanConfig) -> Dict[str, Any]: + """Return a dict with information about VLAN configuration.""" + return { + ATTR_ID: config.id, + ATTR_PARENT: config.interface, + } + + +def interface_struct(interface: Interface) -> Dict[str, Any]: """Return a dict with information of a interface to be used in th API.""" return { ATTR_INTERFACE: interface.name, @@ -115,7 +125,7 @@ def interface_struct(interface: Interface) -> dict: } -def accesspoint_struct(accesspoint: AccessPoint) -> dict: +def accesspoint_struct(accesspoint: AccessPoint) -> Dict[str, Any]: """Return a dict for AccessPoint.""" return { ATTR_MODE: accesspoint.mode, diff --git a/supervisor/const.py b/supervisor/const.py index 4c153076b..e81d22159 100644 --- a/supervisor/const.py +++ b/supervisor/const.py @@ -153,6 +153,7 @@ ATTR_HOST_NETWORK = "host_network" ATTR_HOST_PID = "host_pid" ATTR_HOSTNAME = "hostname" ATTR_ICON = "icon" +ATTR_ID = "id" ATTR_ISSUES = "issues" ATTR_IMAGE = "image" ATTR_IMAGES = "images" @@ -205,6 +206,7 @@ ATTR_PANEL_ICON = "panel_icon" ATTR_PANEL_TITLE = "panel_title" ATTR_PANELS = "panels" ATTR_PASSWORD = "password" +ATTR_PARENT = "parent" ATTR_PORT = "port" ATTR_PORTS = "ports" ATTR_PORTS_DESCRIPTION = "ports_description"