Skip to content

Commit

Permalink
Update to HA 2023.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
rikroe committed May 17, 2023
1 parent 92ea269 commit e97790c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 34 deletions.
8 changes: 8 additions & 0 deletions custom_components/bmw_connected_drive/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,14 @@ class BMWBinarySensorEntityDescription(
icon="mdi:car-electric",
value_fn=lambda v: v.fuel_and_battery.is_charger_connected,
),
BMWBinarySensorEntityDescription(
key="is_pre_entry_climatization_enabled",
name="Pre entry climatization",
icon="mdi:car-seat-heater",
value_fn=lambda v: v.charging_profile.is_pre_entry_climatization_enabled
if v.charging_profile
else False,
),
)


Expand Down
2 changes: 0 additions & 2 deletions custom_components/bmw_connected_drive/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
vol.Required(CONF_USERNAME): str,
vol.Required(CONF_PASSWORD): str,
vol.Required(CONF_REGION): vol.In(CONF_ALLOWED_REGIONS),
vol.Optional(CONF_REFRESH_TOKEN): str,
}
)

Expand All @@ -39,7 +38,6 @@ async def validate_input(
data[CONF_USERNAME],
data[CONF_PASSWORD],
get_region_from_name(data[CONF_REGION]),
refresh_token=data.get(CONF_REFRESH_TOKEN),
)

try:
Expand Down
16 changes: 3 additions & 13 deletions custom_components/bmw_connected_drive/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from homeassistant.const import CONF_PASSWORD, CONF_REGION, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed

from .const import CONF_READ_ONLY, CONF_REFRESH_TOKEN, DOMAIN

Expand Down Expand Up @@ -59,16 +59,9 @@ async def _async_update_data(self) -> None:
except MyBMWAuthError as err:
# Clear refresh token and trigger reauth
self._update_config_entry_refresh_token(None)
raise ConfigEntryAuthFailed(str(err)) from err

raise ConfigEntryAuthFailed(err) from err
except (MyBMWAPIError, RequestError) as err:
if self.last_update_success is True:
_LOGGER.warning(
"Error communicating with BMW API (%s): %s",
type(err).__name__,
err,
)
self.last_update_success = False
raise UpdateFailed(err) from err

if self.account.refresh_token != old_refresh_token:
self._update_config_entry_refresh_token(self.account.refresh_token)
Expand All @@ -78,9 +71,6 @@ async def _async_update_data(self) -> None:
self.account.refresh_token,
)

if self.last_update_success is False:
_LOGGER.info("Reconnected to BMW API")

def _update_config_entry_refresh_token(self, refresh_token: str | None) -> None:
"""Update or delete the refresh_token in the Config Entry."""
data = {
Expand Down
2 changes: 0 additions & 2 deletions custom_components/bmw_connected_drive/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ class BMWNumberEntityDescription(NumberEntityDescription, BMWRequiredKeysMixin):

is_available: Callable[[MyBMWVehicle], bool] = lambda _: False
dynamic_options: Callable[[MyBMWVehicle], list[str]] | None = None
mode: NumberMode = NumberMode.AUTO


NUMBER_TYPES: list[BMWNumberEntityDescription] = [
Expand Down Expand Up @@ -99,7 +98,6 @@ def __init__(
super().__init__(coordinator, vehicle)
self.entity_description = description
self._attr_unique_id = f"{vehicle.vin}-{description.key}"
self._attr_mode = description.mode

@property
def native_value(self) -> float | None:
Expand Down
30 changes: 15 additions & 15 deletions custom_components/bmw_connected_drive/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ def convert_and_round(

SENSOR_TYPES: dict[str, BMWSensorEntityDescription] = {
# --- Generic ---
"ac_current_limit": BMWSensorEntityDescription(
key="ac_current_limit",
name="AC current limit",
key_class="charging_profile",
unit_type=UnitOfElectricCurrent.AMPERE,
icon="mdi:current-ac",
entity_registry_enabled_default=False,
),
"charging_start_time": BMWSensorEntityDescription(
key="charging_start_time",
name="Charging start time",
Expand All @@ -73,28 +81,20 @@ def convert_and_round(
icon="mdi:ev-station",
value=lambda x, y: x.value,
),
"charging_target": BMWSensorEntityDescription(
key="charging_target",
name="Charging target",
key_class="fuel_and_battery",
icon="mdi:battery-charging-high",
unit_type=PERCENTAGE,
),
"remaining_battery_percent": BMWSensorEntityDescription(
key="remaining_battery_percent",
name="Remaining battery percent",
key_class="fuel_and_battery",
unit_type=PERCENTAGE,
device_class=SensorDeviceClass.BATTERY,
),
"ac_current_limit": BMWSensorEntityDescription(
key="ac_current_limit",
name="AC current limit",
key_class="charging_profile",
unit_type=UnitOfElectricCurrent.AMPERE,
icon="mdi:current-ac",
entity_registry_enabled_default=False,
),
"charging_target": BMWSensorEntityDescription(
key="charging_target",
name="Charging target",
key_class="fuel_and_battery",
unit_type=PERCENTAGE,
icon="mdi:battery-charging-high",
),
"charging_mode": BMWSensorEntityDescription(
key="charging_mode",
name="Charging mode",
Expand Down
3 changes: 1 addition & 2 deletions custom_components/bmw_connected_drive/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"data": {
"username": "[%key:common::config_flow::data::username%]",
"password": "[%key:common::config_flow::data::password%]",
"region": "ConnectedDrive Region",
"refresh_token": "Refresh token (optional)"
"region": "ConnectedDrive Region"
}
}
},
Expand Down

0 comments on commit e97790c

Please sign in to comment.