-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Workaround IKEA bulbs freezing during a brightness & color transition #8637
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import {Zcl} from 'zigbee-herdsman'; | ||
|
||
import tz from '../converters/toZigbee'; | ||
import {repInterval} from '../lib/constants'; | ||
import { | ||
addCustomClusterManuSpecificIkeaAirPurifier, | ||
|
@@ -210,6 +211,7 @@ const definitions: DefinitionWithExtend[] = [ | |
vendor: 'IKEA', | ||
description: 'TRADFRI bulb B22, white spectrum, globe, opal, 1055 lm', | ||
extend: [addCustomClusterManuSpecificIkeaUnknown(), ikeaLight({colorTemp: true}), m.identify()], | ||
toZigbee: [tz.ikea_bulb_unfreeze], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could specify different unfreeze mechanisms in the future (as in the original code), but I only have this one bulb type to test with, so I'm just changing this for now |
||
}, | ||
// #endregion E26/E27/B22 | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import * as semver from 'semver'; | ||
|
||
import {Zcl} from 'zigbee-herdsman'; | ||
import {Endpoint, Group} from 'zigbee-herdsman/dist/controller/model'; | ||
|
||
import tz from '../converters/toZigbee'; | ||
import * as constants from '../lib/constants'; | ||
|
@@ -812,3 +813,66 @@ export function addCustomClusterManuSpecificIkeaUnknown(): ModernExtend { | |
commandsResponse: {}, | ||
}); | ||
} | ||
|
||
type UnfreezeMechanism = () => Promise<void>; | ||
|
||
export const unfreezeMechanisms: { | ||
[key: string]: UnfreezeMechanism; | ||
} = { | ||
// WS lights: | ||
// Aborts the color transition midway: light will stay at the intermediary | ||
// state it was when it received the command. | ||
// Color lights: | ||
// Do not support this command. | ||
moveColorTemp: async function (this: {entity: Endpoint | Group}) { | ||
await this.entity.command('lightingColorCtrl', 'moveColorTemp', {rate: 1, movemode: 0, minimum: 0, maximum: 600}, {}); | ||
}, | ||
|
||
// WS lights: | ||
// Same as 'moveColorTemp'. | ||
// Color lights: | ||
// Finishes the color transition instantly: light will instantly | ||
// "fast forward" to the final state, post-transition. | ||
genLevelCtrl: async function (this: {entity: Endpoint | Group}) { | ||
await this.entity.command('genLevelCtrl', 'stop', {}, {}); | ||
}, | ||
}; | ||
|
||
const willFreeze = (clusterKey: string, payload: KeyValue): payload is KeyValue & {transtime: number} => | ||
payload && | ||
// any color command with a transition will freeze the light... | ||
typeof payload.transtime === 'number' && | ||
payload.transtime > 0 && | ||
clusterKey == 'lightingColorCtrl' && | ||
// ...except for 'stop' commands: | ||
payload.rate != 1 && | ||
payload.movemode != 0; | ||
|
||
export class UnfreezeSupport { | ||
readonly entity: Endpoint | Group; | ||
readonly unfreeze: UnfreezeMechanism; | ||
|
||
constructor(entity: Endpoint | Group, mechanism: UnfreezeMechanism) { | ||
this.entity = entity; | ||
this.unfreeze = mechanism; | ||
} | ||
|
||
async command(clusterKey: string, commandKey: string, payload: KeyValue, options: KeyValue) { | ||
const frozenUtil = globalStore.getValue(this.entity, 'frozenUntil'); | ||
if (frozenUtil != null) { | ||
if (Date.now() <= frozenUtil) { | ||
console.log('Light is frozen, will attempt to unfreeze'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This (and below) will be changed to a proper logger call |
||
await this.unfreeze(); | ||
} | ||
globalStore.clearValue(this.entity, 'frozenUntil'); | ||
} | ||
const returnValue = await this.entity.command(clusterKey, commandKey, payload, options); | ||
if (willFreeze(clusterKey, payload)) { | ||
const millis = payload.transtime * 100; | ||
const frozenUntil = Date.now() + millis; | ||
globalStore.putValue(this.entity, 'frozenUntil', frozenUntil); | ||
console.log('Command', clusterKey + '.' + commandKey, payload, options, 'will freeze the light until', frozenUntil); | ||
} | ||
return returnValue; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like vendor-specific imports shouldn't be here and the logic from
../lib/ikea
should be inlined into theikea_bulb_unfreeze
converter below