import { clamp , convertHSLtoRGB } from '../magichome-interface/utils' ; import { HomebridgeMagichomeDynamicPlatformAccessory } from '../platformAccessory' ; export class RGBStrip extends HomebridgeMagichomeDynamicPlatformAccessory { public eightByteProtocol = 2 ; async updateDeviceState ( ) { const hsl = this . lightState . HSL ; const [ red , green , blue ] = convertHSLtoRGB ( hsl ) ; const brightness = this . lightState . brightness ; const mask = 0xF0 ; const r = Math . round ( ( ( clamp ( red , 0 , 255 ) / 100 ) * brightness ) ) ; const g = Math . round ( ( ( clamp ( green , 0 , 255 ) / 100 ) * brightness ) ) ; const b = Math . round ( ( ( clamp ( blue , 0 , 255 ) / 100 ) * brightness ) ) ; if ( this . eightByteProtocol == 0 ) { await this . send ( [ 0x31 , r , g , b , 0x00 , mask , 0x0F ] ) ; } else if ( this . eightByteProtocol == 1 ) { await this . send ( [ 0x31 , r , g , b , 0x00 , 0x00 , mask , 0x0F ] ) ; } else if ( this . eightByteProtocol == 2 ) { this . eightByteProtocol = ( await this . send ( [ 0x31 , r , g , b , 0x00 , 0x00 , mask , 0x0F ] ) ) == undefined ? 0 : 1 ; await this . send ( [ 0x31 , r , g , b , 0x00 , mask , 0x0F ] ) ; } } }