Skip to content

Commit

Permalink
Add default value.
Browse files Browse the repository at this point in the history
  • Loading branch information
mimiqdev committed Nov 22, 2024
1 parent 85fa067 commit 63618df
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions custom_components/madelon_ventilation/fresh_air_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,16 @@ def power(self, state: bool):

@property
def mode(self):
"""获取运行模式"""
return OperationMode(self._get_register_value('mode'))
"""Return the current operation mode."""
value = self._get_register_value('mode')
if value is None:
self.logger.warning("Failed to read mode register.")
return OperationMode.MANUAL # DEFAULT VALUE
try:
return OperationMode(value)
except ValueError:
self.logger.warning(f"Invalid mode value: {value}")
return OperationMode.MANUAL # DEFAULT VALUE

@mode.setter
def mode(self, mode: OperationMode):
Expand Down Expand Up @@ -165,7 +173,7 @@ def temperature(self):
"""获取温度(°C)"""
value = self._get_register_value('temperature')
if value is None:
self.logger.error("Failed to read temperature register.")
self.logger.warning("Failed to read temperature register.")
return 0
return value / 10

Expand All @@ -174,7 +182,7 @@ def humidity(self):
"""获取湿度(%)"""
value = self._get_register_value('humidity')
if value is None:
self.logger.error("Failed to read humidity register.")
self.logger.warning("Failed to read humidity register.")
return 0
return value / 10

Expand Down

0 comments on commit 63618df

Please sign in to comment.