Skip to content

Commit

Permalink
Merge pull request #119 from Snuffy2/Make-GPS-Accuracy-an-Option
Browse files Browse the repository at this point in the history
Make GPS Accuracy an Option
  • Loading branch information
Snuffy2 authored Oct 14, 2022
2 parents 455125c + 095b227 commit 0ca1e0e
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# places
# places
<picture>
<img alt="places Logo" src="https://github.com/custom-components/places/raw/master/logo/icon.png">
</picture>
Expand Down Expand Up @@ -59,9 +59,10 @@ Key | Type | Required | Description | Default |
`api_key` | `string` | `False` | OpenStreetMap API key (your email address). | None
`map_provider` | `string` | `False` | `google`, `apple`, `osm` | `apple`
`map_zoom` | `number` | `False` | Level of zoom for the generated map link <1-20> | `18`
`language` | `string` | `False` | Requested<sup>\*</sup> language(s) for state and attributes. Two-Letter language code(s), separated by commas.<br><sup>\*</sup>Refer to [Notes](#notes) | location's local language
`language` | `string` | `False` | Requested<sup>\*</sup> language(s) for state and attributes. Two-Letter language code(s), separated by commas.<br /><sup>\*</sup>Refer to [Notes](#notes) | location's local language
`extended_attr` | `boolean` | `False` | Show extended attributes: wikidata_id, osm_dict, osm_details_dict, wikidata_dict *(if they exist)*. Provides many additional attributes for advanced logic. **Warning, will make the attributes very long!** | `False`
`show_time` | `boolean` | `False` | Show last updated time at end of state `(since xx:yy)` | `False`
`use_gps_accuracy` | `boolean` | `False` | Use GPS Accuracy when determining whether to update the places sensor (if 0, don't update the places sensor). By not updaing when GPS Accuracy is 0, should prevent inaccurate locations from being set in the places sensors.<br />_Set this to `False` if your devicetracker_id has a GPS Accuracy (`gps_accuracy`) attribute, but it always shows 0 even if the latitude and longitude are correct._ | `True`
`options` | `string` | `False` | Display options: `formatted_place` *(exclusive option)*, `driving` *(can be used with formatted_place or other options)*, `zone` or `zone_name`, `place`, `place_name`, `street_number`, `street`, `city`, `county`, `state`, `postal_code`, `country`, `formatted_address`, `do_not_show_not_home` | `zone`, `place`

Sample attributes that can be used in notifications, alerts, automations, etc:
Expand Down
13 changes: 13 additions & 0 deletions custom_components/places/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@
CONF_MAP_ZOOM,
CONF_OPTIONS,
CONF_SHOW_TIME,
CONF_USE_GPS,
DEFAULT_EXTENDED_ATTR,
DEFAULT_HOME_ZONE,
DEFAULT_MAP_PROVIDER,
DEFAULT_MAP_ZOOM,
DEFAULT_OPTION,
DEFAULT_SHOW_TIME,
DEFAULT_USE_GPS,
DOMAIN,
HOME_LOCATION_DOMAINS,
TRACKING_DOMAINS,
Expand Down Expand Up @@ -240,6 +242,9 @@ async def async_step_user(self, user_input=None) -> FlowResult:
vol.Optional(
CONF_SHOW_TIME, default=DEFAULT_SHOW_TIME
): selector.BooleanSelector(selector.BooleanSelectorConfig()),
vol.Optional(
CONF_USE_GPS, default=DEFAULT_USE_GPS
): selector.BooleanSelector(selector.BooleanSelectorConfig()),
}
)
# If there is no user input or there were errors, show the form again, including any errors that were found with the input.
Expand Down Expand Up @@ -431,6 +436,14 @@ async def async_step_init(self, user_input=None):
else DEFAULT_SHOW_TIME
),
): selector.BooleanSelector(selector.BooleanSelectorConfig()),
vol.Optional(
CONF_USE_GPS,
default=(
self.config_entry.data[CONF_USE_GPS]
if CONF_USE_GPS in self.config_entry.data
else DEFAULT_USE_GPS
),
): selector.BooleanSelector(selector.BooleanSelectorConfig()),
}
)

Expand Down
3 changes: 3 additions & 0 deletions custom_components/places/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
DEFAULT_MAP_ZOOM = 18
DEFAULT_OPTION = "zone_name, place"
DEFAULT_SHOW_TIME = False
DEFAULT_USE_GPS = True

# Settings

Expand All @@ -43,6 +44,7 @@
CONF_NATIVE_VALUE = "native_value"
CONF_OPTIONS = "options"
CONF_SHOW_TIME = "show_time"
CONF_USE_GPS = "use_gps_accuracy"
CONF_YAML_HASH = "yaml_hash"

