Collection of CheckMK checks (see https://checkmk.com/). All checks and plugins are provided as is. Absolutely no warranty. Send any comments to thl-cmk[at]outlook[dot]com

Skip to content
Snippets Groups Projects
Commit a97226b3 authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

Delete fritzbox_smarthome.py

parent 0ede8e41
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# License: GNU General Public License v2
#
# Author: thl-cmk[at]outlook[dot]com
# URL : https://thl-cmk.hopto.org
# Date : 2023-12-29
# File : fritzbox_smarthome.py (check plugin utils)
#
# Based on the work of Maximilian Clemens, see https://github.com/MaximilianClemens/checkmk_fritzbox
#
#
from dataclasses import dataclass
from typing import Any, List, Dict
@dataclass(frozen=True)
class AvmTemperature:
celsius: float
offset: float
@dataclass(frozen=True)
class AvmAlert:
last_alert_chg_timestamp: int
state: int
@dataclass(frozen=True)
class AvmButton:
last_pressed_timestamp: int
id: int | None = None
identifier: int | None = None
name: str | None = None
@dataclass(frozen=True)
class AvmPowerMeter:
energy: float
power: float
voltage: float
@dataclass(frozen=True)
class AvmSimpleOnOff:
state: int
@dataclass(frozen=True)
class AvmNextChange:
end_period: int
temp_change_to: float
@dataclass(frozen=True)
class AvmThermostat:
error_code: int
temp_comfort: float
temp_current: float
temp_economic: float
temp_target: float
adaptive_heating_active: int | None = None
adaptive_heating_running: int | None = None
battery: float | None = None
boost_active: int | None = None
boost_active_end_time: int | None = None
holiday_active: int | None = None
next_change: AvmNextChange | None = None
summer_active: int | None = None
window_open_activ: int | None = None
@dataclass(frozen=True)
class AvmSwitch:
mode: str
state: int
@dataclass(frozen=True)
class AvmSmartHomeDevice:
fbm: int
functions: List[str]
fw_version: str
id: str
identifier: str
manufacturer: str
name: str
present: int
product_name: str
battery_low: int | None = None
device_lock: int | None = None
lock: int | None = None
power_meter: AvmPowerMeter | None = None
simple_on_off: AvmSimpleOnOff | None = None
switch: AvmSwitch | None = None
temperature: AvmTemperature | None = None
thermostat: AvmThermostat | None = None
tx_busy: int | None = None
_AVM_THERMOSTAT = 'hkr'
_AVM_SWITCH = 'switch'
_AVM_POWER_METER = 'powermeter'
_AVM_TEMPERATURE = 'temperature'
_AVM_SIMPLE_ON_OFF = 'simpleonoff'
_AVM_NEXT_CHANGE = 'nextchange'
def _get_battery_low(device: Dict[str, Any]) -> int | None:
try:
return int(device[_AVM_THERMOSTAT]['batterylow'])
except KeyError:
pass
return None
def _get_lock(device: Dict[str, Any]) -> int | None:
try:
return int(device[_AVM_THERMOSTAT]['lock'])
except KeyError:
pass
try:
return int(device[_AVM_SWITCH]['lock'])
except KeyError:
pass
return None
def _get_device_lock(device: Dict[str, Any]) -> int | None:
try:
return int(device[_AVM_THERMOSTAT]['devicelock'])
except KeyError:
pass
try:
return int(device[_AVM_SWITCH]['devicelock'])
except KeyError:
pass
return None
def parse_avm_smarthome_device(raw_device: Dict[str, Any]) -> AvmSmartHomeDevice:
return AvmSmartHomeDevice(
battery_low=_get_battery_low(raw_device),
device_lock=_get_device_lock(raw_device),
fbm=int(raw_device['functionbitmask']),
functions=get_avm_device_functions_from_fbm(int(raw_device['functionbitmask'])),
fw_version=str(raw_device['fwversion']),
id=str(raw_device['id']),
identifier=str(raw_device['identifier']),
lock=_get_lock(raw_device),
manufacturer=str(raw_device['manufacturer']),
name=str(raw_device['name']),
present=int(raw_device['present']),
product_name=str(raw_device['productname']),
tx_busy=int(raw_device['txbusy']) if raw_device.get('txbusy') else None,
temperature=AvmTemperature(
celsius=float(raw_device[_AVM_TEMPERATURE]['celsius']) / 10.0,
offset=float(raw_device[_AVM_TEMPERATURE]['offset']) / 10.0,
) if raw_device.get(_AVM_TEMPERATURE) else None,
thermostat=AvmThermostat(
temp_current=float(raw_device[_AVM_THERMOSTAT]['tist']) / 2.0,
temp_target=float(raw_device[_AVM_THERMOSTAT]['tsoll']) / 2.0,
temp_economic=float(raw_device[_AVM_THERMOSTAT]['absenk']) / 2.0,
temp_comfort=float(raw_device[_AVM_THERMOSTAT]['komfort']) / 2.0,
error_code=int(raw_device[_AVM_THERMOSTAT]['errorcode']),
next_change=AvmNextChange(
end_period=int(raw_device[_AVM_THERMOSTAT][_AVM_NEXT_CHANGE]['endperiod']),
temp_change_to=float(raw_device[_AVM_THERMOSTAT][_AVM_NEXT_CHANGE]['tchange']) / 2.0,
) if raw_device[_AVM_THERMOSTAT].get(_AVM_NEXT_CHANGE) else None,
) if raw_device.get(_AVM_THERMOSTAT) else None,
switch=AvmSwitch(
state=int(raw_device[_AVM_SWITCH]['state']),
mode=str(raw_device[_AVM_SWITCH]['mode']),
) if raw_device.get(_AVM_SWITCH) else None,
power_meter=AvmPowerMeter(
voltage=float(raw_device[_AVM_POWER_METER]['voltage']) / 1000,
power=float(raw_device[_AVM_POWER_METER]['power']) / 1000,
energy=float(raw_device[_AVM_POWER_METER]['energy']), # / 1000,
) if raw_device.get(_AVM_POWER_METER) else None,
simple_on_off=AvmSimpleOnOff(
state=int(raw_device[_AVM_SIMPLE_ON_OFF]['state']),
) if raw_device.get(_AVM_SIMPLE_ON_OFF) else None,
)
def get_avm_device_functions_from_fbm(fbm: int) -> List[str]:
functions = []
if fbm >> 0 & 1:
functions.append('HAN-FUN Device')
if fbm >> 2 & 1:
functions.append('Light')
if fbm >> 3 & 1:
functions.append('unknown (Bit 3)')
if fbm >> 4 & 1:
functions.append('Alarm Sensor')
if fbm >> 5 & 1:
functions.append('AVM Button')
if fbm >> 6 & 1:
functions.append('AVM Thermostat')
if fbm >> 7 & 1:
functions.append('AVM Powermeter')
if fbm >> 8 & 1:
functions.append('Temperature Sensor')
if fbm >> 9 & 1:
functions.append('AVM Switching socket')
if fbm >> 10 & 1:
functions.append('AVM DECT Repeater')
if fbm >> 11 & 1:
functions.append('AVM Microphone')
if fbm >> 12 & 1:
functions.append('unknown (Bit 12)')
if fbm >> 13 & 1:
functions.append('HAN-FUN Unit')
if fbm >> 14 & 1:
functions.append('unknown (Bit 14)')
if fbm >> 15 & 1:
functions.append('on/off switchable device')
if fbm >> 16 & 1:
functions.append('Device with adjustable dimming, height and level')
if fbm >> 17 & 1:
functions.append('Light')
if fbm >> 18 & 1:
functions.append('Roller shutter')
if fbm >> 19 & 1:
functions.append('unknown (Bit 19)')
if fbm >> 20 & 1:
functions.append('Humidity sensor')
functions.sort()
return functions
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment