Update offset in fb
This commit is contained in:
parent
8aeb8cb1a6
commit
1a561a45d7
@ -11,13 +11,14 @@ import logging
|
||||
|
||||
|
||||
class FritzBox:
|
||||
def __init__(self, url: str, password: str, user: str = None) -> None:
|
||||
def __init__(self, url: str, password: str, user: str = None, dry_run: bool = False) -> None:
|
||||
self._endpoints = {
|
||||
"login": "login_sid.lua?version=2",
|
||||
"logout": "index.lua",
|
||||
"data": "data.lua"
|
||||
}
|
||||
self.url: str = url
|
||||
self.dry_run: bool = dry_run
|
||||
self.user: Optional[str] = user
|
||||
self.session: requests.Session = requests.Session()
|
||||
self.password: str = password
|
||||
@ -171,6 +172,9 @@ class FritzBox:
|
||||
return current_temp, current_offset, device["id"], device["displayName"]
|
||||
|
||||
def set_offset(self, current_temp: str, offset: float, device_id: int, device_name: str) -> None:
|
||||
if self.dry_run:
|
||||
logging.warning("No updates in dry-run-mode")
|
||||
return
|
||||
data = {
|
||||
"xhr": 1,
|
||||
"sid": self.sid,
|
||||
@ -178,7 +182,7 @@ class FritzBox:
|
||||
"device": device_id,
|
||||
"page": "home_auto_hkr_edit"
|
||||
}
|
||||
r = self.session.post(f"{self.url}/{self._endpoints['data']}", data=data)
|
||||
self.session.post(f"{self.url}/{self._endpoints['data']}", data=data)
|
||||
|
||||
data = {
|
||||
"xhr": 1,
|
||||
@ -207,5 +211,6 @@ class FritzBox:
|
||||
if device_name not in self.update_time.keys() or (datetime.now() - self.update_time[device_name]) > delta:
|
||||
current_temp, current_offset, idx, name = self.get_device_data(name=device_name)
|
||||
new_offset = current_offset + real_temp - current_temp
|
||||
logging.info(f"Should update offset from {current_offset} to {new_offset}")
|
||||
logging.info(f"Update offset from {current_offset} to {new_offset}")
|
||||
self.set_offset(current_temp, new_offset, idx, device_name)
|
||||
self.update_time[device_name] = datetime.now()
|
||||
|
Loading…
x
Reference in New Issue
Block a user