Skip to content

Commit

Permalink
implemented geofence with ioBroker Visu app
Browse files Browse the repository at this point in the history
  • Loading branch information
foxriver76 committed Apr 9, 2024
1 parent 89db6de commit f38ca0b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ setState('iot.0.app.message', JSON.stringify({
-->

## Changelog
### **WORK IN PROGRESS**
* (foxriver76) implemented geofence with ioBroker Visu app

### 3.1.0 (2024-02-05)
* (bluefox) Updated packages
* (bluefox) Disabled the state change report for alexa v3
Expand Down
38 changes: 37 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,43 @@ async function processMessage(type, request) {
request = request.toString();
}

return { result: 'not yet implemented' };
try {
/** @type {{ presence: Record<string, boolean> }} */
const visuData = JSON.parse(request);

await adapter.setObjectNotExistsAsync('app.geofence', {
type: 'folder',
common: {
name: 'Geofence',
desc: 'Collection of all the Geofence-locations managed by ioBroker Visu App'
},
native: {}
});

for (const [locationName, presenceStatus] of Object.entries(visuData.presence)) {
const id = `app.geofence.${locationName}`;

await adapter.setObjectNotExistsAsync(id, {
type: 'state',
common: {
name: locationName,
desc: `Geofence Status of ${locationName}`,
type: 'boolean',
read: true,
write: false,
role: 'indicator'
},
native: {}
});

await adapter.setForeignStateAsync(id, presenceStatus, true);
}
} catch (e) {
adapter.log.error(`Could not handle data "${request}" by Visu App: ${e.message}`)
return { error: e.message }
}

return { result: 'Ok' };
} else if (
adapter.config.allowedServices[0] === '*' ||
(adapter.config.allowedServices.includes(_type) || ALLOWED_SERVICES.includes(_type))
Expand Down

0 comments on commit f38ca0b

Please sign in to comment.