def async_update(self): """Update state of entity. This method is a coroutine. """ if not self.last_seen: return if self.location_name: self._state = self.location_name elif self.gps is not None and self.source_type == SOURCE_TYPE_GPS: zone_state = async_active_zone( self.hass, self.gps[0], self.gps[1], self.gps_accuracy) if zone_state is None: self._state = STATE_NOT_HOME elif zone_state.entity_id == zone.ENTITY_ID_HOME: self._state = STATE_HOME else: self._state = zone_state.name elif self.stale(): self._state = STATE_NOT_HOME self.gps = None self.last_update_home = False else: self._state = STATE_HOME self.last_update_home = True
async def async_update(self): """Update state of entity. This method is a coroutine. """ if not self.last_seen: return if self.location_name: self._state = self.location_name elif self.gps is not None and self.source_type == SOURCE_TYPE_GPS: zone_state = async_active_zone(self.hass, self.gps[0], self.gps[1], self.gps_accuracy) if zone_state is None: self._state = STATE_NOT_HOME elif zone_state.entity_id == zone.ENTITY_ID_HOME: self._state = STATE_HOME else: self._state = zone_state.name elif self.stale(): self._state = STATE_NOT_HOME self.gps = None self.last_update_home = False else: self._state = STATE_HOME self.last_update_home = True
async def get(self, request: Request): """Handle for GPSLogger message received as GET.""" hass = request.app['hass'] data = request.query if self._password is not None: authenticated = CONF_API_PASSWORD in data and compare_digest( self._password, data[CONF_API_PASSWORD]) if not authenticated: raise HTTPUnauthorized() if 'latitude' not in data or 'longitude' not in data: return ('Latitude and longitude not specified.', HTTP_UNPROCESSABLE_ENTITY) if 'device' not in data: _LOGGER.error("Device id not specified") return ('Device id not specified.', HTTP_UNPROCESSABLE_ENTITY) device = data['device'].replace('-', '') gps_location = (data['latitude'], data['longitude']) accuracy = 200 battery = -1 zone_state = async_active_zone(self.hass, float(data['latitude']), float(data['longitude']), 300) if self._ignore_home and zone_state != None and zone_state.entity_id == zone.ENTITY_ID_HOME: _LOGGER.warn("drop a gps event, because it near home") return if 'accuracy' in data: accuracy = int(float(data['accuracy'])) if 'battery' in data: battery = float(data['battery']) attrs = {} if 'speed' in data: attrs['speed'] = float(data['speed']) if 'direction' in data: attrs['direction'] = float(data['direction']) if 'altitude' in data: attrs['altitude'] = float(data['altitude']) if 'provider' in data: attrs['provider'] = data['provider'] if 'activity' in data: attrs['activity'] = data['activity'] #{{{dylan attrs['update_at'] = int(round(time.time() * 1000)) #}}} hass.async_add_job( self.async_see(dev_id=device, gps=gps_location, battery=battery, gps_accuracy=accuracy, attributes=attrs)) return 'Setting location for {}'.format(device)