<commit_before>const dayjs = require('dayjs');
const colorUtils = require("./color");

//
// HUE BRIDGE
class HueBridgeMessage
{
	constructor(resource, options = {})
	{
		this.message = {};
		this.message.payload = {};
		this.message.payload.id = resource.bridgeid;
		this.message.payload.name = resource.name;
		this.message.payload.factoryNew = resource.factorynew;
		this.message.payload.replacesBridgeId = resource.replacesbridgeid ? resource.replacesbridgeid : false;
		this.message.payload.dataStoreVersion = resource.datastoreversion;
		this.message.payload.starterKitId = resource.starterkitid && resource.starterkitid.length > 0 ? resource.starterkitid : false;
		this.message.payload.softwareVersion = resource.swversion;
		this.message.payload.apiVersion = resource.apiversion;
		this.message.payload.zigbeeChannel = resource.zigbeechannel;
		this.message.payload.macAddress = resource.mac;
		this.message.payload.ipAddress = resource.ipaddress;
		this.message.payload.dhcpEnabled = resource.dhcp;
		this.message.payload.netmask = resource.netmask;
		this.message.payload.gateway = resource.gateway;
		this.message.payload.proxyAddress = resource.proxyaddress == "none" ? false : resource.proxyaddress;
		this.message.payload.proxyPort = resource.proxyport;
		this.message.payload.utcTime = resource.UTC;
		this.message.payload.timeZone = resource.timezone;
		this.message.payload.localTime = resource.localtime;
		this.message.payload.portalServicesEnabled = resource.portalservices;
		this.message.payload.portalConnected = resource.portalconnection;
		this.message.payload.linkButtonEnabled = resource.linkbutton;
		this.message.payload.touchlinkEnabled = (resource["touchlink"] && resource["touchlink"] == true) ? true : false;
		this.message.payload.autoUpdatesEnabled = options["autoupdate"] ? options["autoupdate"] : false;
		this.message.payload.users = [];
		this.message.payload.updated = resource.updated;

		this.message.payload.model = {};
		this.message.payload.model.id = resource.modelid;
		this.message.payload.model.manufacturer = "Philips";
		this.message.payload.model.name = "Hue v2";

		// GET USERS
		if (resource["whitelist"]) {
			for (const [userID, user] of Object.entries(resource["whitelist"]))
			{
				this.message.payload.users.push({
					user: userID,
					name: user["name"],
					created: user["create date"],
					lastAccess: user["last use date"]
				});
			}
		}
	}

	get msg()
	{
		return this.message;
	}
}


//
// HUE BRIGHTNESS
class HueBrightnessMessage
{
	constructor(resource, options = {})
	{
		const service = Object.values(resource["services"]["light_level"])[0];
		const connectivity = resource.services.zigbee_connectivity ? Object.values(resource.services.zigbee_connectivity)[0] : ((resource.services.zgp_connectivity) ? Object.values(resource.services.zgp_connectivity)[0] : false);

		var realLUX = service.light.light_level - 1;
		realLUX = realLUX / 10000;
		realLUX = Math.round(Math.pow(10, realLUX));

		this.message = {};
		this.message.payload = {};
		this.message.payload.active = service.enabled;
		this.message.payload.reachable = connectivity ? (connectivity.status === "connected") : "unknown";
		this.message.payload.connectionStatus = connectivity ? connectivity.status : "unknown";
		this.message.payload.lux = realLUX;
		this.message.payload.lightLevel = service.light.light_level;
		this.message.payload.dark = (realLUX < 90);
		this.message.payload.daylight = (realLUX >= 90);
		this.message.payload.updated = resource.updated;

		this.message.info = {};
		this.message.info.id = service.id;
		this.message.info.idV1 = resource.id_v1 ? resource.id_v1 : false;
		this.message.info.uniqueId = resource.id + "-" + service.id;
		this.message.info.deviceId = resource.id;
		this.message.info.name = resource.metadata.name;
		this.message.info.type = "light_level";
		this.message.info.softwareVersion = resource.product_data.software_version;
		this.message.info.battery = Object.values(resource.services.device_power)[0].power_state.battery_level;
		this.message.info.batteryState = Object.values(resource.services.device_power)[0].power_state.battery_state;

		this.message.info.model = {};
		this.message.info.model.id = resource.product_data.model_id;
		this.message.info.model.manufacturer = resource.product_data.manufacturer_name;
		this.message.info.model.name = resource.product_data.product_name;
		this.message.info.model.type = resource.product_data.product_archetype;
		this.message.info.model.certified = resource.product_data.certified;
	}

