2018-10-02 12:15:12 -07:00
|
|
|
// Xiaomi uses 4151 and 4447 (lumi.plug) as manufacturer ID.
|
|
|
|
const xiaomiManufacturerID = [4151, 4447];
|
2019-02-01 11:04:49 -07:00
|
|
|
const ikeaTradfriManufacturerID = [4476];
|
2018-10-02 12:15:12 -07:00
|
|
|
|
2019-03-02 08:47:36 -07:00
|
|
|
// construct a local ISO8601 string (instead of UTC-based)
|
|
|
|
// Example:
|
|
|
|
// - ISO8601 (UTC) = 2019-03-01T15:32:45.941+0000
|
|
|
|
// - ISO8601 (local) = 2019-03-01T16:32:45.941+0100 (for timezone GMT+1)
|
|
|
|
function toLocalISOString(dDate) {
|
|
|
|
const tzOffset = -dDate.getTimezoneOffset();
|
|
|
|
const plusOrMinus = tzOffset >= 0 ? '+' : '-';
|
|
|
|
const pad = function(num) {
|
|
|
|
const norm = Math.floor(Math.abs(num));
|
|
|
|
return (norm < 10 ? '0' : '') + norm;
|
|
|
|
};
|
|
|
|
|
|
|
|
return dDate.getFullYear() +
|
|
|
|
'-' + pad(dDate.getMonth() + 1) +
|
|
|
|
'-' + pad(dDate.getDate()) +
|
|
|
|
'T' + pad(dDate.getHours()) +
|
|
|
|
':' + pad(dDate.getMinutes()) +
|
|
|
|
':' + pad(dDate.getSeconds()) +
|
|
|
|
plusOrMinus + pad(tzOffset / 60) +
|
|
|
|
':' + pad(tzOffset % 60);
|
|
|
|
}
|
|
|
|
|
2019-03-15 13:19:42 -07:00
|
|
|
const postfixes = [
|
|
|
|
'left', 'right', 'center', 'bottom_left', 'bottom_right',
|
|
|
|
'top_left', 'top_right', 'white', 'rgb', 'system', 'top', 'bottom',
|
|
|
|
];
|
|
|
|
|
2018-10-02 12:15:12 -07:00
|
|
|
module.exports = {
|
|
|
|
millisecondsToSeconds: (milliseconds) => milliseconds / 1000,
|
|
|
|
secondsToMilliseconds: (seconds) => seconds * 1000,
|
|
|
|
isXiaomiDevice: (device) => xiaomiManufacturerID.includes(device.manufId),
|
2019-02-01 11:04:49 -07:00
|
|
|
isIkeaTradfriDevice: (device) => ikeaTradfriManufacturerID.includes(device.manufId),
|
2018-12-21 16:07:53 -07:00
|
|
|
isNumeric: (string) => /^\d+$/.test(string),
|
2019-03-02 08:47:36 -07:00
|
|
|
toLocalISOString: (dDate) => toLocalISOString(dDate),
|
2019-03-15 13:19:42 -07:00
|
|
|
getPostfixes: () => postfixes,
|
2018-10-02 12:15:12 -07:00
|
|
|
};
|