Skip to content

Commit

Permalink
use boolean for update
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaskalov committed Oct 30, 2024
1 parent c4dc9ff commit 65f7fd7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 16 deletions.
14 changes: 4 additions & 10 deletions src/tasmotaCharacteristic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,10 @@ export type Mapping = {
to: CharacteristicValue
}[];

export enum ValueUpdate {
OnChange,
Always,
Never,
}

export type TasmotaResponse = {
topic?: string;
path?: string;
update?: ValueUpdate
update?: boolean;
shared?: boolean;
}

Expand Down Expand Up @@ -95,7 +89,7 @@ export class TasmotaCharacteristic {
this.characteristic.onSet(this.onSet.bind(this));
}
// stat path defaults to get.res.path if not set
if (definition.stat?.update !== ValueUpdate.Never) {
if (definition.stat?.update !== false) {
const topic = this.replaceTemplate(definition.stat?.topic || '{stat}/RESULT');
const path = definition.stat?.path || definition.get?.res?.path || definition.get?.cmd;
if (path !== undefined) {
Expand Down Expand Up @@ -191,8 +185,8 @@ export class TasmotaCharacteristic {
const hbValue = this.checkHBValue(this.mapToHB(value));
if (hbValue !== undefined) {
const prevValue = this.value;
const getUpdateAlways = this.definition.get?.res?.update === ValueUpdate.Always;
const updateAlways = this.definition.stat?.update === ValueUpdate.Always;
const getUpdateAlways = this.definition.get?.res?.update === true;
const updateAlways = this.definition.stat?.update === true;
const update = (hbValue !== prevValue) || updateAlways || getUpdateAlways;
if (update) {
this.service.getCharacteristic(this.platform.Characteristic[this.name]).updateValue(hbValue);
Expand Down
11 changes: 5 additions & 6 deletions src/tasmotaDeviceTypes.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@

import { TasmotaDeviceDefinition } from './tasmotaAccessory';
import { ValueUpdate } from './tasmotaCharacteristic';

export const ACCESSORY_INFORMATION: TasmotaDeviceDefinition = {
AccessoryInformation: {
Manufacturer: {
get: {cmd: 'MODULE0', res: {path: 'Module.0'}},
stat: {update: ValueUpdate.Never},
stat: {update: false},
default: 'Tasmota',
},
Model: {
get: {cmd: 'DeviceName'},
stat: {update: ValueUpdate.Never},
stat: {update: false},
default: 'Unknown',
},
SerialNumber: {
get: {cmd: 'STATUS 5', res: {topic: '{stat}/STATUS5', path: 'StatusNET.Mac'}},
stat: {update: ValueUpdate.Never},
stat: {update: false},
default: 'Unknown',
},
FirmwareRevision: {
get: {cmd: 'STATUS 2', res: {topic: '{stat}/STATUS2', path: 'StatusFWR.Version'}},
stat: {update: ValueUpdate.Never},
stat: {update: false},
default: 'Unknown',
},
},
Expand All @@ -39,7 +38,7 @@ export const DEVICE_TYPES: { [key: string] : TasmotaDeviceDefinition } = {
BUTTON: {
StatelessProgrammableSwitch: {
ProgrammableSwitchEvent: {
stat: {path: 'Button{idx}.Action', update: ValueUpdate.Always},
stat: {path: 'Button{idx}.Action', update: true},
mapping: [{from: 'SINGLE', to: 0}, {from: 'DOUBLE', to: 1}, {from: 'HOLD', to: 3}],
},
},
Expand Down

0 comments on commit 65f7fd7

Please sign in to comment.