Skip to content

Commit

Permalink
Incorporate PR review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Two committed Jul 2, 2023
1 parent b27dbaa commit 7bc2dee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
26 changes: 12 additions & 14 deletions homeassistant/components/subaru/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from typing import Any

import subarulink.const as sc
from subarulink.const import LATITUDE, LONGITUDE, TIMESTAMP

from homeassistant.components.device_tracker import SourceType
from homeassistant.components.device_tracker.config_entry import TrackerEntity
Expand Down Expand Up @@ -32,13 +32,13 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up the Subaru device tracker by config_entry."""
entry = hass.data[DOMAIN][config_entry.entry_id]
coordinator = entry[ENTRY_COORDINATOR]
vehicle_info = entry[ENTRY_VEHICLES]
entities = []
for info in vehicle_info.values():
if info[VEHICLE_HAS_REMOTE_SERVICE]:
entities.append(SubaruDeviceTracker(info, coordinator))
entry: dict = hass.data[DOMAIN][config_entry.entry_id]
coordinator: DataUpdateCoordinator = entry[ENTRY_COORDINATOR]
vehicle_info: dict = entry[ENTRY_VEHICLES]
entities: list[SubaruDeviceTracker] = []
for vehicle in vehicle_info.values():
if vehicle[VEHICLE_HAS_REMOTE_SERVICE]:
entities.append(SubaruDeviceTracker(vehicle, coordinator))
async_add_entities(entities)


Expand All @@ -49,7 +49,7 @@ class SubaruDeviceTracker(

_attr_icon = "mdi:car"
_attr_has_entity_name = True
name = "Location"
name = None

def __init__(self, vehicle_info: dict, coordinator: DataUpdateCoordinator) -> None:
"""Initialize the device tracker."""
Expand All @@ -66,7 +66,7 @@ def extra_state_attributes(self) -> dict[str, Any] | None:
extra_attributes = {
"Position timestamp": self.coordinator.data[self.vin][
VEHICLE_STATUS
].get(sc.TIMESTAMP)
].get(TIMESTAMP)
}
return extra_attributes

Expand All @@ -75,17 +75,15 @@ def latitude(self) -> float | None:
"""Return latitude value of the vehicle."""
latitude = None
if self.vin in self.coordinator.data:
latitude = self.coordinator.data[self.vin][VEHICLE_STATUS].get(sc.LATITUDE)
latitude = self.coordinator.data[self.vin][VEHICLE_STATUS].get(LATITUDE)
return latitude

@property
def longitude(self) -> float | None:
"""Return longitude value of the vehicle."""
longitude = None
if self.vin in self.coordinator.data:
longitude = self.coordinator.data[self.vin][VEHICLE_STATUS].get(
sc.LONGITUDE
)
longitude = self.coordinator.data[self.vin][VEHICLE_STATUS].get(LONGITUDE)
return longitude

@property
Expand Down
2 changes: 1 addition & 1 deletion tests/components/subaru/test_device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from .api_responses import EXPECTED_STATE_EV_IMPERIAL

DEVICE_ID = "device_tracker.test_vehicle_2_location"
DEVICE_ID = "device_tracker.test_vehicle_2"


async def test_location(hass: HomeAssistant, ev_entry) -> None:
Expand Down

0 comments on commit 7bc2dee

Please sign in to comment.