| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 2f24797 commit fe116ea
17 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -284,6 +284,15 @@ def get_preset_rules(params: GetRulesParams | None = None) -> SmartRequest: | |||
| 284 | 284 | """Get preset rules.""" | |
| 285 | 285 | return SmartRequest("get_preset_rules", params or SmartRequest.GetRulesParams()) | |
| 286 | 286 | ||
| 287 | + @staticmethod | ||
| 288 | + def get_on_off_gradually_info( | ||
| 289 | + params: SmartRequestParams | None = None, | ||
| 290 | + ) -> SmartRequest: | ||
| 291 | + """Get preset rules.""" | ||
| 292 | + return SmartRequest( | ||
| 293 | + "get_on_off_gradually_info", params or SmartRequest.SmartRequestParams() | ||
| 294 | + ) | ||
| 295 | + | ||
| 287 | 296 | @staticmethod | |
| 288 | 297 | def get_auto_light_info() -> SmartRequest: | |
| 289 | 298 | """Get auto light info.""" | |
@@ -382,7 +391,7 @@ def get_component_requests(component_id, ver_code): | |||
| 382 | 391 | "auto_light": [SmartRequest.get_auto_light_info()], | |
| 383 | 392 | "light_effect": [SmartRequest.get_dynamic_light_effect_rules()], | |
| 384 | 393 | "bulb_quick_control": [], | |
| 385 | - "on_off_gradually": [SmartRequest.get_raw_request("get_on_off_gradually_info")], | ||
| 394 | + "on_off_gradually": [SmartRequest.get_on_off_gradually_info()], | ||
| 386 | 395 | "light_strip": [], | |
| 387 | 396 | "light_strip_lighting_effect": [ | |
| 388 | 397 | SmartRequest.get_raw_request("get_lighting_effect") | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,12 +19,6 @@ class AutoOff(SmartModule): | |||
| 19 | 19 | ||
| 20 | 20 | def _initialize_features(self): | |
| 21 | 21 | """Initialize features after the initial update.""" | |
| 22 | - if not isinstance(self.data, dict): | ||
| 23 | - _LOGGER.warning( | ||
| 24 | - "No data available for module, skipping %s: %s", self, self.data | ||
| 25 | - ) | ||
| 26 | - return | ||
| 27 | - | ||
| 28 | 22 | self._add_feature( | |
| 29 | 23 | Feature( | |
| 30 | 24 | self._device, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,6 +43,10 @@ def _initialize_features(self): | |||
| 43 | 43 | ) | |
| 44 | 44 | ) | |
| 45 | 45 | ||
| 46 | + def query(self) -> dict: | ||
| 47 | + """Query to execute during the update cycle.""" | ||
| 48 | + return {} | ||
| 49 | + | ||
| 46 | 50 | @property | |
| 47 | 51 | def battery(self): | |
| 48 | 52 | """Return battery level.""" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,6 @@ | |||
| 4 | 4 | ||
| 5 | 5 | from typing import TYPE_CHECKING | |
| 6 | 6 | ||
| 7 | - from ...exceptions import SmartErrorCode | ||
| 8 | 7 | from ...feature import Feature | |
| 9 | 8 | from ..smartmodule import SmartModule | |
| 10 | 9 | ||
@@ -18,6 +17,13 @@ class Cloud(SmartModule): | |||
| 18 | 17 | QUERY_GETTER_NAME = "get_connect_cloud_state" | |
| 19 | 18 | REQUIRED_COMPONENT = "cloud_connect" | |
| 20 | 19 | ||
| 20 | + def _post_update_hook(self): | ||
| 21 | + """Perform actions after a device update. | ||
| 22 | + | ||
| 23 | + Overrides the default behaviour to disable a module if the query returns | ||
| 24 | + an error because the logic here is to treat that as not connected. | ||
| 25 | + """ | ||
| 26 | + | ||
| 21 | 27 | def __init__(self, device: SmartDevice, module: str): | |
| 22 | 28 | super().__init__(device, module) | |
| 23 | 29 | ||
@@ -37,6 +43,6 @@ def __init__(self, device: SmartDevice, module: str): | |||
| 37 | 43 | @property | |
| 38 | 44 | def is_connected(self): | |
| 39 | 45 | """Return True if device is connected to the cloud.""" | |
| 40 | - if isinstance(self.data, SmartErrorCode): | ||
| 46 | + if self._has_data_error(): | ||
| 41 | 47 | return False | |
| 42 | 48 | return self.data["status"] == 0 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,13 @@ class DeviceModule(SmartModule): | |||
| 10 | 10 | ||
| 11 | 11 | REQUIRED_COMPONENT = "device" | |
| 12 | 12 | ||
| 13 | + def _post_update_hook(self): | ||
| 14 | + """Perform actions after a device update. | ||
| 15 | + | ||
| 16 | + Overrides the default behaviour to disable a module if the query returns | ||
| 17 | + an error because this module is critical. | ||
| 18 | + """ | ||
| 19 | + | ||
| 13 | 20 | def query(self) -> dict: | |
| 14 | 21 | """Query to execute during the update cycle.""" | |
| 15 | 22 | query = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,6 @@ | |||
| 13 | 13 | from async_timeout import timeout as asyncio_timeout | |
| 14 | 14 | from pydantic.v1 import BaseModel, Field, validator | |
| 15 | 15 | ||
| 16 | - from ...exceptions import SmartErrorCode | ||
| 17 | 16 | from ...feature import Feature | |
| 18 | 17 | from ..smartmodule import SmartModule | |
| 19 | 18 | ||
@@ -123,6 +122,13 @@ def query(self) -> dict: | |||
| 123 | 122 | req["get_auto_update_info"] = None | |
| 124 | 123 | return req | |
| 125 | 124 | ||
| 125 | + def _post_update_hook(self): | ||
| 126 | + """Perform actions after a device update. | ||
| 127 | + | ||
| 128 | + Overrides the default behaviour to disable a module if the query returns | ||
| 129 | + an error because some of the module still functions. | ||
| 130 | + """ | ||
| 131 | + | ||
| 126 | 132 | @property | |
| 127 | 133 | def current_firmware(self) -> str: | |
| 128 | 134 | """Return the current firmware version.""" | |
@@ -136,11 +142,11 @@ def latest_firmware(self) -> str: | |||
| 136 | 142 | @property | |
| 137 | 143 | def firmware_update_info(self): | |
| 138 | 144 | """Return latest firmware information.""" | |
| 139 | - fw = self.data.get("get_latest_fw") or self.data | ||
| 140 | - if not self._device.is_cloud_connected or isinstance(fw, SmartErrorCode): | ||
| 145 | + if not self._device.is_cloud_connected or self._has_data_error(): | ||
| 141 | 146 | # Error in response, probably disconnected from the cloud. | |
| 142 | 147 | return UpdateInfo(type=0, need_to_upgrade=False) | |
| 143 | 148 | ||
| 149 | + fw = self.data.get("get_latest_fw") or self.data | ||
| 144 | 150 | return UpdateInfo.parse_obj(fw) | |
| 145 | 151 | ||
| 146 | 152 | @property | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,10 @@ class FrostProtection(SmartModule): | |||
| 14 | 14 | REQUIRED_COMPONENT = "frost_protection" | |
| 15 | 15 | QUERY_GETTER_NAME = "get_frost_protection" | |
| 16 | 16 | ||
| 17 | + def query(self) -> dict: | ||
| 18 | + """Query to execute during the update cycle.""" | ||
| 19 | + return {} | ||
| 20 | + | ||
| 17 | 21 | @property | |
| 18 | 22 | def enabled(self) -> bool: | |
| 19 | 23 | """Return True if frost protection is on.""" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -45,6 +45,10 @@ def __init__(self, device: SmartDevice, module: str): | |||
| 45 | 45 | ) | |
| 46 | 46 | ) | |
| 47 | 47 | ||
| 48 | + def query(self) -> dict: | ||
| 49 | + """Query to execute during the update cycle.""" | ||
| 50 | + return {} | ||
| 51 | + | ||
| 48 | 52 | @property | |
| 49 | 53 | def humidity(self): | |
| 50 | 54 | """Return current humidity in percentage.""" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -140,7 +140,7 @@ def query(self) -> dict: | |||
| 140 | 140 | """Query to execute during the update cycle.""" | |
| 141 | 141 | if self._state_in_sysinfo: # Child lights can have states in the child info | |
| 142 | 142 | return {} | |
| 143 | - return {self.QUERY_GETTER_NAME: None} | ||
| 143 | + return {self.QUERY_GETTER_NAME: {"start_index": 0}} | ||
| 144 | 144 | ||
| 145 | 145 | async def _check_supported(self): | |
| 146 | 146 | """Additional check to see if the module is supported by the device. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -230,7 +230,7 @@ def query(self) -> dict: | |||
| 230 | 230 | if self._state_in_sysinfo: | |
| 231 | 231 | return {} | |
| 232 | 232 | else: | |
| 233 | - return {self.QUERY_GETTER_NAME: None} | ||
| 233 | + return {self.QUERY_GETTER_NAME: {}} | ||
| 234 | 234 | ||
| 235 | 235 | async def _check_supported(self): | |
| 236 | 236 | """Additional check to see if the module is supported by the device.""" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments