From 8504b729a76e066c9e6c9c4951c19e9c291484d6 Mon Sep 17 00:00:00 2001 From: Mark Steward Date: Sun, 22 Dec 2024 14:45:30 +0000 Subject: [PATCH] Preserve netmask if one isn't supplied in address --- src/data/hassio/network.ts | 9 ++++----- src/panels/config/network/supervisor-network.ts | 8 +++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/data/hassio/network.ts b/src/data/hassio/network.ts index afe8b920f7d7..51cd6b8e3730 100644 --- a/src/data/hassio/network.ts +++ b/src/data/hassio/network.ts @@ -117,11 +117,10 @@ export const accesspointScan = async ( }; export const parseAddress = (address: string) => { - const isIPv6 = address.includes(":"); - const [ip, cidr] = address.includes("/") - ? address.split("/") - : [address, isIPv6 ? "64" : "24"]; - return { ip, mask: cidrToNetmask(cidr, isIPv6) }; + const [ip, cidr] = address.split("/"); + const isIPv6 = ip.includes(":"); + const mask = cidr ? cidrToNetmask(cidr, isIPv6) : null; + return { ip, mask }; }; export const formatAddress = (ip: string, mask: string) => diff --git a/src/panels/config/network/supervisor-network.ts b/src/panels/config/network/supervisor-network.ts index 22b23188c6c9..50f3afbe98f0 100644 --- a/src/panels/config/network/supervisor-network.ts +++ b/src/panels/config/network/supervisor-network.ts @@ -655,8 +655,14 @@ export class HassioNetwork extends LitElement { this._dirty = true; if (id === "address") { const index = (ev.target as any).index as number; + const { mask: oldMask } = parseAddress( + this._interface![version]!.address![index] + ); const { mask } = parseAddress(value); - this._interface[version]!.address![index] = formatAddress(value, mask); + this._interface[version]!.address![index] = formatAddress( + value, + mask || oldMask || "" + ); this.requestUpdate("_interface"); } else if (id === "netmask") { const index = (ev.target as any).index as number;