import urllib.request from fritz_rest import get_sid class FritzSmartHome: def __init__(self, host: str): self.host = host self.sid = None def session_start(self, username: str, password: str): self.sid = get_sid(self.host, username, password) def session_end(self): self.sid = None def query(self, ain: str, cmd: str): if self.sid is None: raise Exception("Start Session") with urllib.request.urlopen(f"{self.host}/webservices/homeautoswitch.lua?ain={ain}&switchcmd={cmd}&sid={self.sid}") as f: return f.read() def get_temperature(hnd: FritzSmartHome, ain: str): response = hnd.query(ain, 'gettemperature') value = float(response.decode()) / 10 return value if __name__ == '__main__': f = FritzSmartHome("http://192.168.22.4") f.session_start("fritz6632", "body9517") temp = get_temperature(f, "116570135300") print(f"Temp = {temp}°C")