#!/usr/bin/python
# -*- encoding: utf-8; py-indent-offset: 4 -*-
# +------------------------------------------------------------------+
# |             ____ _               _        __  __ _  __           |
# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
# |                                                                  |
# | Copyright Mathias Kettner 2013             mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software;  you can redistribute it and/or modify it
# under the  terms of the  GNU General Public License  as published by
# the Free Software Foundation in version 2.  check_mk is  distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
# ails.  You should have  received  a copy of the  GNU  General Public
# License along with GNU Make; see the file  COPYING.  If  not,  write
# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
# Boston, MA 02110-1301 USA.

climaveneta_sensors = {
    1 : "Room",
    3 : "Outlet Air 1",
    4 : "Outlet Air 2",
    5 : "Outlet Air 3",
    6 : "Outlet Air 4",
    7 : "Intlet Air 1",
    8 : "Intlet Air 2",
    9 : "Intlet Air 3",
    10 : "Intlet Air 4",
    11 : "Coil 1 Inlet Water",
    12 : "Coil 2 Inlet Water",
    13 : "Coil 1 Outlet Water",
    14 : "Coil 2 Outlet Water",
    23 : "Regulation Valve/Compressor",
    24 : "Regulation Fan 1",
    25 : "Regulation Fan 2",
    28 : "Suction",
}

climaveneta_temp_default_levels = (28, 30)

def inventory_climaveneta_temp(info):
    for sensor_id, value in info:
        sensor_id = int(sensor_id.split('.')[0])
        if sensor_id in climaveneta_sensors.keys() and int(value) > 0:
            yield climaveneta_sensors[sensor_id], 'climaveneta_temp_default_levels'


def check_climaveneta_temp(item, params, info):
    for sensor_id, sensor_value in info:
        sensor_id = int(sensor_id.split('.')[0])
        if climaveneta_sensors.get(sensor_id) == item:
            sensor_value = int(sensor_value) / 10.0
            return check_temperature(sensor_value, params)


check_info["climaveneta_temp"] = {
    "check_function"        : check_climaveneta_temp,
    "inventory_function"    : inventory_climaveneta_temp,
    "service_description"   : "Temperature %s",
    "has_perfdata"          : True,
    "snmp_scan_function"    : lambda oid: oid(".1.3.6.1.2.1.1.1.0") == "pCO Gateway",
    "snmp_info"             : (".1.3.6.1.4.1.9839.2.1", [ OID_END, 2 ] ),
    "group"                 : "room_temperature",
    "includes"              : [ "temperature.include" ],
}

