"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 () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.definitions = void 0;
const exposes = __importStar(require("../lib/exposes"));
const legacy = __importStar(require("../lib/legacy"));
const tuya = __importStar(require("../lib/tuya"));
const e = exposes.presets;
const ea = exposes.access;
const te = tuya.exposes;
exports.definitions = [
    {
        fingerprint: tuya.fingerprint("TS0601", ["_TZE200_wt9agwf3", "_TZE200_5uodvhgc", "_TZE200_1n2zev06"]),
        model: "FK_V02",
        vendor: "FrankEver",
        description: "Zigbee smart water valve",
        fromZigbee: [legacy.fz.frankever_valve],
        toZigbee: [legacy.tz.tuya_switch_state, legacy.tz.frankever_threshold, legacy.tz.frankever_timer],
        exposes: [
            e.switch().setAccess("state", ea.STATE_SET),
            e
                .numeric("threshold", exposes.access.STATE_SET)
                .withValueMin(0)
                .withValueMax(100)
                .withUnit("%")
                .withDescription("Valve open percentage (multiple of 10)"),
            e
                .numeric("timer", exposes.access.STATE_SET)
                .withValueMin(0)
                .withValueMax(600)
                .withUnit("min")
                .withDescription("Countdown timer in minutes"),
        ],
    },
    {
        fingerprint: [{ modelID: "TS0601", manufacturerName: "_TZE200_nbqnmkee" }],
        model: "FK-BV05",
        vendor: "FrankEver",
        description: "Zigbee smart water valve with flow meter and temperature sensor",
        extend: [tuya.modernExtend.tuyaBase({ dp: true })],
        exposes: [
            // --- Valve Controls ---
            e.switch().setAccess("state", ea.STATE_SET),
            e
                .numeric("threshold", ea.STATE_SET)
                .withUnit("%")
                .withValueMin(0)
                .withValueMax(100)
                .withValueStep(10)
                .withDescription("Target valve opening percentage"),
            e.numeric("position", ea.STATE).withUnit("%").withDescription("Current valve position"),
            e.enum("power_off_state", ea.STATE_SET, ["off", "on", "maintain"]).withDescription("Power-off status behavior"),
            e.enum("weather_delay", ea.STATE_SET, ["cancel", "24h", "48h", "72h"]).withDescription("Weather delay"),
            e
                .numeric("countdown", ea.STATE_SET)
                .withUnit("s")
                .withValueMin(0)
                .withValueMax(86400)
                .withDescription("Irrigation Duration (countdown in seconds)"),
            // --- Sensors ---
            e.numeric("water_temperature", ea.STATE).withUnit("°C").withDescription("Water temperature"),
            e
                .numeric("water_consumed_last", ea.STATE)
                .withUnit("L")
                .withValueMin(0)
                .withValueMax(1000)
                .withValueStep(0.1)
                .withDescription("Single water consumption (last irrigation)"),
            e.numeric("water_consumed_total", ea.STATE).withUnit("L").withValueMin(0).withDescription("Total water consumption"),
            e.enum("water_leakage_state", ea.STATE, ["water_leakage_yes", "water_leakage_no"]).withDescription("Leak detection status"),
            // --- Irrigation Volume Limits ---
            e.binary("single_irrigation_switch", ea.STATE_SET, "ON", "OFF").withDescription("Enable single irrigation volume limit"),
            e
                .numeric("single_irrigation_set", ea.STATE_SET)
                .withUnit("L")
                .withValueMin(0)
                .withValueMax(1000)
                .withDescription("Single irrigation water volume setting"),
            e.binary("day_irrigation_switch", ea.STATE_SET, "ON", "OFF").withDescription("Enable daily irrigation volume limit"),
            e
                .numeric("day_irrigation_set", ea.STATE_SET)
                .withUnit("L")
                .withValueMin(0)
                .withValueMax(1000)
                .withDescription("Daily irrigation water volume setting"),
            // --- Alarms and Thresholds ---
            e.binary("water_volume_alarm_switch", ea.STATE_SET, "ON", "OFF").withDescription("Water volume alarm switch"),
            e
                .numeric("water_volume_alarm_set", ea.STATE_SET)
                .withUnit("L")
                .withValueMin(0)
                .withValueMax(1000)
                .withDescription("Alarm water volume setting value"),
            e.binary("water_temp_alarm_switch", ea.STATE_SET, "ON", "OFF").withDescription("Water temperature alarm switch"),
            e
                .numeric("water_temp_alarm_max", ea.STATE_SET)
                .withUnit("°C")
                .withValueMin(0)
                .withValueMax(120)
                .withDescription("Alarm water temperature maximum setting"),
            e
                .numeric("water_temp_alarm_min", ea.STATE_SET)
                .withUnit("°C")
                .withValueMin(0)
                .withValueMax(120)
                .withDescription("Alarm water temperature minimum setting"),
            e.binary("water_volume_alarm", ea.STATE, true, false).withDescription("Water volume alarm is active (configured volume exceeded)"),
            e.binary("water_temp_alarm", ea.STATE, true, false).withDescription("Water temperature alarm is active (configured range exceeded)"),
            // --- Maintenance ---
            e
                .binary("creep_switch", ea.STATE_SET, "ON", "OFF")
                .withDescription("Peristaltic function switch (Auto cycle anti-calc) - KEEP OFF for normal use"),
            te.fault(),
        ],
        meta: {
            tuyaDatapoints: [
                [1, "state", tuya.valueConverter.onOff],
                [2, "threshold", tuya.valueConverter.raw],
                [3, "position", tuya.valueConverter.raw],
                [4, "fault", tuya.valueConverter.fault],
                // The vendor datapoint spec marks dp 5 with "Multiple: 1" (0.1 L per unit) and dp 6 with
                // "Multiple: 0" (1 L per unit), so the last irrigation volume is reported in dL.
                [5, "water_consumed_last", tuya.valueConverter.divideBy10],
                [6, "water_consumed_total", tuya.valueConverter.raw],
                [
                    10,
                    "weather_delay",
                    tuya.valueConverterBasic.lookup({
                        cancel: new tuya.Enum(0),
                        "24h": new tuya.Enum(1),
                        "48h": new tuya.Enum(2),
                        "72h": new tuya.Enum(3),
                    }),
                ],
                [11, "countdown", tuya.valueConverter.raw],
                [22, "water_temperature", tuya.valueConverter.raw],
                [
                    101,
                    "water_leakage_state",
                    tuya.valueConverterBasic.lookup({ water_leakage_yes: new tuya.Enum(0), water_leakage_no: new tuya.Enum(1) }),
                ],
                [102, "single_irrigation_switch", tuya.valueConverter.onOff],
                [103, "single_irrigation_set", tuya.valueConverter.raw],
                [104, "day_irrigation_switch", tuya.valueConverter.onOff],
                [105, "day_irrigation_set", tuya.valueConverter.raw],
                [106, "water_volume_alarm_switch", tuya.valueConverter.onOff],
                [107, "water_volume_alarm_set", tuya.valueConverter.raw],
                [108, "water_temp_alarm_switch", tuya.valueConverter.onOff],
                [109, "water_temp_alarm_max", tuya.valueConverter.raw],
                [110, "power_off_state", tuya.valueConverterBasic.lookup({ off: new tuya.Enum(0), on: new tuya.Enum(1), maintain: new tuya.Enum(2) })],
                [112, "creep_switch", tuya.valueConverter.onOff],
                [113, "water_temp_alarm_min", tuya.valueConverter.raw],
                [114, "water_temp_alarm", tuya.valueConverter.raw],
                [115, "water_volume_alarm", tuya.valueConverter.raw],
            ],
        },
    },
];
//# sourceMappingURL=frankever.js.map