From fba89d2cfff0e9e114a19ba33d43489dd53b3cf9 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 | 3 ++- 2 files changed, 6 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..615a828f48d3 100644 --- a/src/panels/config/network/supervisor-network.ts +++ b/src/panels/config/network/supervisor-network.ts @@ -655,8 +655,9 @@ 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;