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

fix (#79): skip power state for non supported device for get & set thermostat mode #88

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
21 changes: 15 additions & 6 deletions src/accessory/thermostat-accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export default class ThermostatAccessory extends BaseAccessory {
service: Service;
namespaces = ThermostatNamespaces;
isExternalAccessory = false;
isPowerSupported = true;

configureServices() {
this.service =
Expand Down Expand Up @@ -132,7 +133,15 @@ export default class ThermostatAccessory extends BaseAccessory {
}

async handleTargetStateGet(): Promise<number> {
Copy link
Contributor

@zouma45 zouma45 Jan 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to add the the try catch part for getState indeed, thanks for the update :), looks good to me, I am testing your code on my device too

const powerState = await this.handlePowerGet();
let isDeviceOn: boolean;
try {
isDeviceOn = this.isPowerSupported ? await this.handlePowerGet() : true;
} catch (e) {
this.logWithContext('debug', 'Skipping power-related logic for unsupported devices', e);
this.isPowerSupported = false;
isDeviceOn = true;
}

const alexaNamespace: ThermostatNamespacesType =
'Alexa.ThermostatController';
const alexaValueName = 'thermostatMode';
Expand All @@ -143,7 +152,7 @@ export default class ThermostatAccessory extends BaseAccessory {
namespace === alexaNamespace && name === alexaValueName,
),
),
O.map(({ value }) => powerState ? tstatMapper.mapAlexaModeToHomeKit(value, this.Characteristic): tstatMapper.mapAlexaModeToHomeKit(0, this.Characteristic),
O.map(({ value }) => isDeviceOn ? tstatMapper.mapAlexaModeToHomeKit(value, this.Characteristic): tstatMapper.mapAlexaModeToHomeKit(0, this.Characteristic),
),
O.tap((s) =>
O.of(this.logWithContext('debug', `Get thermostat mode result: ${s}`)),
Expand All @@ -166,15 +175,15 @@ export default class ThermostatAccessory extends BaseAccessory {
}

let isDeviceOn: boolean;
let isPowerSupported = true;
try {
isDeviceOn = await this.handlePowerGet();
isDeviceOn = this.isPowerSupported ? await this.handlePowerGet() : true;
} catch (e) {
this.logWithContext('debug', 'Skipping power-related logic for unsupported devices', e);
this.isPowerSupported = false;
isDeviceOn = true;
isPowerSupported = false;
}
if(value === 0 && isPowerSupported) {

if(value === 0 && this.isPowerSupported) {
await this.handlePowerSet(false);
this.updateCacheValue({
value: tstatMapper.mapHomekitModeToAlexa(value, this.Characteristic),
Expand Down