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 c6ecea9b authored by thl-cmk's avatar thl-cmk :flag_na:
Browse files

Delete fritzbox_smarthome_thermostat.py

parent ae3f3f78
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-28
# File : fritzbox_smarthome_thermostat.py (check plugin)
#
#
from time import strftime, localtime
from typing import Dict
from cmk.base.plugins.agent_based.agent_based_api.v1 import (
Metric,
Result,
Service,
State,
register,
)
from cmk.base.plugins.agent_based.agent_based_api.v1.type_defs import CheckResult, DiscoveryResult
from cmk.base.plugins.agent_based.utils.fritzbox_smarthome import AvmSmartHomeDevice
_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S'
def discovery_fritzbox_smarthome_thermostat_single(
section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> DiscoveryResult:
if isinstance(section, AvmSmartHomeDevice):
if section.thermostat:
yield Service()
def discovery_fritzbox_smarthome_thermostat_multiple(
section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> DiscoveryResult:
if not isinstance(section, AvmSmartHomeDevice):
for device_id, device in section.items():
if device.thermostat:
yield Service(item=str(device_id))
def check_fritzbox_smarthome_thermostat_single(
params, section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> CheckResult:
if not isinstance(section, AvmSmartHomeDevice):
return
if not section.thermostat:
return
if thermostat := section.thermostat:
_error_codes = {
0: 'no error',
1: 'No adaptation possible. Is the thermostat correctly mounted on the radiator?',
2: 'Valve stroke too short or battery power too low. Open and close the '
'valve tappet several times by hand or insert new batteries.',
3: 'No valve movement possible. Valve tappet free?',
4: 'The installation is currently being prepared.',
5: 'The thermostat is in installation mode and can be mounted on the heating valve.',
6: 'The thermostat now adapts to the stroke of the heating valve',
}
if thermostat.temp_target == 126.5: # == radiator off
yield Result(state=State.OK, summary=f'Temperature current: {thermostat.temp_current}°C')
yield Result(state=State.OK, summary=f'Temperature target: radiator off')
else:
deviation = thermostat.temp_current - thermostat.temp_target
if deviation == 0:
yield Result(state=State.OK, summary=f'Temperature current: {thermostat.temp_target}°C')
else:
_message = f'Temperature current: {thermostat.temp_current}°C (deviation from target {deviation}°C)'
_state = State.OK
if params.get('deviation'):
warn, crit = params['deviation']
if abs(deviation) >= crit:
_state = State.CRIT
elif abs(deviation) >= warn:
_state = State.WARN
yield Result(state=_state, summary=_message)
yield Result(
state=State.OK,
summary=f'Target: {thermostat.temp_target}°C',
details=f'Temperature target: {thermostat.temp_target}°C'
)
yield Metric(name='temp_target', value=thermostat.temp_target)
yield Result(state=State.OK, notice=f'Temperature economic: {thermostat.temp_economic}°C')
yield Result(state=State.OK, notice=f'Temperature comfort: {thermostat.temp_comfort}°C')
yield Metric(name='temp_current', value=thermostat.temp_current)
yield Metric(name='temp_comfort', value=thermostat.temp_comfort)
yield Metric(name='temp_economic', value=thermostat.temp_economic)
if thermostat.next_change:
yield Result(
state=State.OK,
notice=f'End of period: {strftime(_TIME_FORMAT, localtime(thermostat.next_change.end_period))}'
)
yield Result(
state=State.OK,
notice=f'Temperature target after end of period: {thermostat.next_change.temp_change_to}°C'
)
_message = f'Error code: {_error_codes.get(thermostat.error_code, f"unknown error {thermostat.error_code}")}'
if thermostat.error_code == 0:
yield Result(state=State.OK, notice=_message)
else:
yield Result(
state=State(params.get('state_on_error', 1)),
summary=f'Error Code: {thermostat.error_code} (see details)',
details=_message)
def check_fritzbox_smarthome_thermostat_multiple(
item, params, section: AvmSmartHomeDevice | Dict[str, AvmSmartHomeDevice]
) -> CheckResult:
if isinstance(section, Dict):
try:
yield from check_fritzbox_smarthome_thermostat_single(params, section[item])
except KeyError:
return
register.check_plugin(
name='fritzbox_smarthome_thermostat_single',
service_name='Thermostat',
sections=['fritzbox_smarthome'],
discovery_function=discovery_fritzbox_smarthome_thermostat_single,
check_function=check_fritzbox_smarthome_thermostat_single,
check_ruleset_name='fritzbox_smarthome_thermostat_single',
check_default_parameters={}
)
register.check_plugin(
name='fritzbox_smarthome_thermostat_multiple',
service_name='Smarthome Thermostat %s',
sections=['fritzbox_smarthome'],
discovery_function=discovery_fritzbox_smarthome_thermostat_multiple,
check_function=check_fritzbox_smarthome_thermostat_multiple,
check_ruleset_name='fritzbox_smarthome_thermostat_multiple',
check_default_parameters={}
)
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