Closed ZyroBlue closed 2 months ago
Thanks for the report. I can see what the issue is. It occurs if your config.json
doesn't specify a configuration for a particular appliance.
This crept in due to VSCode auto-fixing eslint's @typescript-eslint/no-unnecessary-condition
rule, which incorrectly assumes that Record<key, value>
types have entries for every key
. I am also using VSCode's source.fixAll.eslint
option which attempts to fix this problem by changing ?.
optional chaining to .
non-optional chaining whenever the source file is saved - without any warning. My testing had the configuration fully-populated, so didn't encounter this problem.
I need to (i) find a way to prevent VSCode from breaking working code like this (preferably without completely disabling the @typescript-eslint/no-unnecessary-condition
rule which has found some real logic errors) and (ii) check for anywhere else that might have been similarly affected. This may take a while...
There appear to be quite a few issues raised against eslint for this problem; all of them rejected, saying that either the Record
type should include undefined
as a possible value (i.e. Record<KeyType, ValueType | undefined>
) or Typescript's noUncheckedIndexedAccess
option should be used. Unfortunately, the former then incorrectly leads eslint to think that it is possible to have a key defined with an undefined
value which breaks a lot of code that iterates over keys, and the latter results in incorrect claims that types have no overlap
and are almost impossible to fix without just suppressing eslint for the problem lines.
I think the best option will be to add undefined
as a possible type where the object's keys aren't enumerated, but that probably won't be a complete fix.
On the plus side, adding undefined as a possible value means that eslint no longer complains about the object[key] ?? default
pattern, which previously required key in object ? object[key] : default
.
Checking the diffs between v0.42.4 and v1.0.0 these are the places where optional chaining operators were removed:
src/api-ua.ts:
- if (body?.length) {
+ if (body.length) {
this.log.debug(`${name} body:`);
--
src/api-value.ts:
- const typeName = props?.find(prop => prop.name === event.event)?.ttype?.name;
+ const typeName = props?.find(prop => prop.name === event.event)?.ttype.name;
if (!typeName) {
--
src/has-programs.ts:
- if (!name?.length) throw new Error("No 'name' field provided for program");
- if (!key?.length) throw new Error("No 'key' field provided for program");
+ if (!name.length) throw new Error("No 'name' field provided for program");
+ if (!key.length) throw new Error("No 'key' field provided for program");
--
src/has-programs.ts:
- const constraints = option?.constraints ?? {};
+ const constraints = option.constraints ?? {};
const allowedValues: string[] = constraints.allowedvalues ?? [];
--
src/homebridge-ui/schema-data.ts
- const findProgram = (key: string) => appliance?.programs.find(p => p.key === key);
+ const findProgram = (key: string): SchemaProgramWithOptions | undefined => appliance.programs.find(p => p.key === key);
appliance.programs = newPrograms.map(program => ({ ...findProgram(program.key), ...program }));
--
src/platform.ts:
- const enabledAppliances = appliances.filter(ha => this.configAppliances[ha.haId]?.enabled ?? true);
+ const enabledAppliances = appliances.filter(ha => this.configAppliances[ha.haId].enabled ?? true);
It looks like all of the other changes were safe.
This should be fixed in v1.0.1.
Thanks again for reporting it, and providing a log that led directly to the problem.
This is insane!
Description of Issue
After updating to 1.0.0., all my devices on the Devices tab are stuck at what they were when I last used the Devices tab. Nothing is being forwarded to HomeKit either. After downgrading, all works perfectly again.
Expected Behaviour
Behaviour from last version.
Steps to Reproduce
Update.
Plugin Version
1.0.0.
Environment
Home Connect Appliance(s)
No response
HomeKit App(s)
No response
Diagnostic Checks
Log File
Configuration
Additional Information
No response