"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const hap_types_1 = require("../hap-types");
class Lightbulb {
    sync(service) {
        const attributes = {};
        const traits = [
            'action.devices.traits.OnOff',
        ];
        if (service.characteristics.find(x => x.type === hap_types_1.Characteristic.Brightness)) {
            traits.push('action.devices.traits.Brightness');
        }
        if (service.characteristics.find(x => x.type === hap_types_1.Characteristic.Hue)) {
            traits.push('action.devices.traits.ColorSetting');
            attributes.colorModel = 'hsv';
            attributes.colorTemp;
        }
        return {
            id: service.uniqueId,
            type: 'action.devices.types.LIGHT',
            traits,
            attributes,
            name: {
                defaultNames: [
                    service.serviceName,
                    service.accessoryInformation.Name,
                ],
                name: service.serviceName,
                nicknames: [],
            },
            willReportState: true,
            deviceInfo: {
                manufacturer: service.accessoryInformation.Manufacturer,
                model: service.accessoryInformation.Model,
            },
            customData: {
                aid: service.aid,
                iid: service.iid,
                instanceUsername: service.instance.username,
                instanceIpAddress: service.instance.ipAddress,
                instancePort: service.instance.port,
            },
        };
    }
    query(service) {
        const response = {
            on: service.characteristics.find(x => x.type === hap_types_1.Characteristic.On).value,
            online: true,
        };
        if (service.characteristics.find(x => x.type === hap_types_1.Characteristic.Brightness)) {
            response.brightness = service.characteristics.find(x => x.type === hap_types_1.Characteristic.Brightness).value;
        }
        if (service.characteristics.find(x => x.type === hap_types_1.Characteristic.Hue)) {
            response.color = {
                spectrumHsv: {
                    hue: service.characteristics.find(x => x.type === hap_types_1.Characteristic.Hue).value,
                    saturation: service.characteristics.find(x => x.type === hap_types_1.Characteristic.Saturation).value / 100,
                    value: 1,
                },
            };
        }
        return response;
    }
    execute(service, command) {
        if (!command.execution.length) {
            return { characteristics: [] };
        }
        switch (command.execution[0].command) {
            case ('action.devices.commands.OnOff'): {
                return {
                    characteristics: [{
                            aid: service.aid,
                            iid: service.characteristics.find(x => x.type === hap_types_1.Characteristic.On).iid,
                            value: command.execution[0].params.on,
                        }],
                };
            }
            case ('action.devices.commands.BrightnessAbsolute'): {
                return {
                    characteristics: [{
                            aid: service.aid,
                            iid: service.characteristics.find(x => x.type === hap_types_1.Characteristic.Brightness).iid,
                            value: command.execution[0].params.brightness,
                        },
                        {
                            aid: service.aid,
                            iid: service.characteristics.find(x => x.type === hap_types_1.Characteristic.On).iid,
                            value: command.execution[0].params.brightness ? true : false,
                        }],
                };
            }
            case ('action.devices.commands.ColorAbsolute'): {
                return {
                    characteristics: [{
                            aid: service.aid,
                            iid: service.characteristics.find(x => x.type === hap_types_1.Characteristic.Hue).iid,
                            value: command.execution[0].params.color.spectrumHSV.hue,
                        }, {
                            aid: service.aid,
                            iid: service.characteristics.find(x => x.type === hap_types_1.Characteristic.Saturation).iid,
                            value: command.execution[0].params.color.spectrumHSV.saturation * 100,
                        }],
                };
            }
        }
    }
}
exports.Lightbulb = Lightbulb;
//# sourceMappingURL=lightbulb.js.map