diff --git a/custom_components/bouncie/__init__.py b/custom_components/bouncie/__init__.py index 8341d06..0632b29 100644 --- a/custom_components/bouncie/__init__.py +++ b/custom_components/bouncie/__init__.py @@ -51,8 +51,8 @@ def patch_missing_data(vehicle_info): "milOn": "Not available", "lastUpdated": "Not available", } - elif "battery" not in vehicle_info["stats"]["mil"]: - vehicle_info["stats"]["mil"]["battery"] = { + elif "battery" not in vehicle_info["stats"]: + vehicle_info["stats"]["battery"] = { "status": "Not available", "lastUpdated": "Not available", } diff --git a/custom_components/bouncie/sensor.py b/custom_components/bouncie/sensor.py index 8a1afaf..0b41d83 100644 --- a/custom_components/bouncie/sensor.py +++ b/custom_components/bouncie/sensor.py @@ -117,19 +117,17 @@ def update_car_info_attributes(vehicle_info): value_fn=lambda vehicle_info: vehicle_info["stats"]["mil"]["milOn"], extra_attrs_fn=lambda vehicle_info: { const.ATTR_VEHICLE_MIL_LAST_UPDATED_KEY: vehicle_info["stats"]["mil"][ - "lastUpdated" - ] + "lastUpdated"] }, ), BouncieSensorEntityDescription( key="car-battery", icon="mdi:car-battery", name="Car Battery", - value_fn=lambda vehicle_info: vehicle_info["stats"]["mil"]["battery"]["status"], + value_fn=lambda vehicle_info: vehicle_info["stats"]["battery"]["status"], extra_attrs_fn=lambda vehicle_info: { - const.ATTR_VEHICLE_BATTERY_LAST_UPDATED_KEY: vehicle_info["stats"]["mil"][ - "battery" - ]["lastUpdated"] + const.ATTR_VEHICLE_BATTERY_LAST_UPDATED_KEY: vehicle_info["stats"][ + "battery"]["lastUpdated"] }, ), ) diff --git a/tests/const.py b/tests/const.py index 0fd9905..d8e0519 100644 --- a/tests/const.py +++ b/tests/const.py @@ -68,10 +68,10 @@ "mil": { "milOn": False, "lastUpdated": "2022-11-23T01:38:55.000Z", - "battery": { - "status": "normal", - "lastUpdated": "2022-11-23T01:37:41.000Z", - }, + }, + "battery": { + "status": "normal", + "lastUpdated": "2022-11-23T01:37:41.000Z", }, }, }, @@ -93,10 +93,10 @@ "mil": { "milOn": False, "lastUpdated": "2020-01-01 12:00:00:000Z", - "battery": { - "status": "normal", - "lastUpdated": "2020-04-25 12:00:00:000Z", - }, + }, + "battery": { + "status": "normal", + "lastUpdated": "2020-04-25 12:00:00:000Z", }, }, } diff --git a/tests/test_sensor.py b/tests/test_sensor.py index ca37649..7a937fb 100644 --- a/tests/test_sensor.py +++ b/tests/test_sensor.py @@ -102,7 +102,7 @@ async def test_car_battery_sensor( state = hass.states.get("sensor.my_prius_car_battery") assert ( state.state - == const.MOCK_VEHICLES_RESPONSE[0]["stats"]["mil"]["battery"]["status"] + == const.MOCK_VEHICLES_RESPONSE[0]["stats"]["battery"]["status"] ) @@ -131,7 +131,7 @@ async def test_battery_info_missing( ) -> None: """Test battery info missing from bouncie server.""" updated_response = list(const.MOCK_VEHICLES_RESPONSE) - del updated_response[0]["stats"]["mil"]["battery"] + del updated_response[0]["stats"]["battery"] await setup_platform(hass, SENSOR_DOMAIN, updated_response) entity_registry = er.async_get(hass) entry = entity_registry.async_get("sensor.my_prius_car_battery")