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

Feature: Add "bzyd" White Noise Night Light #510

Merged
merged 8 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions SUPPORTED_DEVICES.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Most category code is pinyin abbreviation of Chinese name.
| Dimmer | 调光器 | tgq | Lightbulb | ✅ | [Documentation](https://developer.tuya.com/en/docs/iot/tgq?id=Kaof8ke9il4k4) |
| Remote Control | 遥控器 | ykq | | | [Documentation](https://developer.tuya.com/en/docs/iot/ykq?id=Kaof8ljn81aov) |
| Spotlight | 射灯 | sxd | Lightbulb | ✅ | [Documentation](https://developer.tuya.com/en/docs/iot/sxd?id=Kb7jayalltstu) |
| White Noise Light | 白噪音灯 | bzyd | Lightbulb<br> Switch | ✅ | Documentation |


## Electrical Products
Expand Down
4 changes: 4 additions & 0 deletions src/accessory/AccessoryFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import VibrationSensorAccessory from './VibrationSensorAccessory';
import WeatherStationAccessory from './WeatherStationAccessory';
import DoorbellAccessory from './DoorbellAccessory';
import PetFeederAccessory from './PetFeederAccessory';
import WhiteNoiseLightAccessory from './WhiteNoiseLightAccessory';


export default class AccessoryFactory {
Expand Down Expand Up @@ -91,6 +92,9 @@ export default class AccessoryFactory {
case 'cjkg':
handler = new SceneSwitchAccessory(platform, accessory);
break;
case 'bzyd':
handler = new WhiteNoiseLightAccessory(platform, accessory);
break;

// Large Home Appliances
case 'kt':
Expand Down
70 changes: 70 additions & 0 deletions src/accessory/WhiteNoiseLightAccessory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import BaseAccessory from './BaseAccessory';
import { configureOn } from './characteristic/On';
import { configureLight } from './characteristic/Light';

const SCHEMA_CODE = {
LIGHT_ON: ['switch_led'],
LIGHT_COLOR: ['colour_data'],
MUSIC_ON: ['switch_music'],
};

export default class WhiteNoiseLightAccessory extends BaseAccessory {
requiredSchema() {
return [SCHEMA_CODE.LIGHT_ON, SCHEMA_CODE.MUSIC_ON];
}

configureServices() {
// Light
if (this.lightServiceType() === this.Service.Lightbulb) {
configureLight(
this,
this.lightService(),
this.getSchema(...SCHEMA_CODE.LIGHT_ON),
undefined,
undefined,
this.lightColorSchema(),
undefined,
);
} else if (this.lightServiceType() === this.Service.Switch) {
configureOn(this, undefined, this.getSchema(...SCHEMA_CODE.LIGHT_ON));
const unusedService = this.accessory.getService(this.Service.Lightbulb);
unusedService && this.accessory.removeService(unusedService);
}

// White Noise
configureOn(this, undefined, this.getSchema(...SCHEMA_CODE.MUSIC_ON));
}

lightColorSchema() {
const colorSchema = this.getSchema(...SCHEMA_CODE.LIGHT_COLOR);
if (!colorSchema) {
return;
}

const { h, s, v } = (colorSchema.property || {}) as never;
if (!h || !s || !v) {
// Set sensible defaults for missing properties
colorSchema.property = {
h: { min: 0, scale: 0, unit: '', max: 360, step: 1 },
s: { min: 0, scale: 0, unit: '', max: 1000, step: 1 },
v: { min: 0, scale: 0, unit: '', max: 1000, step: 1 },
};
}

return colorSchema;
}

lightServiceType() {
if (this.lightColorSchema()) {
return this.Service.Lightbulb;
}
return this.Service.Switch;
}

lightService() {
return (
this.accessory.getService(this.Service.Lightbulb) ||
this.accessory.addService(this.Service.Lightbulb)
);
}
}
Loading