Skip to content

Commit

Permalink
Merge branch 'dev' into object_creation_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrounger authored Nov 4, 2023
2 parents b61cb37 + d6ce3f6 commit 1177a28
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ Or you can use the tab **files** to upload the file. (see image below)\
-->

### **WORK IN PROGRESS**

- (Scounger) bug fix: objects only if necessary
- (Scrounger) Calculate distance between ioBroker and tracker

### 0.1.2 (2023-02-24)

Expand Down
46 changes: 46 additions & 0 deletions build/lib/object_definition.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions build/main.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion io-package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"common": {
"name": "tractive-gps",
"version": "0.1.2",
"version": "0.1.3",
"news": {
"0.1.2": {
"en": "Dependencies updated\nUI updated",
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iobroker.tractive-gps",
"version": "0.1.2",
"version": "0.1.3",
"description": "This adapter allows you to connect to the Tractive GPS service and retrieve the location of your pets.",
"author": {
"name": "xXBJXx",
Expand Down Expand Up @@ -31,7 +31,8 @@
"cron": "^2.2.0",
"dayjs": "^1.11.7",
"react-leaflet": "3.2.5",
"source-map-support": "^0.5.21"
"source-map-support": "^0.5.21",
"geo-position.ts": "^1.4.1"
},
"devDependencies": {
"@alcalzone/release-script": "^3.5.9",
Expand Down
46 changes: 46 additions & 0 deletions src/lib/object_definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,42 @@ export const stateAttrb: StateAttr = {
read: true,
write: false,
},
prioritized_zone_entered_at: {
name: 'Prioritized zone entered at',
desc: 'Prioritized zone entered at',
type: 'number',
role: 'value',
def: null,
read: true,
write: false,
},
prioritized_zone_last_seen_at: {
name: 'Prioritized zone last seen at',
desc: 'Prioritized zone last seen at',
type: 'number',
role: 'value',
def: null,
read: true,
write: false,
},
prioritized_zone_type: {
name: 'Prioritized zone type',
desc: 'Prioritized zone type',
type: 'string',
role: 'value',
def: null,
read: true,
write: false,
},
prioritized_zone_id: {
name: 'Prioritized zone id',
desc: 'Prioritized zone id',
type: 'string',
role: 'value',
def: null,
read: true,
write: false,
},
hw_status: {
name: 'Hardware Status',
desc: 'Hardware Status of the device',
Expand Down Expand Up @@ -335,6 +371,16 @@ export const stateAttrb: StateAttr = {
read: true,
write: false,
},
distance: {
name: 'Distance',
desc: 'Distance to ioBroker',
type: 'number',
role: 'value.gps.distance',
def: 0,
unit: 'm',
read: true,
write: false,
},
speed: {
name: 'Speed',
desc: 'Speed in meters per second',
Expand Down
21 changes: 21 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as utils from '@iobroker/adapter-core';
// import 'source-map-support/register.js';
import axios from 'axios';
import { CronJob } from 'cron';
import { GeoPosition } from 'geo-position.ts';
import sourceMapSupport from 'source-map-support';
import { decrypt, encrypt } from './lib/Helper';
import { stateAttrb } from './lib/object_definition';
Expand Down Expand Up @@ -199,6 +200,21 @@ class TractiveGPS extends utils.Adapter {
val: value[1],
ack: true,
});

let sysConfig = await this.getForeignObjectAsync('system.config');

if (sysConfig && sysConfig.common && sysConfig.common.longitude && sysConfig.common.latitude) {
let sysPoint = new GeoPosition(sysConfig.common.latitude, sysConfig.common.longitude);
let petPoint = new GeoPosition(value[0], value[1]);

await this.setStateAsync(`${device._id}.device_pos_report.distance`, {
val: Number(sysPoint.Distance(petPoint).toFixed(0)),
ack: true,
});
} else {
this.writeLog('No gps coordinates of system found!', "warn");
}

} else {
if (typeof value === 'object' && value !== null) {
await this.setStateAsync(`${device._id}.device_pos_report.${key}`, {
Expand Down Expand Up @@ -416,6 +432,11 @@ class TractiveGPS extends utils.Adapter {
common: stateAttrb['longitude'],
native: {},
});
await this.extendObjectAsync(`${device._id}.device_pos_report.distance`, {
type: 'state',
common: stateAttrb['distance'],
native: {},
});
} else {
await this.setObjectNotExistsAsync(`${device._id}.device_pos_report.${key}`, {
type: 'state',
Expand Down
4 changes: 4 additions & 0 deletions src/types/TractiveDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export interface Tracker {
charging_state: string;
battery_state: string;
power_saving_zone_id: string | null;
prioritized_zone_entered_at: number | null;
prioritized_zone_last_seen_at: number | null;
prioritized_zone_type: string,
prioritized_zone_id: string
}

export interface DeviceHwReport {
Expand Down

0 comments on commit 1177a28

Please sign in to comment.