	get msg()
	{
		return this.message;
	}
}


//
// HUE GROUP
class HueGroupMessage
{
	constructor(resource, options = {})
	{
		let service = Object.values(resource["services"]["grouped_light"])[0];
		service = options.resources[service.id];

		// GET ALL RESOURCES
		let allResourcesInsideGroup = {};
		for (const [type, resources] of Object.entries(resource["services"]))
		{
			allResourcesInsideGroup[type] = Object.keys(resource["services"][type]);
		}

		this.message = {};
		this.message.payload = {};
		this.message.payload.on = service.on.on;
		this.message.payload.updated = resource.updated;

		this.message.info = {};
		this.message.info.id = resource.id;
		this.message.info.idV1 = resource.id_v1 ? resource.id_v1 : false;
		this.message.info.name = resource.metadata ? resource.metadata.name : "all";
		this.message.info.resources = allResourcesInsideGroup;
		this.message.info.type = "group";
	}

	get msg()
	{
		return this.message;
	}
}


//
// HUE LIGHT
class HueLightMessage
{
	constructor(resource, options = {})<commit_msg>Update messages.js<commit_after>const dayjs = require('dayjs');
const colorUtils = require("./color");

//
// HUE BRIDGE
class HueBridgeMessage
{
	constructor(resource, options = {})
	{
		this.message = {};
		this.message.payload = {};
		this.message.payload.id = resource.bridgeid;
		this.message.payload.name = resource.name;
		this.message.payload.factoryNew = resource.factorynew;
		this.message.payload.replacesBridgeId = resource.replacesbridgeid ? resource.replacesbridgeid : false;
		this.message.payload.dataStoreVersion = resource.datastoreversion;
		this.message.payload.starterKitId = resource.starterkitid && resource.starterkitid.length > 0 ? resource.starterkitid : false;
		this.message.payload.softwareVersion = resource.swversion;
		this.message.payload.apiVersion = resource.apiversion;
		this.message.payload.zigbeeChannel = resource.zigbeechannel;
		this.message.payload.macAddress = resource.mac;
		this.message.payload.ipAddress = resource.ipaddress;
		this.message.payload.dhcpEnabled = resource.dhcp;
		this.message.payload.netmask = resource.netmask;
		this.message.payload.gateway = resource.gateway;
		this.message.payload.proxyAddress = resource.proxyaddress == "none" ? false : resource.proxyaddress;
		this.message.payload.proxyPort = resource.proxyport;
		this.message.payload.utcTime = resource.UTC;
		this.message.payload.timeZone = resource.timezone;
		this.message.payload.localTime = resource.localtime;
		this.message.payload.portalServicesEnabled = resource.portalservices;
		this.message.payload.portalConnected = resource.portalconnection;
		this.message.payload.linkButtonEnabled = resource.linkbutton;
		this.message.payload.touchlinkEnabled = (resource["touchlink"] && resource["touchlink"] == true) ? true : false;
		this.message.payload.autoUpdatesEnabled = options["autoupdate"] ? options["autoupdate"] : false;
		this.message.payload.users = [];
		this.message.payload.updated = resource.updated;

		this.message.payload.model = {};
		this.message.payload.model.id = resource.modelid;
		this.message.payload.model.manufacturer = "Philips";
		this.message.payload.model.name = "Hue v2";

		// GET USERS
		if (resource["whitelist"]) {
			for (const [userID, user] of Object.entries(resource["whitelist"]))
			{
				this.message.payload.users.push({
					user: userID,
					name: user["name"],
					created: user["create date"],
					lastAccess: user["last use date"]
				});
			}
		}
	}

