-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/car-health-data
- Loading branch information
Showing
18 changed files
with
821 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
SOURCE= custom_components | ||
|
||
PYTEST= pytest | ||
|
||
all: | ||
|
||
lint: | ||
ruff check $(SOURCE) | ||
|
||
reformat: | ||
ruff check --select I --fix $(SOURCE) | ||
ruff format $(SOURCE) | ||
ruff check --select I --fix $(SOURCE) tests | ||
ruff format $(SOURCE) tests | ||
|
||
test: | ||
PYTHONPATH=. $(PYTEST) -vv tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
"""Support for Polestar binary sensors.""" | ||
|
||
import logging | ||
|
||
from homeassistant.components.binary_sensor import ( | ||
BinarySensorDeviceClass, | ||
BinarySensorEntity, | ||
BinarySensorEntityDescription, | ||
) | ||
from homeassistant.const import EntityCategory | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from .const import DOMAIN as POLESTAR_API_DOMAIN | ||
from .data import PolestarConfigEntry | ||
from .entity import PolestarEntity | ||
from .polestar import PolestarCar | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
ENTITY_DESCRIPTIONS = ( | ||
BinarySensorEntityDescription( | ||
key="api_connected", | ||
name="API Connected", | ||
device_class=BinarySensorDeviceClass.CONNECTIVITY, | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
), | ||
) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, # noqa: ARG001 Unused function argument: `hass` | ||
entry: PolestarConfigEntry, | ||
async_add_entities: AddEntitiesCallback, | ||
) -> None: | ||
"""Set up the binary_sensor platform.""" | ||
async_add_entities( | ||
PolestarBinarySensor( | ||
car=car, | ||
entity_description=entity_description, | ||
) | ||
for entity_description in ENTITY_DESCRIPTIONS | ||
for car in entry.runtime_data.cars | ||
) | ||
|
||
|
||
class PolestarBinarySensor(PolestarEntity, BinarySensorEntity): | ||
"""integration_blueprint binary_sensor class.""" | ||
|
||
def __init__( | ||
self, | ||
car: PolestarCar, | ||
entity_description: BinarySensorEntityDescription, | ||
) -> None: | ||
"""Initialize the binary_sensor class.""" | ||
super().__init__(car) | ||
self.car = car | ||
self.entity_description = entity_description | ||
self.entity_id = f"{POLESTAR_API_DOMAIN}.'polestar_'.{car.get_short_id()}_{entity_description.key}" | ||
self._attr_unique_id = ( | ||
f"polestar_{car.get_unique_id()}_{entity_description.key}" | ||
) | ||
self._attr_translation_key = f"polestar_{entity_description.key}" | ||
|
||
@property | ||
def is_on(self) -> bool | None: | ||
"""Return true if the binary_sensor is on.""" | ||
return self.car.data.get(self.entity_description.key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"""Provides diagnostics for Polestar API.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
from homeassistant.components.diagnostics import async_redact_data | ||
from homeassistant.const import CONF_PASSWORD | ||
from homeassistant.core import HomeAssistant | ||
|
||
from .data import PolestarConfigEntry | ||
|
||
TO_REDACT = {CONF_PASSWORD} | ||
|
||
|
||
async def async_get_config_entry_diagnostics( | ||
hass: HomeAssistant, entry: PolestarConfigEntry | ||
) -> dict[str, Any]: | ||
"""Return diagnostics for a config entry.""" | ||
|
||
coordinator = entry.runtime_data.coordinator | ||
cars = entry.runtime_data.cars | ||
api = coordinator.polestar_api | ||
|
||
return { | ||
"config_entry_data": async_redact_data(dict(entry.data), TO_REDACT), | ||
"cars": [{"vin": car.vin, "model": car.model} for car in cars], | ||
"auth_api": { | ||
"oidc_provider": api.auth.oidc_provider, | ||
"access_token_valid": api.auth.is_token_valid(), | ||
"endpoint": api.auth.api_url, | ||
"status": api.auth.latest_call_code, | ||
}, | ||
"data_api": {"endpoint": api.api_url, "status": api.latest_call_code}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.