Skip to content

Commit

Permalink
Preserve netmask if one isn't supplied in address
Browse files Browse the repository at this point in the history
  • Loading branch information
marksteward committed Dec 22, 2024
1 parent 523c38a commit fba89d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/data/hassio/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
3 changes: 2 additions & 1 deletion src/panels/config/network/supervisor-network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Check failure on line 660 in src/panels/config/network/supervisor-network.ts

View workflow job for this annotation

GitHub Actions / Lint and check format

Argument of type 'string | null' is not assignable to parameter of type 'string'.
this.requestUpdate("_interface");
} else if (id === "netmask") {
const index = (ev.target as any).index as number;
Expand Down

0 comments on commit fba89d2

Please sign in to comment.