@@ -267,19 +267,40 @@ class XEnergyTotal(XSensor):
267267 _attr_state_class = SensorStateClass .TOTAL_INCREASING
268268
269269
270- class XTemperatureNS (XSensor ):
270+ def parse_float (v : int | float | str ):
271+ return float (v ) if isinstance (v , str ) else v
272+
273+
274+ class XTempCorrection (XSensor ):
271275 params = {"temperature" , "tempCorrection" }
272276 uid = "temperature"
273277
274278 def set_state (self , params : dict = None , value : float = None ):
275- if params :
276- # cache updated in XClimateNS entity
277- cache = self .device ["params" ]
278- value = cache ["temperature" ]
279- # fix str https://github.com/AlexxIT/SonoffLAN/issues/1628
279+ try :
280+ if (cache := self .device ["params" ]) != params :
281+ cache .update (params )
282+ value = parse_float (cache ["temperature" ])
280283 if v := cache .get ("tempCorrection" ):
281- value += float (v )
282- XSensor .set_state (self , value = value )
284+ value += parse_float (v )
285+ XSensor .set_state (self , value = value )
286+ except :
287+ pass
288+
289+
290+ class XHumCorrection (XSensor ):
291+ params = {"humidity" , "humCorrection" }
292+ uid = "humidity"
293+
294+ def set_state (self , params : dict = None , value : float = None ):
295+ try :
296+ if (cache := self .device ["params" ]) != params :
297+ cache .update (params )
298+ value = parse_float (cache ["humidity" ])
299+ if v := cache .get ("humCorrection" ):
300+ value += parse_float (v )
301+ XSensor .set_state (self , value = value )
302+ except :
303+ pass
283304
284305
285306class XOutdoorTempNS (XSensor ):
0 commit comments