-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: endpoint device & group members typing #1330
Conversation
src/controller/model/endpoint.ts
Outdated
public getDevice(): Device { | ||
return Device.byIeeeAddr(this.deviceIeeeAddress)!; // XXX: no way for device to not exist? | ||
public getDevice(): Device | undefined { | ||
return Device.byIeeeAddr(this.deviceIeeeAddress); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we just throw an exception when device === undefined
? I'm not sure when exactly this can happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are places where undefined
was being checked against the return value, even though the type didn't allow it, so, I don't think we can just throw.
return Array.from(this._members).filter((e) => e.getDevice()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And how can the device get undefined
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be only if deleted
zigbee-herdsman/src/controller/model/device.ts
Lines 634 to 638 in c9e3fd1
public static byIeeeAddr(ieeeAddr: string, includeDeleted: boolean = false): Device | undefined { | |
Device.loadFromDatabaseIfNecessary(); | |
return includeDeleted ? (Device.deletedDevices.get(ieeeAddr) ?? Device.devices.get(ieeeAddr)) : Device.devices.get(ieeeAddr); | |
} |
endpoint.getDevice()
could potentially be undefined => log error/stack tracegroup._members
required array conversion for use in some places => use array as base instead (with check on add)@Koenkk I'm a little worried that this didn't trip coverage, smells like hidden coverage issues, particularly for
Group
.The
members
getter forGroup
is a little awkward. It also results in lots of chained calls because more often than not, Z2M will chain the result with some other filters on top. And typing is crappy too, becausegetDevice
shouldn't be undefined for resulting items since that's the whole purpose of the getter. See any easy way to change this?