Skip to content
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

Enforce TS strict type checking. #23601

Merged
merged 27 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,735 changes: 885 additions & 850 deletions lib/extension/homeassistant.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib/extension/legacy/bridgeLegacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ export default class BridgeLegacy extends Extension {

async onZigbeeEvent_(type: string, data: KeyValue, resolvedEntity: Device | undefined): Promise<void> {
if (resolvedEntity) {
/* istanbul ignore else */
if (type === 'deviceJoined') {
this.lastJoinedDeviceName = resolvedEntity.name;
await this.mqtt.publish('bridge/log', stringify({type: `device_connected`, message: {friendly_name: resolvedEntity.name}}));
Expand Down
3 changes: 2 additions & 1 deletion lib/extension/legacy/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,11 @@ export default class Report extends Extension {
return true;
}

// These do not support reproting.
// These do not support reporting.
// /~https://github.com/Koenkk/zigbee-herdsman/issues/110
if (
device.zh.manufacturerName === 'Philips' &&
/* istanbul ignore next */
(device.zh.softwareBuildID === '5.127.1.26581' || device.zh.softwareBuildID === '5.130.1.30000')
) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions lib/model/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export default class Device {
get ID(): string {
return this.zh.ieeeAddr;
}
get options(): DeviceOptions {
const deviceOptions = settings.getDevice(this.ieeeAddr) ?? {friendly_name: this.ieeeAddr};
get options(): DeviceOptionsWithId {
const deviceOptions = settings.getDevice(this.ieeeAddr) ?? {friendly_name: this.ieeeAddr, ID: this.ieeeAddr};
return {...settings.get().device_options, ...deviceOptions};
}
get name(): string {
return this.zh.type === 'Coordinator' ? 'Coordinator' : this.options?.friendly_name || this.ieeeAddr;
return this.zh.type === 'Coordinator' ? 'Coordinator' : this.options?.friendly_name;
}
get isSupported(): boolean {
return this.zh.type === 'Coordinator' || Boolean(this.definition && !this.definition.generated);
Expand Down
1 change: 1 addition & 0 deletions lib/model/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default class Group {
const definitions: zhc.Definition[] = [];

for (const member of this.membersDevices()) {
/* istanbul ignore else */
if (member.definition) {
definitions.push(member.definition);
}
Expand Down
28 changes: 18 additions & 10 deletions lib/util/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,24 +378,32 @@ function filterProperties(filter: string[] | undefined, data: KeyValue): void {
}
}

export function isNumericExposeFeature(feature: zhc.Feature): feature is zhc.Numeric {
return feature?.type === 'numeric';
export function isNumericExpose(expose: zhc.Expose): expose is zhc.Numeric {
return expose?.type === 'numeric';
}

export function isEnumExposeFeature(feature: zhc.Feature): feature is zhc.Enum {
return feature?.type === 'enum';
export function assertEnumExpose(expose: zhc.Expose): asserts expose is zhc.Enum {
assert(expose?.type === 'enum');
}

export function isBinaryExposeFeature(feature: zhc.Feature): feature is zhc.Binary {
return feature?.type === 'binary';
export function assertNumericExpose(expose: zhc.Expose): asserts expose is zhc.Numeric {
assert(expose?.type === 'numeric');
}

export function isLightExpose(expose: zhc.Expose): expose is zhc.Light {
return expose.type === 'light';
export function assertBinaryExpose(expose: zhc.Expose): asserts expose is zhc.Binary {
assert(expose?.type === 'binary');
}

export function isEnumExpose(expose: zhc.Expose): expose is zhc.Enum {
return expose?.type === 'enum';
}

export function assertLightExpose(expose: zhc.Expose): asserts expose is zhc.Light {
assert(expose.type === 'light');
export function isBinaryExpose(expose: zhc.Expose): expose is zhc.Binary {
return expose?.type === 'binary';
}

export function isLightExpose(expose: zhc.Expose): expose is zhc.Light {
return expose.type === 'light';
}

function getScenes(entity: zh.Endpoint | zh.Group): Scene[] {
Expand Down
1 change: 1 addition & 0 deletions lib/zigbee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ export default class Zigbee {
// First split the input token by the latest slash
const match = ID.match(entityIDRegex);

/* istanbul ignore else */
if (match) {
// Get the resulting IDs from the match
entityName = match[1];
Expand Down
Loading