GPS coordinates from device (#12521)

* GPS coords from device
in yaml or php
define for epmp, airos, and airos-af-ltu
quirk for airos bug with - in the middle of the number

* style fixes

* revert airos-af-ltu mempool change

* fix imports

* add epmp test data... more improvements to come there.

* don't stagger geocoding now that this is moved to discovery
also, no need to check OSDiscovery since the base implements it.

* fix json data

* fixed
This commit is contained in:
Tony Murray
2021-02-14 20:36:55 -06:00
committed by GitHub
parent f9a379fa3c
commit 8b105ba162
14 changed files with 902 additions and 98 deletions

View File

@@ -324,15 +324,33 @@ class Device extends BaseModel
return $this->attribs->pluck('attrib_value', 'attrib_type')->toArray();
}
public function setLocation($location_text)
/**
* Update the location to the correct location and update GPS if needed
*
* @param \App\Models\Location $location location data
*/
public function setLocation(Location $location)
{
$location_text = $location_text ? Rewrite::location($location_text) : null;
$location->location = $location->location ? Rewrite::location($location->location) : null;
$this->location_id = null;
if ($location_text) {
$location = Location::firstOrCreate(['location' => $location_text]);
if (! $location->location) { // disassociate if the location name is empty
$this->location_id = null;
return;
}
$coord = array_filter($location->only(['lat', 'lng']));
if (! $this->relationLoaded('location') || optional($this->location)->location !== $location->location) {
if (! $location->exists) { // don't fetch if new location persisted to the DB, just use it
$location = Location::firstOrCreate(['location' => $location->location], $coord);
}
$this->location()->associate($location);
}
// save new coords if needed
if ($this->location) {
$this->location->fill($coord)->save();
}
}
// ---- Accessors/Mutators ----