Skip to content

Commit 06db29c

Browse files
authored
Merge pull request #28 from rospogrigio/fix_econoMode
Fixed crash in devices that don't provide econoMode preset mode
2 parents 0322a91 + d797cdd commit 06db29c

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

custom_components/daikin_residential/daikin_api.py

+21-8
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,16 @@ async def doBearerRequest(self, resourceUrl, options=None, refreshed=False):
8282
async with self._cloud_lock:
8383
_LOGGER.debug("BEARER REQUEST URL: %s", resourceUrl)
8484
_LOGGER.debug("BEARER REQUEST HEADERS: %s", headers)
85-
if options is not None and "method" in options and options["method"] == "PATCH":
85+
if (
86+
options is not None
87+
and "method" in options
88+
and options["method"] == "PATCH"
89+
):
8690
_LOGGER.debug("BEARER REQUEST JSON: %s", options["json"])
8791
func = functools.partial(
8892
requests.patch, resourceUrl, headers=headers, data=options["json"]
8993
)
90-
# res = requests.patch(resourceUrl, headers=headers, data=options["json"])
94+
# res = requests.patch(resourceUrl, headers, data=options["json"])
9195
else:
9296
func = functools.partial(requests.get, resourceUrl, headers=headers)
9397
# res = requests.get(resourceUrl, headers=headers)
@@ -505,18 +509,27 @@ async def async_update(self, **kwargs):
505509
dev_data
506510
)
507511

508-
if dev_data["managementPoints"][1]["econoMode"]["value"] == "on":
512+
_mode = "none"
513+
if (
514+
"econoMode" in dev_data["managementPoints"][1]
515+
and dev_data["managementPoints"][1]["econoMode"]["value"] == "on"
516+
):
509517
_mode = "eco"
510-
elif dev_data["managementPoints"][1]["powerfulMode"]["value"] == "on":
518+
if (
519+
"powerfulMode" in dev_data["managementPoints"][1]
520+
and dev_data["managementPoints"][1]["powerfulMode"]["value"] == "on"
521+
):
511522
_mode = "powerful"
512-
else:
513-
_mode = "none"
514523

515-
_LOGGER.debug("DEVICE %s: %s/%s/%s/%s",
524+
_LOGGER.debug(
525+
"DEVICE %s: %s/%s/%s/%s",
516526
dev_data["managementPoints"][1]["name"]["value"],
517527
dev_data["managementPoints"][1]["onOffMode"]["value"],
518528
dev_data["managementPoints"][1]["operationMode"]["value"],
519529
_mode,
520-
"streamer" if dev_data["managementPoints"][1]["streamerMode"]["value"] == "on" else "nostreamer")
530+
"streamer"
531+
if dev_data["managementPoints"][1]["streamerMode"]["value"] == "on"
532+
else "nostreamer",
533+
)
521534

522535
return True

0 commit comments

Comments
 (0)