Migrate Tractive to new entity naming style (#75184)

This commit is contained in:
Maciej Bieniek 2022-07-17 15:01:26 +02:00 committed by GitHub
parent d8f3044ffa
commit cd223d91bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 12 deletions

View File

@ -31,13 +31,14 @@ TRACKERS_WITH_BUILTIN_BATTERY = ("TRNJA4", "TRAXL1")
class TractiveBinarySensor(TractiveEntity, BinarySensorEntity):
"""Tractive sensor."""
_attr_has_entity_name = True
def __init__(
self, user_id: str, item: Trackables, description: BinarySensorEntityDescription
) -> None:
"""Initialize sensor entity."""
super().__init__(user_id, item.trackable, item.tracker_details)
self._attr_name = f"{item.trackable['details']['name']} {description.name}"
self._attr_unique_id = f"{item.trackable['_id']}_{description.key}"
self.entity_description = description
@ -76,7 +77,7 @@ class TractiveBinarySensor(TractiveEntity, BinarySensorEntity):
SENSOR_TYPE = BinarySensorEntityDescription(
key=ATTR_BATTERY_CHARGING,
name="Battery Charging",
name="Tracker battery charging",
device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
entity_category=EntityCategory.DIAGNOSTIC,
)

View File

@ -40,7 +40,9 @@ async def async_setup_entry(
class TractiveDeviceTracker(TractiveEntity, TrackerEntity):
"""Tractive device tracker."""
_attr_has_entity_name = True
_attr_icon = "mdi:paw"
_attr_name = "Tracker"
def __init__(self, user_id: str, item: Trackables) -> None:
"""Initialize tracker entity."""
@ -51,8 +53,6 @@ class TractiveDeviceTracker(TractiveEntity, TrackerEntity):
self._longitude: float = item.pos_report["latlong"][1]
self._accuracy: int = item.pos_report["pos_uncertainty"]
self._source_type: str = item.pos_report["sensor_used"]
self._attr_name = f"{self._tracker_id} {item.trackable['details']['name']}"
self._attr_unique_id = item.trackable["_id"]
@property

View File

@ -18,7 +18,7 @@ class TractiveEntity(Entity):
self._attr_device_info = DeviceInfo(
configuration_url="https://my.tractive.com/",
identifiers={(DOMAIN, tracker_details["_id"])},
name=f"Tractive ({tracker_details['_id']})",
name=trackable["details"]["name"],
manufacturer="Tractive GmbH",
sw_version=tracker_details["fw_version"],
model=tracker_details["model_number"],

View File

@ -48,6 +48,8 @@ class TractiveSensorEntityDescription(
class TractiveSensor(TractiveEntity, SensorEntity):
"""Tractive sensor."""
_attr_has_entity_name = True
def __init__(
self,
user_id: str,
@ -57,7 +59,6 @@ class TractiveSensor(TractiveEntity, SensorEntity):
"""Initialize sensor entity."""
super().__init__(user_id, item.trackable, item.tracker_details)
self._attr_name = f"{item.trackable['details']['name']} {description.name}"
self._attr_unique_id = f"{item.trackable['_id']}_{description.key}"
self.entity_description = description
@ -133,7 +134,7 @@ class TractiveActivitySensor(TractiveSensor):
SENSOR_TYPES: tuple[TractiveSensorEntityDescription, ...] = (
TractiveSensorEntityDescription(
key=ATTR_BATTERY_LEVEL,
name="Battery Level",
name="Tracker battery level",
native_unit_of_measurement=PERCENTAGE,
device_class=SensorDeviceClass.BATTERY,
entity_class=TractiveHardwareSensor,
@ -149,14 +150,14 @@ SENSOR_TYPES: tuple[TractiveSensorEntityDescription, ...] = (
),
TractiveSensorEntityDescription(
key=ATTR_MINUTES_ACTIVE,
name="Minutes Active",
name="Minutes active",
icon="mdi:clock-time-eight-outline",
native_unit_of_measurement=TIME_MINUTES,
entity_class=TractiveActivitySensor,
),
TractiveSensorEntityDescription(
key=ATTR_DAILY_GOAL,
name="Daily Goal",
name="Daily goal",
icon="mdi:flag-checkered",
native_unit_of_measurement=TIME_MINUTES,
entity_class=TractiveActivitySensor,

View File

@ -47,7 +47,7 @@ class TractiveSwitchEntityDescription(
SWITCH_TYPES: tuple[TractiveSwitchEntityDescription, ...] = (
TractiveSwitchEntityDescription(
key=ATTR_BUZZER,
name="Tracker Buzzer",
name="Tracker buzzer",
icon="mdi:volume-high",
method="async_set_buzzer",
entity_category=EntityCategory.CONFIG,
@ -61,7 +61,7 @@ SWITCH_TYPES: tuple[TractiveSwitchEntityDescription, ...] = (
),
TractiveSwitchEntityDescription(
key=ATTR_LIVE_TRACKING,
name="Live Tracking",
name="Live tracking",
icon="mdi:map-marker-path",
method="async_set_live_tracking",
entity_category=EntityCategory.CONFIG,
@ -88,6 +88,7 @@ async def async_setup_entry(
class TractiveSwitch(TractiveEntity, SwitchEntity):
"""Tractive switch."""
_attr_has_entity_name = True
entity_description: TractiveSwitchEntityDescription
def __init__(
@ -99,7 +100,6 @@ class TractiveSwitch(TractiveEntity, SwitchEntity):
"""Initialize switch entity."""
super().__init__(user_id, item.trackable, item.tracker_details)
self._attr_name = f"{item.trackable['details']['name']} {description.name}"
self._attr_unique_id = f"{item.trackable['_id']}_{description.key}"
self._attr_available = False
self._tracker = item.tracker