Skip to content

Commit

Permalink
Fix error in 2024.04 when charging polling option is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Two committed Apr 16, 2024
1 parent 93038c4 commit f4bcf06
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.11", "3.12"]
python-version: ["3.12"]
steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
Expand Down
27 changes: 8 additions & 19 deletions custom_components/subaru/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
from subarulink import Controller as SubaruAPI, InvalidCredentials, SubaruException
from subarulink.const import COUNTRY_USA

from homeassistant.components.binary_sensor import (
DOMAIN as BINARY_SENSOR_DOMAIN,
BinarySensorDeviceClass,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_DEVICE_ID,
Expand Down Expand Up @@ -154,7 +150,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

async def _refresh_subaru_data(
hass: HomeAssistant,
config_entry: ConfigEntry,
entry: ConfigEntry,
vehicle_info: dict,
controller: SubaruAPI,
) -> dict:
Expand All @@ -171,22 +167,15 @@ async def _refresh_subaru_data(

# Poll vehicle, if option is enabled
polling_option = PollingOptions.get_by_value(
config_entry.options.get(CONF_POLLING_OPTION, PollingOptions.DISABLE.value)
entry.options.get(CONF_POLLING_OPTION, PollingOptions.DISABLE.value)
)
if polling_option == PollingOptions.CHARGING:
# Is there a better way to check if the subaru is charging?
e_registry = er.async_get(hass)
battery_charging = e_registry.async_get_device_class_lookup(
{(Platform.BINARY_SENSOR, BinarySensorDeviceClass.BATTERY_CHARGING)}
)
for item in battery_charging.values():
entity_id = item[
(BINARY_SENSOR_DOMAIN, BinarySensorDeviceClass.BATTERY_CHARGING)
]
entity = e_registry.async_get(entity_id)
state = hass.states.get(entity_id)
if entity and state:
if entity.platform == DOMAIN and state.state == STATE_ON:
entity_registry = er.async_get(hass)
if entity_id := entity_registry.async_get_entity_id(
Platform.BINARY_SENSOR, DOMAIN, f"{vin.upper()}_EV_CHARGER_STATE_TYPE"
):
if state := hass.states.get(entity_id):
if state.state == STATE_ON:
await poll_subaru(
vehicle,
controller,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/subaru/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/G-Two/homeassistant-subaru/issues",
"requirements": ["subarulink==0.7.11"],
"version": "0.7.13"
"version": "0.7.14"
}

0 comments on commit f4bcf06

Please sign in to comment.