node-red-contrib-home-assistant-websocket
Version:
Node-RED integration with Home Assistant through websocket and REST API
27 lines (26 loc) • 951 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.inZone = inZone;
exports.getLocationData = getLocationData;
exports.getZoneData = getZoneData;
const geolib_1 = require("geolib");
function inZone(location, zone) {
const { radius = 0, ...zoneLatLog } = zone;
const inZone = (0, geolib_1.isPointWithinRadius)(location, zoneLatLog, radius);
return inZone;
}
function getLocationData(entity) {
const coord = {
latitude: entity.attributes.latitude,
longitude: entity.attributes.longitude,
};
return (0, geolib_1.isValidCoordinate)(coord) ? coord : undefined;
}
function getZoneData(zone) {
var _a;
const data = getLocationData(zone);
if (data === undefined || ((_a = zone === null || zone === void 0 ? void 0 : zone.attributes) === null || _a === void 0 ? void 0 : _a.radius) === undefined)
return;
data.radius = zone.attributes.radius;
return data;
}
;