	get msg()
	{
		return this.message;
	}
}


//
// HUE BRIGHTNESS
class HueBrightnessMessage
{
	constructor(resource, options = {})
	{
		const service = Object.values(resource["services"]["light_level"])[0];
		const connectivity = resource.services.zigbee_connectivity ? Object.values(resource.services.zigbee_connectivity)[0] : ((resource.services.zgp_connectivity) ? Object.values(resource.services.zgp_connectivity)[0] : false);

		var realLUX = service.light.light_level - 1;
		realLUX = realLUX / 10000;
		realLUX = Math.round(Math.pow(10, realLUX));

		this.message = {};
		this.message.payload = {};
		this.message.payload.active = service.enabled;
		this.message.payload.reachable = connectivity ? (connectivity.status === "connected") : "unknown";
		this.message.payload.connectionStatus = connectivity ? connectivity.status : "unknown";
		this.message.payload.lux = realLUX;
		this.message.payload.lightLevel = service.light.light_level;
		this.message.payload.dark = (realLUX < 90);
		this.message.payload.daylight = (realLUX >= 90);
		this.message.payload.updated = resource.updated;

		this.message.info = {};
		this.message.info.id = service.id;
		this.message.info.idV1 = resource.id_v1 ? resource.id_v1 : false;
		this.message.info.uniqueId = resource.id + "-" + service.id;
		this.message.info.deviceId = resource.id;
		this.message.info.name = resource.metadata.name;
		this.message.info.type = "light_level";
		this.message.info.softwareVersion = resource.product_data.software_version;
		this.message.info.battery = Object.values(resource.services.device_power)[0].power_state.battery_level;
		this.message.info.batteryState = Object.values(resource.services.device_power)[0].power_state.battery_state;

		this.message.info.model = {};
		this.message.info.model.id = resource.product_data.model_id;
		this.message.info.model.manufacturer = resource.product_data.manufacturer_name;
		this.message.info.model.name = resource.product_data.product_name;
		this.message.info.model.type = resource.product_data.product_archetype;
		this.message.info.model.certified = resource.product_data.certified;
	}

	get msg()
	{
		return this.message;
	}
}


//
// HUE GROUP
class HueGroupMessage
{
	constructor(resource, options = {})
	{
		let service = Object.values(resource["services"]["grouped_light"])[0];
		let onOff = service.on.on;
		service = options.resources[service.id];

		// GET ALL RESOURCES
		let allResourcesInsideGroup = {};
		for (const [type, resources] of Object.entries(resource["services"]))
		{
			allResourcesInsideGroup[type] = Object.keys(resource["services"][type]);
		}

		this.message = {};
		this.message.payload = {};
		this.message.payload.on = onOff;
		this.message.payload.updated = resource.updated;

		this.message.info = {};
		this.message.info.id = resource.id;
		this.message.info.idV1 = resource.id_v1 ? resource.id_v1 : false;
		this.message.info.name = resource.metadata ? resource.metadata.name : "all";
		this.message.info.resources = allResourcesInsideGroup;
		this.message.info.type = "group";
	}

	get msg()
	{
		return this.message;
	}
}


//
// HUE LIGHT
class HueLightMessage
{
	constructor(resource, options = {})
{'fraction_non_alphanumeric': 0.1392665474060823, 'fraction_numerical': 0.004651162790697674, 'mean_word_length': 4.532409698169223, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2853472', 'n_tokens_mistral': 3850, 'n_tokens_neox': 3532, 'n_words': 518}