1515 CONF_CO2_OFFSET , CONF_PM25_OFFSET , CONF_PM10_OFFSET ,
1616 CONF_NOISE_OFFSET , CONF_TVOC_OFFSET , CONF_TVOC_INDEX_OFFSET ,
1717 CONF_POWER_OFF_TIME , CONF_DISPLAY_OFF_TIME , CONF_NIGHT_MODE_START_TIME , CONF_NIGHT_MODE_END_TIME ,
18- CONF_AUTO_SLIDING_TIME , CONF_SCREENSAVER_TYPE ,
18+ CONF_AUTO_SLIDING_TIME , CONF_SCREENSAVER_TYPE , CONF_TIMEZONE ,
1919 DEFAULT_SENSOR_OFFSET
2020)
2121
@@ -59,10 +59,11 @@ async def async_setup_entry(
5959 ])
6060 elif model == "CGDN1" :
6161 entities .extend ([
62- # QingpingCGSxTimeNumber(coordinator, config_entry, mac, name, "Power Off Time", CONF_POWER_OFF_TIME, device_info, 0, 60, 1, 30, "minutes"),
63- # QingpingCGSxTimeNumber(coordinator, config_entry, mac, name, "Display Off Time", CONF_DISPLAY_OFF_TIME, device_info, 0, 300, 1, 30, "seconds"),
64- QingpingCGSxTimeNumber (coordinator , config_entry , mac , name , "Auto Sliding Time" , CONF_AUTO_SLIDING_TIME , device_info , 0 , 180 , 5 , 30 , "seconds" ),
62+ QingpingCGSxTimeNumber (coordinator , config_entry , mac , name , "Power Off Time" , CONF_POWER_OFF_TIME , device_info , 0 , 60 , 1 , 30 , "minutes" , NumberMode . SLIDER ),
63+ QingpingCGSxTimeNumber (coordinator , config_entry , mac , name , "Display Off Time" , CONF_DISPLAY_OFF_TIME , device_info , 0 , 300 , 1 , 30 , "seconds" , NumberMode . SLIDER ),
64+ QingpingCGSxTimeNumber (coordinator , config_entry , mac , name , "Auto Sliding Time" , CONF_AUTO_SLIDING_TIME , device_info , 0 , 180 , 5 , 30 , "seconds" , NumberMode . SLIDER ),
6565 QingpingCGSxScreensaverTypeNumber (coordinator , config_entry , mac , name , device_info ),
66+ QingpingCGSxTimezoneNumber (coordinator , config_entry , mac , name , device_info ),
6667 ])
6768
6869 async_add_entities (entities )
@@ -245,7 +246,7 @@ def _handle_coordinator_update(self) -> None:
245246class QingpingCGSxTimeNumber (CoordinatorEntity , NumberEntity ):
246247 """Representation of a Qingping CGSx time setting number input."""
247248
248- def __init__ (self , coordinator , config_entry , mac , name , time_name , time_key , device_info , min_val , max_val , step , default_val , unit ):
249+ def __init__ (self , coordinator , config_entry , mac , name , time_name , time_key , device_info , min_val , max_val , step , default_val , unit , mode = NumberMode . BOX ):
249250 """Initialize the number entity."""
250251 super ().__init__ (coordinator )
251252 self ._config_entry = config_entry
@@ -260,6 +261,7 @@ def __init__(self, coordinator, config_entry, mac, name, time_name, time_key, de
260261 self ._attr_native_step = step
261262 self ._attr_entity_category = EntityCategory .CONFIG
262263 self ._attr_native_unit_of_measurement = unit
264+ self ._attr_mode = mode
263265
264266 @property
265267 def native_value (self ) -> int :
@@ -342,4 +344,55 @@ def _handle_coordinator_update(self) -> None:
342344 """Handle updated data from the coordinator."""
343345 if CONF_SCREENSAVER_TYPE not in self .coordinator .data :
344346 self .coordinator .data [CONF_SCREENSAVER_TYPE ] = self ._config_entry .data .get (CONF_SCREENSAVER_TYPE , 1 )
347+ self .async_write_ha_state ()
348+
349+ class QingpingCGSxTimezoneNumber (CoordinatorEntity , NumberEntity ):
350+ """Representation of a Qingping CGSx timezone setting number input."""
351+
352+ def __init__ (self , coordinator , config_entry , mac , name , device_info ):
353+ """Initialize the number entity."""
354+ super ().__init__ (coordinator )
355+ self ._config_entry = config_entry
356+ self ._mac = mac
357+ self ._attr_name = f"{ name } Time Zone"
358+ self ._attr_unique_id = f"{ mac } _timezone"
359+ self ._attr_device_info = device_info
360+ self ._attr_native_min_value = - 12
361+ self ._attr_native_max_value = 14
362+ self ._attr_native_step = 0.5
363+ self ._attr_entity_category = EntityCategory .CONFIG
364+ self ._attr_mode = NumberMode .BOX
365+
366+ @property
367+ def native_value (self ) -> float :
368+ """Return the current value."""
369+ return self .coordinator .data .get (CONF_TIMEZONE , 0 )
370+
371+ async def async_set_native_value (self , value : float ) -> None :
372+ """Update the current value."""
373+ self .coordinator .data [CONF_TIMEZONE ] = value
374+ self .async_write_ha_state ()
375+
376+ # Update config entry
377+ new_data = dict (self ._config_entry .data )
378+ new_data [CONF_TIMEZONE ] = value
379+ self .hass .config_entries .async_update_entry (self ._config_entry , data = new_data )
380+
381+ await self .coordinator .async_request_refresh ()
382+
383+ # Publish setting change to device (value * 10 for device)
384+ from .sensor import publish_setting_change
385+ device_value = int (value * 10 )
386+ await publish_setting_change (self .hass , self ._mac , CONF_TIMEZONE , device_value )
387+
388+ async def async_added_to_hass (self ) -> None :
389+ """Run when entity about to be added to hass."""
390+ await super ().async_added_to_hass ()
391+ self ._handle_coordinator_update ()
392+
393+ @callback
394+ def _handle_coordinator_update (self ) -> None :
395+ """Handle updated data from the coordinator."""
396+ if CONF_TIMEZONE not in self .coordinator .data :
397+ self .coordinator .data [CONF_TIMEZONE ] = self ._config_entry .data .get (CONF_TIMEZONE , 0 )
345398 self .async_write_ha_state ()
0 commit comments