@@ -10,7 +10,7 @@ import { configureSwingMode } from './characteristic/SwingMode';
1010const SCHEMA_CODE = {
1111 FAN_ON : [ 'switch_fan' , 'fan_switch' , 'switch' ] ,
1212 FAN_DIRECTION : [ 'fan_direction' ] ,
13- FAN_SPEED : [ 'fan_speed' ] ,
13+ FAN_SPEED : [ 'fan_speed' , 'fan_speed_percent' ] ,
1414 FAN_SPEED_LEVEL : [ 'fan_speed_enum' , 'fan_speed' ] ,
1515 FAN_LOCK : [ 'child_lock' ] ,
1616 FAN_SWING : [ 'switch_horizontal' , 'switch_vertical' ] ,
@@ -29,13 +29,12 @@ export default class FanAccessory extends BaseAccessory {
2929
3030 configureServices ( ) {
3131
32- const serviceType = this . fanServiceType ( ) ;
33- if ( serviceType === this . Service . Fan ) {
32+ if ( this . fanServiceType ( ) === this . Service . Fan ) {
3433 const unusedService = this . accessory . getService ( this . Service . Fanv2 ) ;
3534 unusedService && this . accessory . removeService ( unusedService ) ;
3635
3736 configureOn ( this , this . fanService ( ) , this . getSchema ( ...SCHEMA_CODE . FAN_ON ) ) ;
38- } else if ( serviceType === this . Service . Fanv2 ) {
37+ } else if ( this . fanServiceType ( ) === this . Service . Fanv2 ) {
3938 const unusedService = this . accessory . getService ( this . Service . Fan ) ;
4039 unusedService && this . accessory . removeService ( unusedService ) ;
4140
@@ -57,19 +56,21 @@ export default class FanAccessory extends BaseAccessory {
5756
5857 // Light
5958 if ( this . getSchema ( ...SCHEMA_CODE . LIGHT_ON ) ) {
60- configureLight (
61- this ,
62- this . lightService ( ) ,
63- this . getSchema ( ...SCHEMA_CODE . LIGHT_ON ) ,
64- this . getSchema ( ...SCHEMA_CODE . LIGHT_BRIGHT ) ,
65- this . getSchema ( ...SCHEMA_CODE . LIGHT_TEMP ) ,
66- this . getSchema ( ...SCHEMA_CODE . LIGHT_COLOR ) ,
67- this . getSchema ( ...SCHEMA_CODE . LIGHT_MODE ) ,
68- ) ;
69- } else {
70- this . log . warn ( 'Remove Lightbulb Service...' ) ;
71- const unusedService = this . accessory . getService ( this . Service . Lightbulb ) ;
72- unusedService && this . accessory . removeService ( unusedService ) ;
59+ if ( this . lightServiceType ( ) === this . Service . Lightbulb ) {
60+ configureLight (
61+ this ,
62+ this . lightService ( ) ,
63+ this . getSchema ( ...SCHEMA_CODE . LIGHT_ON ) ,
64+ this . getSchema ( ...SCHEMA_CODE . LIGHT_BRIGHT ) ,
65+ this . getSchema ( ...SCHEMA_CODE . LIGHT_TEMP ) ,
66+ this . getSchema ( ...SCHEMA_CODE . LIGHT_COLOR ) ,
67+ this . getSchema ( ...SCHEMA_CODE . LIGHT_MODE ) ,
68+ ) ;
69+ } else if ( this . lightServiceType ( ) === this . Service . Switch ) {
70+ configureOn ( this , undefined , this . getSchema ( ...SCHEMA_CODE . LIGHT_ON ) ) ;
71+ const unusedService = this . accessory . getService ( this . Service . Lightbulb ) ;
72+ unusedService && this . accessory . removeService ( unusedService ) ;
73+ }
7374 }
7475 }
7576
@@ -87,6 +88,16 @@ export default class FanAccessory extends BaseAccessory {
8788 || this . accessory . addService ( serviceType ) ;
8889 }
8990
91+ lightServiceType ( ) {
92+ if ( this . getSchema ( ...SCHEMA_CODE . LIGHT_BRIGHT )
93+ || this . getSchema ( ...SCHEMA_CODE . LIGHT_TEMP )
94+ || this . getSchema ( ...SCHEMA_CODE . LIGHT_COLOR )
95+ || this . getSchema ( ...SCHEMA_CODE . LIGHT_MODE ) ) {
96+ return this . Service . Lightbulb ;
97+ }
98+ return this . Service . Switch ;
99+ }
100+
90101 lightService ( ) {
91102 return this . accessory . getService ( this . Service . Lightbulb )
92103 || this . accessory . addService ( this . Service . Lightbulb ) ;
0 commit comments