@@ -2,11 +2,14 @@ import {Zcl} from "zigbee-herdsman";
22
33import * as constants from "../lib/constants" ;
44import * as exposes from "../lib/exposes" ;
5+ import { logger } from "../lib/logger" ;
56import * as m from "../lib/modernExtend" ;
67import * as reporting from "../lib/reporting" ;
78import type { DefinitionWithExtend , Fz , KeyValue , Tz } from "../lib/types" ;
89import * as utils from "../lib/utils" ;
910
11+ const NS = "zhc:amina" ;
12+
1013const e = exposes . presets ;
1114const ea = exposes . access ;
1215
@@ -46,12 +49,33 @@ const aminaAlarms = [
4649] ;
4750
4851const fzLocal = {
52+ poll_energy : {
53+ cluster : "haElectricalMeasurement" ,
54+ type : [ "attributeReport" ] ,
55+ convert : ( model , msg , publish , options , meta ) => {
56+ if ( msg . data . totalActivePower != null ) {
57+ // Device does not support reporting of energy attributes, so we poll them manually when power is updated
58+ msg . endpoint . read ( "aminaControlCluster" , [ "totalActiveEnergy" ] ) . catch ( ( error ) => {
59+ logger . error ( `Failed to poll energy of '${ msg . device . ieeeAddr } ' (${ error } )` , NS ) ;
60+ } ) ;
61+ }
62+ } ,
63+ } satisfies Fz . Converter ,
4964 ev_status : {
5065 cluster : "aminaControlCluster" ,
5166 type : [ "attributeReport" , "readResponse" ] ,
5267 convert : ( model , msg , publish , options , meta ) => {
5368 const result : KeyValue = { } ;
5469
70+ if ( msg . type === "attributeReport" ) {
71+ // Device does not support reporting of energy attributes, so we poll them manually when charging is stopped
72+ if ( ( msg . data . evStatus & ( 1 << 2 ) ) === 0 ) {
73+ msg . endpoint . read ( "aminaControlCluster" , [ "totalActiveEnergy" , "lastSessionEnergy" ] ) . catch ( ( error ) => {
74+ logger . error ( `Failed to poll energy of '${ msg . device . ieeeAddr } ' (${ error } )` , NS ) ;
75+ } ) ;
76+ }
77+ }
78+
5579 if ( msg . data . evStatus !== undefined ) {
5680 let statusText = "Not Connected" ;
5781 const evStatus = msg . data . evStatus ;
@@ -73,7 +97,6 @@ const fzLocal = {
7397 }
7498 } ,
7599 } satisfies Fz . Converter ,
76-
77100 alarms : {
78101 cluster : "aminaControlCluster" ,
79102 type : [ "attributeReport" , "readResponse" ] ,
@@ -106,14 +129,12 @@ const tzLocal = {
106129 await entity . read ( "genLevelCtrl" , [ "currentLevel" ] ) ;
107130 } ,
108131 } satisfies Tz . Converter ,
109-
110132 ev_status : {
111133 key : [ "ev_status" ] ,
112134 convertGet : async ( entity , key , meta ) => {
113135 await entity . read ( "aminaControlCluster" , [ "evStatus" ] , manufacturerOptions ) ;
114136 } ,
115137 } satisfies Tz . Converter ,
116-
117138 alarms : {
118139 key : [ "alarms" ] ,
119140 convertGet : async ( entity , key , meta ) => {
@@ -308,11 +329,9 @@ export const definitions: DefinitionWithExtend[] = [
308329 entityCategory : "config" ,
309330 } ) ,
310331 ] ,
311-
312332 endpoint : ( device ) => {
313333 return { default : 10 } ;
314334 } ,
315-
316335 configure : async ( device , coordinatorEndpoint ) => {
317336 const endpoint = device . getEndpoint ( 10 ) ;
318337
@@ -350,19 +369,5 @@ export const definitions: DefinitionWithExtend[] = [
350369 "lastSessionEnergy" ,
351370 ] ) ;
352371 } ,
353-
354- onEvent : async ( type , data , device ) => {
355- if ( type === "message" && data . type === "attributeReport" && data . cluster === "haElectricalMeasurement" && data . data . totalActivePower ) {
356- // Device does not support reporting of energy attributes, so we poll them manually when power is updated
357- await data . endpoint . read ( "aminaControlCluster" , [ "totalActiveEnergy" ] ) ;
358- }
359-
360- if ( type === "message" && data . type === "attributeReport" && data . cluster === "aminaControlCluster" && data . data . evStatus ) {
361- // Device does not support reporting of energy attributes, so we poll them manually when charging is stopped
362- if ( ( data . data . evStatus & ( 1 << 2 ) ) === 0 ) {
363- await data . endpoint . read ( "aminaControlCluster" , [ "totalActiveEnergy" , "lastSessionEnergy" ] ) ;
364- }
365- }
366- } ,
367372 } ,
368373] ;
0 commit comments