@@ -94,38 +94,57 @@ describe("Extension: HomeAssistant", () => {
9494 } ) ;
9595
9696 it ( "Should discover weekly_schedule sensor with json_attributes instead of truncated value" , ( ) => {
97- // Create a mock device with weekly_schedule exposed
98- const mockDeviceWithWeeklySchedule = {
99- definition : {
100- model : "TRVZB" ,
101- vendor : "SONOFF" ,
102- description : "Test TRV with weekly schedule" ,
103- } ,
104- isDevice : ( ) : boolean => true ,
105- isGroup : ( ) : boolean => false ,
106- options : { } ,
107- exposes : ( ) : unknown [ ] => [
108- {
109- type : "composite" ,
110- property : "weekly_schedule" ,
111- name : "weekly_schedule" ,
112- features : [
113- { type : "text" , property : "sunday" , name : "sunday" , access : 7 } ,
114- { type : "text" , property : "monday" , name : "monday" , access : 7 } ,
115- { type : "text" , property : "tuesday" , name : "tuesday" , access : 7 } ,
116- { type : "text" , property : "wednesday" , name : "wednesday" , access : 7 } ,
117- { type : "text" , property : "thursday" , name : "thursday" , access : 7 } ,
118- { type : "text" , property : "friday" , name : "friday" , access : 7 } ,
119- { type : "text" , property : "saturday" , name : "saturday" , access : 7 } ,
120- ] ,
121- access : 7 ,
122- } ,
123- ] ,
124- zh : { endpoints : [ ] } ,
125- } ;
97+ // Create a SONOFF TRVZB expose definition with schedule (composite type)
98+ const trvzbExposes = [
99+ {
100+ type : "climate" ,
101+ features : [
102+ {
103+ name : "occupied_heating_setpoint" ,
104+ property : "occupied_heating_setpoint" ,
105+ type : "numeric" ,
106+ access : 7 ,
107+ value_min : 4 ,
108+ value_max : 35 ,
109+ value_step : 0.5 ,
110+ } ,
111+ { name : "local_temperature" , property : "local_temperature" , type : "numeric" , access : 5 } ,
112+ { name : "system_mode" , property : "system_mode" , type : "enum" , access : 7 , values : [ "off" , "auto" , "heat" ] } ,
113+ { name : "running_state" , property : "running_state" , type : "enum" , access : 5 , values : [ "idle" , "heat" ] } ,
114+ ] ,
115+ } ,
116+ {
117+ type : "composite" ,
118+ name : "schedule" ,
119+ property : "weekly_schedule" ,
120+ label : "Schedule" ,
121+ access : 3 ,
122+ category : "config" ,
123+ features : [
124+ { name : "sunday" , property : "sunday" , type : "text" , access : 3 } ,
125+ { name : "monday" , property : "monday" , type : "text" , access : 3 } ,
126+ { name : "tuesday" , property : "tuesday" , type : "text" , access : 3 } ,
127+ { name : "wednesday" , property : "wednesday" , type : "text" , access : 3 } ,
128+ { name : "thursday" , property : "thursday" , type : "text" , access : 3 } ,
129+ { name : "friday" , property : "friday" , type : "text" , access : 3 } ,
130+ { name : "saturday" , property : "saturday" , type : "text" , access : 3 } ,
131+ ] ,
132+ } ,
133+ ] ;
134+
135+ // Create a mock device with TRVZB exposes
136+ const mockDevice = {
137+ definition : { vendor : "SONOFF" , model : "TRVZB" } ,
138+ isDevice : ( ) => true ,
139+ isGroup : ( ) => false ,
140+ options : { ID : "0x1234567890abcdef" } ,
141+ exposes : ( ) => trvzbExposes ,
142+ zh : { endpoints : [ ] } ,
143+ name : "test_trvzb" ,
144+ } ;
126145
127146 // @ts -expect-error private
128- const configs = extension . getConfigs ( mockDeviceWithWeeklySchedule ) ;
147+ const configs = extension . getConfigs ( mockDevice ) ;
129148 const weeklyScheduleConfig = configs . find ( ( c ) => c . object_id === "weekly_schedule" ) ;
130149
131150 expect ( weeklyScheduleConfig ) . toBeDefined ( ) ;
@@ -165,7 +184,7 @@ describe("Extension: HomeAssistant", () => {
165184 } ,
166185 {
167186 type : "composite" ,
168- name : "schedule" , // This is the key - "schedule", not "weekly_schedule"
187+ name : "schedule" ,
169188 property : "weekly_schedule" ,
170189 label : "Schedule" ,
171190 access : 3 ,
@@ -197,7 +216,7 @@ describe("Extension: HomeAssistant", () => {
197216 const configs = extension . getConfigs ( mockDevice ) ;
198217
199218 // Find the schedule sensor config
200- const scheduleConfig = configs . find ( ( c ) => c . object_id === "schedule" || c . object_id === " weekly_schedule") ;
219+ const scheduleConfig = configs . find ( ( c ) => c . object_id === "weekly_schedule" ) ;
201220
202221 expect ( scheduleConfig ) . toBeDefined ( ) ;
203222 expect ( scheduleConfig . type ) . toBe ( "sensor" ) ;
0 commit comments