@@ -377,19 +377,22 @@ async def set_hysteresis_humidity_upper_bound(self, upper_bound: float) -> bool:
377377 self ._hysteresis_config .humidity_upper_bound ,
378378 upper_bound ,
379379 )
380- if upper_bound < 1 or upper_bound > 128 :
380+ if upper_bound < 1 or upper_bound > 99 :
381381 raise ValueError (
382- "Invalid humidity upper bound {upper_bound}. It must be between 1 and 128 percent."
382+ f "Invalid humidity upper bound { upper_bound } . It must be between 1 and 99 percent."
383383 )
384- if upper_bound < self ._hysteresis_config .humidity_lower_bound :
384+ if (
385+ self ._hysteresis_config .humidity_lower_bound is not None
386+ and upper_bound < self ._hysteresis_config .humidity_lower_bound
387+ ):
385388 raise ValueError (
386- "Invalid humidity upper bound {upper_bound}. It must be equal or above the lower bound {self._hysteresis_config.humidity_lower_bound}."
389+ f "Invalid humidity upper bound { upper_bound } . It must be equal or above the lower bound { self ._hysteresis_config .humidity_lower_bound } ."
387390 )
388391 if self ._hysteresis_config .humidity_upper_bound == upper_bound :
389392 return False
390393 self ._hysteresis_config = replace (
391394 self ._hysteresis_config ,
392- upper_bound = upper_bound ,
395+ humidity_upper_bound = upper_bound ,
393396 dirty = True ,
394397 )
395398 await self ._sense_configure_update ()
@@ -406,19 +409,22 @@ async def set_hysteresis_humidity_lower_bound(self, lower_bound: float) -> bool:
406409 self ._hysteresis_config .humidity_lower_bound ,
407410 lower_bound ,
408411 )
409- if lower_bound < 1 or lower_bound > 128 :
412+ if lower_bound < 1 or lower_bound > 99 :
410413 raise ValueError (
411- "Invalid humidity lower bound {lower_bound}. It must be between 1 and 128 percent."
414+ f "Invalid humidity lower bound { lower_bound } . It must be between 1 and 99 percent."
412415 )
413- if lower_bound > self ._hysteresis_config .humidity_upper_bound :
416+ if (
417+ self ._hysteresis_config .humidity_upper_bound is not None
418+ and lower_bound > self ._hysteresis_config .humidity_upper_bound
419+ ):
414420 raise ValueError (
415- "Invalid humidity lower bound {lower_bound}. It must be equal or above the lower bound {self._hysteresis_config.humidity_lower_bound}."
421+ f "Invalid humidity lower bound { lower_bound } . It must be equal or above the lower bound { self ._hysteresis_config .humidity_lower_bound } ."
416422 )
417423 if self ._hysteresis_config .humidity_lower_bound == lower_bound :
418424 return False
419425 self ._hysteresis_config = replace (
420426 self ._hysteresis_config ,
421- lower_bound = lower_bound ,
427+ humidity_lower_bound = lower_bound ,
422428 dirty = True ,
423429 )
424430 await self ._sense_configure_update ()
@@ -477,19 +483,22 @@ async def set_hysteresis_temperature_upper_bound(self, upper_bound: float) -> bo
477483 self ._hysteresis_config .temperature_upper_bound ,
478484 upper_bound ,
479485 )
480- if upper_bound < 1 or upper_bound > 128 :
486+ if upper_bound < 1 or upper_bound > 60 :
481487 raise ValueError (
482- "Invalid temperature upper bound {upper_bound}. It must be between 1 and 128 percent ."
488+ f "Invalid temperature upper bound { upper_bound } . It must be between 1 and 60 degrees ."
483489 )
484- if upper_bound < self ._hysteresis_config .temperature_lower_bound :
490+ if (
491+ self ._hysteresis_config .temperature_lower_bound is not None
492+ and upper_bound < self ._hysteresis_config .temperature_lower_bound
493+ ):
485494 raise ValueError (
486- "Invalid temperature upper bound {upper_bound}. It must be equal or above the lower bound {self._hysteresis_config.temperature_lower_bound}."
495+ f "Invalid temperature upper bound { upper_bound } . It must be equal or above the lower bound { self ._hysteresis_config .temperature_lower_bound } ."
487496 )
488497 if self ._hysteresis_config .temperature_upper_bound == upper_bound :
489498 return False
490499 self ._hysteresis_config = replace (
491500 self ._hysteresis_config ,
492- upper_bound = upper_bound ,
501+ temperature_upper_bound = upper_bound ,
493502 dirty = True ,
494503 )
495504 await self ._sense_configure_update ()
@@ -506,19 +515,22 @@ async def set_hysteresis_temperature_lower_bound(self, lower_bound: float) -> bo
506515 self ._hysteresis_config .temperature_lower_bound ,
507516 lower_bound ,
508517 )
509- if lower_bound < 1 or lower_bound > 128 :
518+ if lower_bound < 1 or lower_bound > 60 :
510519 raise ValueError (
511- "Invalid temperature lower bound {lower_bound}. It must be between 1 and 128 percent ."
520+ f "Invalid temperature lower bound { lower_bound } . It must be between 1 and 60 degrees ."
512521 )
513- if lower_bound > self ._hysteresis_config .temperature_upper_bound :
522+ if (
523+ self ._hysteresis_config .temperature_upper_bound is not None
524+ and lower_bound > self ._hysteresis_config .temperature_upper_bound
525+ ):
514526 raise ValueError (
515- "Invalid temperature lower bound {lower_bound}. It must be equal or below the upper bound {self._hysteresis_config.temperature_upper_bound}."
527+ f "Invalid temperature lower bound { lower_bound } . It must be equal or below the upper bound { self ._hysteresis_config .temperature_upper_bound } ."
516528 )
517529 if self ._hysteresis_config .temperature_lower_bound == lower_bound :
518530 return False
519531 self ._hysteresis_config = replace (
520532 self ._hysteresis_config ,
521- lower_bound = lower_bound ,
533+ temperature_lower_bound = lower_bound ,
522534 dirty = True ,
523535 )
524536 await self ._sense_configure_update ()
@@ -614,8 +626,13 @@ async def _run_awake_tasks(self) -> None:
614626 """Execute all awake tasks."""
615627 await super ()._run_awake_tasks ()
616628 if self ._hysteresis_config .dirty :
617- await self ._configure_sense_humidity_task ()
618- await self ._configure_sense_temperature_task ()
629+ configure_result = await gather (
630+ self ._configure_sense_humidity_task (),
631+ self ._configure_sense_temperature_task (),
632+ )
633+ if not all (configure_result ):
634+ self ._hysteresis_config = replace (self ._hysteresis_config , dirty = False )
635+ await self ._sense_configure_update ()
619636
620637 async def _configure_sense_humidity_task (self ) -> bool :
621638 """Configure Sense humidity hysteresis device settings. Returns True if successful."""
@@ -662,8 +679,6 @@ async def _configure_sense_humidity_task(self) -> bool:
662679 _LOGGER .debug (
663680 "Successful configure humidity hysteresis settings for %s" , self .name
664681 )
665- self ._hysteresis_config = replace (self ._hysteresis_config , dirty = False )
666- await self ._sense_configure_update ()
667682 return True
668683
669684 _LOGGER .warning (
@@ -718,8 +733,6 @@ async def _configure_sense_temperature_task(self) -> bool:
718733 _LOGGER .debug (
719734 "Successful configure temperature hysteresis settings for %s" , self .name
720735 )
721- self ._hysteresis_config = replace (self ._hysteresis_config , dirty = False )
722- await self ._sense_configure_update ()
723736 return True
724737
725738 _LOGGER .warning (
0 commit comments