# Attributes
Expand Down Expand Up @@ -115,6 +117,7 @@
CONF_NAME,
CONF_OPTIONS,
CONF_SHOW_TIME,
CONF_USE_GPS,
CONF_UNIQUE_ID,
]
RESET_ATTRIBUTE_LIST = [
Expand Down
8 changes: 5 additions & 3 deletions custom_components/places/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
CONF_MAP_ZOOM,
CONF_OPTIONS,
CONF_SHOW_TIME,
CONF_USE_GPS,
CONF_YAML_HASH,
CONFIG_ATTRIBUTES_LIST,
DEFAULT_EXTENDED_ATTR,
Expand All @@ -118,6 +119,7 @@
DEFAULT_MAP_ZOOM,
DEFAULT_OPTION,
DEFAULT_SHOW_TIME,
DEFAULT_USE_GPS,
DOMAIN,
EVENT_ATTRIBUTE_LIST,
EXTENDED_ATTRIBUTE_LIST,
Expand Down Expand Up @@ -430,15 +432,14 @@ def __init__(self, hass, config, config_entry, name, unique_id):
self.set_attr(
CONF_LANGUAGE, self.get_attr(CONF_LANGUAGE).replace(" ", "").strip()
)

self.set_attr(
CONF_EXTENDED_ATTR,
config.setdefault(CONF_EXTENDED_ATTR, DEFAULT_EXTENDED_ATTR),
)

self.set_attr(
CONF_SHOW_TIME, config.setdefault(CONF_SHOW_TIME, DEFAULT_SHOW_TIME)
)
self.set_attr(CONF_USE_GPS, config.setdefault(CONF_USE_GPS, DEFAULT_USE_GPS))
self.set_attr(
ATTR_JSON_FILENAME,
(DOMAIN + "-" + slugify(str(self.get_attr(CONF_UNIQUE_ID))) + ".json"),
Expand Down Expand Up @@ -782,6 +783,7 @@ def in_zone(self):
or self.get_attr(ATTR_DEVICETRACKER_ZONE).lower() == "away"
or self.get_attr(ATTR_DEVICETRACKER_ZONE).lower() == "not_home"
or self.get_attr(ATTR_DEVICETRACKER_ZONE).lower() == "notset"
or self.get_attr(ATTR_DEVICETRACKER_ZONE).lower() == "not_set"
):
return False
else:
Expand Down Expand Up @@ -1142,7 +1144,7 @@ def get_gps_accuracy(self):
)
proceed_with_update = True
if not self.is_attr_blank(ATTR_GPS_ACCURACY):
if self.get_attr(ATTR_GPS_ACCURACY) == 0:
if self.get_attr(CONF_USE_GPS) and self.get_attr(ATTR_GPS_ACCURACY) == 0:
proceed_with_update = False
_LOGGER.info(
"("
Expand Down
6 changes: 4 additions & 2 deletions custom_components/places/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"api_key": "Email to use as OpenStreetMap API Key (optional)",
"language": "Language (optional)",
"extended_attr": "Extended Attributes",
"show_time": "Show last updated time at end of state '(since xx:yy)'"
"show_time": "Show last updated time at end of state '(since xx:yy)'",
"use_gps_accuracy": "Use GPS Accuracy"
},
"description": "Create a new sensor"
}
Expand All @@ -33,7 +34,8 @@
"api_key": "Email to use as OpenStreetMap API Key (optional)",
"language": "Language (optional)",
"extended_attr": "Enable Extended Attributes",
"show_time": "Show last updated time at end of state '(since xx:yy)'"
"show_time": "Show last updated time at end of state '(since xx:yy)'",
"use_gps_accuracy": "Use GPS Accuracy"
},
"description": "Update existing sensor"
}
Expand Down
6 changes: 4 additions & 2 deletions custom_components/places/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"api_key": "Email to use as OpenStreetMap API Key (optional)",
"language": "Language (optional)",
"extended_attr": "Enable Extended Attributes",
"show_time": "Show last updated time at end of state '(since xx:yy)'"
"show_time": "Show last updated time at end of state '(since xx:yy)'",
"use_gps_accuracy": "Use GPS Accuracy"
},
"description": "Create a new sensor\nSee [Configuration Options]({component_config_url}) on GitHub for details"
}
Expand All @@ -33,7 +34,8 @@
"api_key": "Email to use as OpenStreetMap API Key (optional)",
"language": "Language (optional)",
"extended_attr": "Enable Extended Attributes",
"show_time": "Show last updated time at end of state '(since xx:yy)'"
"show_time": "Show last updated time at end of state '(since xx:yy)'",
"use_gps_accuracy": "Use GPS Accuracy"
},
"description": "**Updating sensor:&nbsp;{sensor_name}**\nSee [Configuration Options]({component_config_url}) on GitHub for details"
}
Expand Down

0 comments on commit 0ca1e0e

Please sign in to comment.