This repository has been archived by the owner on Nov 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fan): add support for fans as dimmable switch (#70)
- Loading branch information
Showing
9 changed files
with
147 additions
and
42 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
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
17 changes: 17 additions & 0 deletions
17
packages/home-assistant-matter-hub/src/aspects/utils/noop-fn.ts
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,17 @@ | ||
import { Logger } from 'winston'; | ||
|
||
export function noopFn(logger: Logger, name: string): () => void { | ||
return () => { | ||
logger.warn( | ||
[ | ||
'Matter Command "%s" was called, which is currently not supported.', | ||
'Please create a new issue at https://github.com/t0bst4r/matterbridge-home-assistant/issues and provide as much information as possible:', | ||
' - Which Matter controller (e.g. Alexa, Google Home, Apple Home, Tuya, ...) are you using?', | ||
' - What kind of device produced this warning?', | ||
' - What (voice) command did you use to trigger this log message?', | ||
' - Please provide the relevant log output (this message and some lines before and after this message)', | ||
].join('\n'), | ||
name, | ||
); | ||
}; | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/home-assistant-matter-hub/src/devices/fan-device.ts
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,26 @@ | ||
import { DeviceTypes } from 'matterbridge'; | ||
|
||
import { IdentifyAspect, LevelControlAspect, OnOffAspect } from '@/aspects/index.js'; | ||
import { DeviceBase, DeviceBaseConfig } from '@/devices/device-base.js'; | ||
import { HomeAssistantClient } from '@/home-assistant-client/index.js'; | ||
import { HomeAssistantMatterEntity } from '@/models/index.js'; | ||
|
||
export class FanDevice extends DeviceBase { | ||
constructor(client: HomeAssistantClient, entity: HomeAssistantMatterEntity, config: DeviceBaseConfig) { | ||
super(entity, DeviceTypes.DIMMABLE_PLUGIN_UNIT, config); | ||
|
||
this.addAspect(new IdentifyAspect(this.matter, entity)); | ||
this.addAspect(new OnOffAspect(client, this.matter, entity)); | ||
this.addAspect( | ||
new LevelControlAspect(client, this.matter, entity, { | ||
getValue: (entity) => (entity.attributes.percentage / 100) * 254, | ||
getMinValue: () => 0, | ||
getMaxValue: () => 254, | ||
moveToLevel: { | ||
service: 'fan.set_percentage', | ||
data: (value) => ({ percentage: (value / 254) * 100 }), | ||
}, | ||
}), | ||
); | ||
} | ||
} |
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