Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cpu_temp property to fritz status #232

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions fritzconnection/core/fritzconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,7 @@ def call_http(

.. versionadded:: 1.12
"""
header, content = self.http_interface.execute(
command,
identifier,
header, content = self.http_interface.executeQuery(
**kwargs
)
content_type, charset = [item.strip() for item in header.split(";")]
Expand All @@ -499,6 +497,16 @@ def call_http(
"encoding": encoding,
"content": content
}

def call_http_query(
self,
payload
) -> dict[str, str]:
"""
Send a request to the query.lua endpoint.
"""
content = self.http_interface.executeQuery(payload)
return content

def reconnect(self) -> None:
"""
Expand Down
30 changes: 30 additions & 0 deletions fritzconnection/core/fritzhttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

URL_LOGIN = "/login_sid.lua?version=2"
URL_HOMEAUTOSWITCH = "/webservices/homeautoswitch.lua"
URL_QUERY = "/query.lua"
PBKDF2_CHALLENGE_INDICATOR = "2$"


Expand Down Expand Up @@ -62,6 +63,11 @@ def login_url(self):
def homeauto_url(self):
"""The homeauto-url including protocol and configurable port."""
return f"{self.fc.address}:{self.remote_port}{URL_HOMEAUTOSWITCH}"

@property
def query_url(self):
"""The homeauto-url including protocol and configurable port."""
return f"{self.fc.address}:{self.remote_port}{URL_QUERY}"

def execute(self, command=None, identifier=None, **kwargs):
"""
Expand Down Expand Up @@ -95,6 +101,30 @@ def execute(self, command=None, identifier=None, **kwargs):
# therefore include the payload in the message:
msg = f"{msg}, payload: {payload}"
raise FritzHttpInterfaceError(msg)

def executeQuery(self, payload):
"""
Send a request to the query.lua endpoint.
"""
for sid in self._get_sid():
if sid == None:
continue
payload['sid'] = sid
with self.fc.session.get(
self.query_url, params=payload
) as response:
if response.status_code == HTTPStatus.OK:
return response.json()
msg = f"Request failed: http error code '{response.status_code}'"
if response.status_code == HTTPStatus.FORBIDDEN:
# can happen if FritzConnection was initialized
# without a password.
raise FritzAuthorizationError(msg)
# This can be from the 400 or 500 error-family.
# Most often these errors are triggered by a malformed payload,
# therefore include the payload in the message:
msg = f"{msg}, payload: {payload}"
raise FritzHttpInterfaceError(msg)

def _get_sid(self):
"""
Expand Down
7 changes: 7 additions & 0 deletions fritzconnection/lib/fritzstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,3 +392,10 @@ def has_wan_support(self) -> bool:
False otherwise.
"""
return "Layer3Forwarding1" in self.fc.services

@property
def cpu_temp(self) -> int:
"""
Returns the current cpu temperature.
"""
return self.fc.call_http_query({ "CPUTEMP": "cpu:status/StatTemperature" })["CPUTEMP"].split(",")[0]