Skip to content

Commit

Permalink
feat: add temperature sensor for echo devices that support it (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyhage authored Dec 30, 2023
1 parent 91643a8 commit 7b28bc8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion nodemon.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"watch": ["src"],
"ext": "ts",
"ignore": ["src/**/*.it.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"exec": "tsc && homebridge -I -D",
"exec": "tsc -p tsconfig.prod.json && homebridge -I -D",
"signal": "SIGTERM",
"env": {
"NODE_OPTIONS": "--trace-warnings"
Expand Down
32 changes: 31 additions & 1 deletion src/domain/alexa/echo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import * as A from 'fp-ts/Array';
import * as O from 'fp-ts/Option';
import { constFalse, constTrue, constant, pipe } from 'fp-ts/lib/function';
import { Pattern, match } from 'ts-pattern';
import { AlexaSmartHomePlatform } from '../../platform';
import { generateUuid } from '../../util';
import { HomebridgeAccessoryInfo } from '../homebridge';
import { Nullable } from '../index';
import { CapabilityState, SupportedNamespaces } from './index';
import { constFalse, constTrue } from 'fp-ts/lib/function';

const mediaPlayerPattern = {
state: Pattern.string,
Expand Down Expand Up @@ -51,3 +56,28 @@ export interface MediaPlayer {
export interface MediaPlayback extends MediaPlayer {
players: MediaPlayer[];
}

export const toSupportedHomeKitAccessories = (
platform: AlexaSmartHomePlatform,
entityId: string,
deviceName: string,
capStates: CapabilityState[],
): HomebridgeAccessoryInfo[] =>
pipe(
capStates,
A.filterMap((cap) =>
match(cap)
.with({ namespace: 'Alexa.TemperatureSensor' }, () =>
O.of({
altDeviceName: O.of(`${deviceName} temperature`),
deviceType: platform.Service.TemperatureSensor.UUID,
uuid: generateUuid(
platform,
entityId,
platform.Service.TemperatureSensor.UUID,
),
}),
)
.otherwise(constant(O.none)),
),
);
7 changes: 7 additions & 0 deletions src/mapper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import SwitchAccessory from '../accessory/switch-accessory';
import TelevisionAccessory from '../accessory/television-accessory';
import ThermostatAccessory from '../accessory/thermostat-accessory';
import * as airQuality from '../domain/alexa/air-quality-monitor';
import * as echo from '../domain/alexa/echo';
import {
AlexaDeviceError,
InvalidDeviceError,
Expand Down Expand Up @@ -190,6 +191,12 @@ const determineSupportedHomeKitAccessories = (
device.providerData.deviceType,
),
},
...echo.toSupportedHomeKitAccessories(
platform,
entityId,
device.displayName,
platform.deviceStore.getCacheStatesForDevice(entityId),
),
]),
)
.with(['AIR_QUALITY_MONITOR', Pattern._], () =>
Expand Down

0 comments on commit 7b28bc8

Please sign in to comment.