hass-core/homeassistant/components/subaru/entity.py
Garrett a019f076c0
Subaru integration code quality changes (#48193)
* Apply changes from code review

* Update sensor tests

* Fix pylint error

* Apply suggestions from code review

Co-authored-by: Brandon Rothweiler <brandonrothweiler@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

Co-authored-by: Brandon Rothweiler <brandonrothweiler@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2021-03-26 04:24:37 +01:00

34 lines
1 KiB
Python

"""Base class for all Subaru Entities."""
from homeassistant.helpers.update_coordinator import CoordinatorEntity
from .const import DOMAIN, MANUFACTURER, VEHICLE_NAME, VEHICLE_VIN
class SubaruEntity(CoordinatorEntity):
"""Representation of a Subaru Entity."""
def __init__(self, vehicle_info, coordinator):
"""Initialize the Subaru Entity."""
super().__init__(coordinator)
self.car_name = vehicle_info[VEHICLE_NAME]
self.vin = vehicle_info[VEHICLE_VIN]
self.entity_type = "entity"
@property
def name(self):
"""Return name."""
return f"{self.car_name} {self.entity_type}"
@property
def unique_id(self) -> str:
"""Return a unique ID."""
return f"{self.vin}_{self.entity_type}"
@property
def device_info(self):
"""Return the device_info of the device."""
return {
"identifiers": {(DOMAIN, self.vin)},
"name": self.car_name,
"manufacturer": MANUFACTURER,
}