Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
HomeAssistant
Core
Commits
a1e6d4b6
Unverified
Commit
a1e6d4b6
authored
6 months ago
by
epenet
Committed by
GitHub
6 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Use shorthand attributes in geofency device tracker (#126741)
parent
77db88ad
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
homeassistant/components/geofency/device_tracker.py
+19
-43
19 additions, 43 deletions
homeassistant/components/geofency/device_tracker.py
with
19 additions
and
43 deletions
homeassistant/components/geofency/device_tracker.py
+
19
−
43
View file @
a1e6d4b6
...
...
@@ -57,44 +57,17 @@ class GeofencyEntity(TrackerEntity, RestoreEntity):
def
__init__
(
self
,
device
,
gps
=
None
,
location_name
=
None
,
attributes
=
None
):
"""
Set up Geofency entity.
"""
self
.
_attributes
=
attributes
or
{}
self
.
_
attr_extra_state_
attributes
=
attributes
or
{}
self
.
_name
=
device
self
.
_location_name
=
location_name
self
.
_gps
=
gps
self
.
_attr_location_name
=
location_name
if
gps
:
self
.
_attr_latitude
=
gps
[
0
]
self
.
_attr_longitude
=
gps
[
1
]
self
.
_unsub_dispatcher
=
None
self
.
_unique_id
=
device
@property
def
extra_state_attributes
(
self
):
"""
Return device specific attributes.
"""
return
self
.
_attributes
@property
def
latitude
(
self
):
"""
Return latitude value of the device.
"""
return
self
.
_gps
[
0
]
@property
def
longitude
(
self
):
"""
Return longitude value of the device.
"""
return
self
.
_gps
[
1
]
@property
def
location_name
(
self
):
"""
Return a location name for the current location of the device.
"""
return
self
.
_location_name
@property
def
unique_id
(
self
):
"""
Return the unique ID.
"""
return
self
.
_unique_id
@property
def
device_info
(
self
)
->
DeviceInfo
:
"""
Return the device info.
"""
return
DeviceInfo
(
identifiers
=
{(
GF_DOMAIN
,
self
.
_unique_id
)},
name
=
self
.
_name
,
self
.
_attr_unique_id
=
device
self
.
_attr_device_info
=
DeviceInfo
(
identifiers
=
{(
GF_DOMAIN
,
device
)},
name
=
device
,
)
async
def
async_added_to_hass
(
self
)
->
None
:
...
...
@@ -104,21 +77,23 @@ class GeofencyEntity(TrackerEntity, RestoreEntity):
self
.
hass
,
TRACKER_UPDATE
,
self
.
_async_receive_data
)
if
self
.
_attributes
:
if
self
.
_
attr_extra_state_
attributes
:
return
if
(
state
:
=
await
self
.
async_get_last_state
())
is
None
:
self
.
_gps
=
(
None
,
None
)
self
.
_attr_latitude
=
None
self
.
_attr_longitude
=
None
return
attr
=
state
.
attributes
self
.
_gps
=
(
attr
.
get
(
ATTR_LATITUDE
),
attr
.
get
(
ATTR_LONGITUDE
))
self
.
_attr_latitude
=
attr
.
get
(
ATTR_LATITUDE
)
self
.
_attr_longitude
=
attr
.
get
(
ATTR_LONGITUDE
)
async
def
async_will_remove_from_hass
(
self
)
->
None
:
"""
Clean up after entity before removal.
"""
await
super
().
async_will_remove_from_hass
()
self
.
_unsub_dispatcher
()
self
.
hass
.
data
[
GF_DOMAIN
][
"
devices
"
].
remove
(
self
.
_
unique_id
)
self
.
hass
.
data
[
GF_DOMAIN
][
"
devices
"
].
remove
(
self
.
unique_id
)
@callback
def
_async_receive_data
(
self
,
device
,
gps
,
location_name
,
attributes
):
...
...
@@ -126,7 +101,8 @@ class GeofencyEntity(TrackerEntity, RestoreEntity):
if
device
!=
self
.
_name
:
return
self
.
_attributes
.
update
(
attributes
)
self
.
_location_name
=
location_name
self
.
_gps
=
gps
self
.
_attr_extra_state_attributes
.
update
(
attributes
)
self
.
_attr_location_name
=
location_name
self
.
_attr_latitude
=
gps
[
0
]
self
.
_attr_longitude
=
gps
[
1
]
self
.
async_write_ha_state
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment