Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented geofence with ioBroker Visu app #741

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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}`)

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (97% of all statements in
the enclosing function
have an explicit semicolon).
return { error: e.message }

Check notice

Code scanning / CodeQL

Semicolon insertion Note

Avoid automated semicolon insertion (97% of all statements in
the enclosing function
have an explicit semicolon).
}

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