"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const zigbee_herdsman_1 = require("@willieee802/zigbee-herdsman");
const exposes = __importStar(require("../lib/exposes"));
const fromZigbee_1 = __importDefault(require("../converters/fromZigbee"));
const legacy = __importStar(require("../lib/legacy"));
const toZigbee_1 = __importDefault(require("../converters/toZigbee"));
const reporting = __importStar(require("../lib/reporting"));
const e = exposes.presets;
const ea = exposes.access;
const definitions = [
    {
        zigbeeModel: ["7377019"],
        model: "7377019",
        vendor: "Viessmann",
        description: "ViCare CO2, temperature and humidity sensor",
        fromZigbee: [fromZigbee_1.default.co2, fromZigbee_1.default.temperature, fromZigbee_1.default.humidity, fromZigbee_1.default.battery],
        toZigbee: [],
        exposes: [e.battery(), e.co2(), e.temperature(), e.humidity()],
    },
    {
        zigbeeModel: ["7637435"],
        model: "ZK03839",
        vendor: "Viessmann",
        description: "ViCare climate sensor",
        fromZigbee: [fromZigbee_1.default.temperature, fromZigbee_1.default.humidity, fromZigbee_1.default.battery],
        toZigbee: [],
        exposes: [e.battery(), e.temperature(), e.humidity()],
    },
    {
        zigbeeModel: ["7637434"],
        model: "ZK03840",
        vendor: "Viessmann",
        description: "ViCare radiator thermostat valve",
        fromZigbee: [
            legacy.fz.viessmann_thermostat_att_report,
            fromZigbee_1.default.battery,
            legacy.fz.hvac_user_interface,
        ],
        toZigbee: [
            toZigbee_1.default.thermostat_local_temperature,
            toZigbee_1.default.thermostat_occupied_heating_setpoint,
            toZigbee_1.default.thermostat_control_sequence_of_operation,
            toZigbee_1.default.thermostat_system_mode,
            toZigbee_1.default.thermostat_keypad_lockout,
            toZigbee_1.default.viessmann_window_open,
            toZigbee_1.default.viessmann_window_open_force,
            toZigbee_1.default.viessmann_assembly_mode,
            toZigbee_1.default.thermostat_weekly_schedule,
            toZigbee_1.default.thermostat_clear_weekly_schedule,
        ],
        exposes: [
            e
                .climate()
                .withSetpoint("occupied_heating_setpoint", 7, 30, 1)
                .withLocalTemperature()
                .withSystemMode(["heat", "sleep"])
                .withWeeklySchedule(["heat"]),
            e
                .binary("window_open", ea.STATE_GET, true, false)
                .withDescription("Detected by sudden temperature drop or set manually."),
            e
                .binary("window_open_force", ea.ALL, true, false)
                .withDescription("Manually set window_open, ~1 minute to take affect."),
            e.keypad_lockout(),
            e.battery(),
        ],
        configure: async (device, coordinatorEndpoint) => {
            const endpoint = device.getEndpoint(1);
            const options = {
                manufacturerCode: zigbee_herdsman_1.Zcl.ManufacturerCode.VIESSMANN_ELEKTRONIK_GMBH,
            };
            await reporting.bind(endpoint, coordinatorEndpoint, [
                "genBasic",
                "genPowerCfg",
                "genIdentify",
                "genTime",
                "hvacThermostat",
            ]);
            // standard ZCL attributes
            await reporting.batteryPercentageRemaining(endpoint);
            await reporting.thermostatTemperature(endpoint);
            await reporting.thermostatOccupiedHeatingSetpoint(endpoint);
            await reporting.thermostatPIHeatingDemand(endpoint);
            // manufacturer attributes
            await endpoint.configureReporting("hvacThermostat", [
                {
                    attribute: "viessmannWindowOpenInternal",
                    minimumReportInterval: 60,
                    maximumReportInterval: 3600,
                    reportableChange: 1,
                },
            ], options);
            // read window_open_force, we don't need reporting as it cannot be set physically on the device
            await endpoint.read("hvacThermostat", ["viessmannWindowOpenForce"], options);
            // read keypadLockout, we don't need reporting as it cannot be set physically on the device
            await endpoint.read("hvacUserInterfaceCfg", ["keypadLockout"]);
        },
    },
];
exports.default = definitions;
module.exports = definitions;
//# sourceMappingURL=viessmann.js.map