Skip to content

Commit

Permalink
chore(#88): pr review formatting and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyhage committed Jan 1, 2024
1 parent d95d0d7 commit 5167427
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

See the [roadmap](https://homebridge-alexa-smarthome.canny.io/) for up-to-date, unreleased work in progress.

## [2.0.7] - 2024-01-01

### Fixed

- Another attempt to fix bug introduced in 2.0.4 for set thermostat mode.

## [2.0.6] - 2023-12-29

### Added
Expand Down Expand Up @@ -149,7 +155,8 @@ See the [roadmap](https://homebridge-alexa-smarthome.canny.io/) for up-to-date,

- Support for outlets i.e. smart plugs.

[unreleased]: https://github.com/joeyhage/homebridge-spotify-speaker/compare/v2.0.6...HEAD
[unreleased]: https://github.com/joeyhage/homebridge-spotify-speaker/compare/v2.0.7...HEAD
[2.0.7]: https://github.com/joeyhage/homebridge-spotify-speaker/compare/v2.0.6...v2.0.7
[2.0.6]: https://github.com/joeyhage/homebridge-spotify-speaker/compare/v2.0.5...v2.0.6
[2.0.5]: https://github.com/joeyhage/homebridge-spotify-speaker/compare/v2.0.4...v2.0.5
[2.0.4]: https://github.com/joeyhage/homebridge-spotify-speaker/compare/v2.0.3...v2.0.4
Expand Down
47 changes: 34 additions & 13 deletions src/accessory/thermostat-accessory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {
pipe,
} from 'fp-ts/lib/function';
import { CharacteristicValue, Service } from 'homebridge';
import {CapabilityState, SupportedActionsType, SupportedNamespacesType} from '../domain/alexa';
import {
CapabilityState,
SupportedActionsType,
SupportedNamespacesType,
} from '../domain/alexa';
import {
ThermostatNamespaces,
ThermostatNamespacesType,
Expand All @@ -24,7 +28,7 @@ import {
TemperatureScale,
isTemperatureValue,
} from '../domain/alexa/temperature';
import {SwitchState} from '../domain/alexa/switch';
import { SwitchState } from '../domain/alexa/switch';
import * as mapper from '../mapper/power-mapper';

export default class ThermostatAccessory extends BaseAccessory {
Expand Down Expand Up @@ -137,11 +141,15 @@ export default class ThermostatAccessory extends BaseAccessory {
try {
isDeviceOn = this.isPowerSupported ? await this.handlePowerGet() : true;
} catch (e) {
this.logWithContext('debug', 'Skipping power-related logic for unsupported devices', 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 @@ -152,17 +160,20 @@ export default class ThermostatAccessory extends BaseAccessory {
namespace === alexaNamespace && name === alexaValueName,
),
),
O.map(({ value }) => isDeviceOn ? 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}`)),
O.of(this.logWithContext('debug', `Get target state result: ${s}`)),
),
);

return pipe(
this.getState(determineTargetState),
TE.match((e) => {
this.logWithContext('errorT', 'Get thermostat mode', e);
this.logWithContext('errorT', 'Get target state', e);
throw this.serviceCommunicationError;
}, identity),
)();
Expand All @@ -178,38 +189,48 @@ export default class ThermostatAccessory extends BaseAccessory {
try {
isDeviceOn = this.isPowerSupported ? await this.handlePowerGet() : true;
} catch (e) {
this.logWithContext('debug', 'Skipping power-related logic for unsupported devices', e);
this.logWithContext(
'debug',
'Skipping power-related logic for unsupported devices',
e,
);
this.isPowerSupported = false;
isDeviceOn = true;
}

if(value === 0 && this.isPowerSupported) {
if (value === 0 && this.isPowerSupported) {
await this.handlePowerSet(false);
this.updateCacheValue({
value: tstatMapper.mapHomekitModeToAlexa(value, this.Characteristic),
namespace: 'Alexa.ThermostatController',
name: 'thermostatMode',
});
} else {
if (!isDeviceOn){
if (!isDeviceOn) {
await this.handlePowerSet(true);
} else {
return pipe(
this.platform.alexaApi.setDeviceState(
this.device.id,
'setThermostatMode',
{
'thermostatMode.value': tstatMapper.mapHomekitModeToAlexa(value, this.Characteristic),
'thermostatMode.value': tstatMapper.mapHomekitModeToAlexa(
value,
this.Characteristic,
),
},
),
TE.match(
(e) => {
this.logWithContext('errorT', 'Set mode error', e);
this.logWithContext('errorT', 'Set target state error', e);
throw this.serviceCommunicationError;
},
() => {
this.updateCacheValue({
value: tstatMapper.mapHomekitModeToAlexa(value, this.Characteristic),
value: tstatMapper.mapHomekitModeToAlexa(
value,
this.Characteristic,
),
namespace: 'Alexa.ThermostatController',
name: 'thermostatMode',
});
Expand Down

0 comments on commit 5167427

Please sign in to comment.