-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
132 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { z } from 'zod'; | ||
import { putMotorService, type BlindsServiceService, type SlatsServiceService } from '../litecom/restClient/index.js'; | ||
import { Logger } from '../util/logger.js'; | ||
|
||
export interface LitecomBlindsServiceAdapter { | ||
putBlindServiceByZone: (typeof BlindsServiceService)['putBlindServiceByZone']; | ||
putBlindsServiceByZoneAndDevice: (typeof BlindsServiceService)['putBlindServiceByZoneAndDevice']; | ||
} | ||
export interface LitecomSlatsServiceAdapter { | ||
putSlatServiceByZone: (typeof SlatsServiceService)['putSlatServiceByZone']; | ||
putSlatServiceByZoneAndDevice: (typeof SlatsServiceService)['putSlatServiceByZoneAndDevice']; | ||
} | ||
|
||
export const CoverCommand = z.discriminatedUnion('command', [ | ||
z.object({ | ||
command: z.literal('move'), | ||
payload: z.union([z.literal('OPEN'), z.literal('CLOSE'), z.literal('STOP')]), | ||
}), | ||
]); | ||
type CoverCommand = z.infer<typeof CoverCommand>; | ||
|
||
export class CoverServiceMQTTHandler { | ||
constructor( | ||
private readonly blindsLitecomAdapter: LitecomBlindsServiceAdapter, | ||
private readonly slatsLitecomAdapter: LitecomSlatsServiceAdapter, | ||
private readonly log: Logger, | ||
) {} | ||
|
||
async handleZoneCommand(zoneId: string, { command, payload }: CoverCommand): Promise<void> { | ||
switch (command) { | ||
case 'move': { | ||
await this.blindsLitecomAdapter.putBlindServiceByZone(zoneId, { | ||
command: payload as putMotorService.command, // cast should be fine. HomeAssistantCoverEntity announces this enums' values to Home Assistant as payloads | ||
}); | ||
} | ||
} | ||
} | ||
|
||
async handleDeviceCommand(zoneId: string, deviceId: string, { command, payload }: CoverCommand): Promise<void> { | ||
Check failure on line 39 in src/homeAssistant/coverServiceMqttHandler.ts GitHub Actions / quality-checks
Check failure on line 39 in src/homeAssistant/coverServiceMqttHandler.ts GitHub Actions / quality-checks
Check failure on line 39 in src/homeAssistant/coverServiceMqttHandler.ts GitHub Actions / quality-checks
|
||
this.log.warning('Not Implemented'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import * as Litecom from '../../litecom/restClient/index.js'; | ||
import { Config, config } from '../../util/config.js'; | ||
import { DataPointType, HomeAssistantEntity, HomeAssistantEntityType } from './homeAssistantEntity.js'; | ||
|
||
/** | ||
* @see https://www.home-assistant.io/integrations/cover.mqtt/ | ||
*/ | ||
export class HomeAssistantCoverEntity extends HomeAssistantEntity { | ||
override readonly homeAssistantEntityType: HomeAssistantEntityType = 'cover'; | ||
override readonly dataPointType: DataPointType = 'cover'; | ||
|
||
constructor( | ||
config: Config, | ||
private readonly hasBlinds: boolean, | ||
private readonly hasSlats: boolean, | ||
zone: Litecom.Zone, | ||
device?: Litecom.Device, | ||
) { | ||
super(config, zone, device); | ||
} | ||
|
||
override get homeAssistantCommandTopics(): Record<string, string> { | ||
if (this.device) { | ||
return { | ||
command_topic: `${config.LITECOM2MQTT_MQTT_TOPIC_PREFIX}/${this.zone.id}/evices/${this.objectId}/${this.dataPointType}/move`, | ||
}; | ||
} | ||
return { | ||
command_topic: `${config.LITECOM2MQTT_MQTT_TOPIC_PREFIX}/${this.zone.id}/${this.dataPointType}/move`, | ||
}; | ||
} | ||
|
||
override get homeAssistantEntityConfig(): Record<string, string | number | boolean> { | ||
const shared = { | ||
name: 'Cover', | ||
position_closed: 100.0, | ||
position_open: 0.0, | ||
payload_open: Litecom.putMotorService.command.OPEN, | ||
payload_close: Litecom.putMotorService.command.CLOSE, | ||
payload_stop: Litecom.putMotorService.command.STOP, | ||
}; | ||
|
||
if (this.device) { | ||
return { | ||
...shared, | ||
position_topic: `${config.LITECOM2MQTT_LITECOM_STATE_MQTT_TOPIC_PREFIX}/zones/${this.zone.id}/devices/${this.device.id}/services/blind/position`, | ||
}; | ||
} | ||
|
||
return { | ||
...shared, | ||
position_topic: `${config.LITECOM2MQTT_LITECOM_STATE_MQTT_TOPIC_PREFIX}/zones/${this.zone.id}/services/blind/position`, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters