Skip to content

Commit 18f3621

Browse files
authored
Merge pull request #198 from jaroschek/release/1.7.x
Release 1.7.1
2 parents 07b8f2d + eea08b3 commit 18f3621

2 files changed

Lines changed: 24 additions & 19 deletions

File tree

custom_components/myuplink/api.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,25 @@ async def request(self, method, path, **kwargs) -> ClientResponse:
7676
headers=headers,
7777
)
7878

79+
7980
class Subscription:
81+
"""Class that represents the subscription in the myUplink API."""
82+
8083
def __init__(self, raw_data: dict) -> None:
84+
"""Initialize a subscription object."""
8185
self.raw_data = raw_data
82-
86+
8387
@property
8488
def type(self) -> str:
89+
"""Return the subscription type."""
8590
return self.raw_data["type"]
86-
91+
8792
@property
88-
def validUntil(self) -> datetime:
93+
def valid_until(self) -> datetime:
94+
"""Return datetime value of 'validUntil'."""
8995
return datetime(self.raw_data("validUntil"))
9096

97+
9198
class Notification:
9299
"""Class that represents the notificationobject in the myUplink API."""
93100

@@ -213,7 +220,10 @@ def unit(self) -> str:
213220
@property
214221
def is_writable(self) -> bool:
215222
"""Return if the parameter is writable."""
216-
if self.device.system.premium_manage or self.device.system.api.writable_without_subscription:
223+
if (
224+
self.device.system.premium_manage
225+
or self.device.system.api.writable_without_subscription
226+
):
217227
if self.id in self.device.system.api.writable_override:
218228
return self.device.system.api.writable_override[self.id]
219229

@@ -280,8 +290,6 @@ async def update_parameter(self, value) -> None:
280290
"""Patch parameter if writable."""
281291
if not self.is_writable:
282292
return
283-
if not self.device.system.premium_manage:
284-
return
285293
await self.device.system.api.patch_parameter(
286294
self.device.id, str(self.id), str(value)
287295
)
@@ -516,7 +524,7 @@ async def async_fetch_data(self) -> None:
516524
self.devices = [
517525
Device(device_data, self) for device_data in self.raw_data["devices"]
518526
]
519-
527+
520528
self.premium_manage = await self.api.get_premium_manage(self)
521529

522530
if self.api.entry.options.get(CONF_ENABLE_SMART_HOME_MODE, True):
@@ -580,8 +588,10 @@ def __init__(
580588
self.throttle = Throttle(timedelta(seconds=5))
581589

582590
self.header = {"Accept-Language": language_code}
583-
584-
self.writable_without_subscription = entry.options.get(CONF_WRITABLE_WITHOUT_SUBSCRIPTION, True)
591+
592+
self.writable_without_subscription = entry.options.get(
593+
CONF_WRITABLE_WITHOUT_SUBSCRIPTION, True
594+
)
585595

586596
try:
587597
self.parameter_whitelist = json.loads(
@@ -651,20 +661,15 @@ async def get_premium_manage(self, system: System) -> bool:
651661
"""Check for a premium subscription to allow writing values."""
652662
_LOGGER.debug("Fetch subscriptions for system %s", system.id)
653663
async with self.lock, self.throttle:
654-
resp = await self.auth.request(
655-
"get", f"systems/{system.id}/subscriptions"
656-
)
664+
resp = await self.auth.request("get", f"systems/{system.id}/subscriptions")
657665
resp.raise_for_status()
658666
if resp.status == 200:
659667
data = await resp.json()
660-
for element in data:
661-
for subscription in data["subscriptions"]:
662-
if Subscription(subscription).type == "manage":
663-
return True
668+
for subscription in data["subscriptions"]:
669+
if Subscription(subscription).type == "manage":
670+
return True
664671
return False
665672

666-
667-
668673
async def get_smart_home_mode(self, system: System) -> str:
669674
"""Return smart home mode by system id."""
670675
_LOGGER.debug("Fetch smart home mode for system %s", system.id)

custom_components/myuplink/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"issue_tracker": "https://github.com/jaroschek/home-assistant-myuplink/issues",
1111
"requirements": [],
1212
"ssdp": [],
13-
"version": "1.7.0",
13+
"version": "1.7.1",
1414
"zeroconf": []
1515
}

0 commit comments

Comments
 (0)