Skip to content

Commit

Permalink
Fixed test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarons committed Nov 6, 2024
1 parent 3cfa572 commit 55e6051
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
10 changes: 5 additions & 5 deletions custom_components/bouncie/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:

def patch_missing_data(vehicle_info):
"""Fill in missing data."""
if "battery" not in vehicle_info["stats"]:
vehicle_info["stats"]["battery"] = {
"status": "Not available",
"lastUpdated": "Not available",
}
if "mil" not in vehicle_info["stats"]:
vehicle_info["stats"]["mil"] = {
"milOn": "Not available",
"lastUpdated": "Not available",
}
elif "battery" not in vehicle_info["stats"]["mil"]:
vehicle_info["stats"]["mil"]["battery"] = {
"status": "Not available",
"lastUpdated": "Not available",
}
if "location" not in vehicle_info["stats"]:
vehicle_info["stats"]["location"] = {
"address": "Not available",
Expand Down
20 changes: 16 additions & 4 deletions tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,14 @@
"fuelLevel": 29.411764705882355,
"isRunning": False,
"speed": 123.2446465,
"mil": {"milOn": False, "lastUpdated": "2022-11-23T01:38:55.000Z"},
"battery": {"status": "normal", "lastUpdated": "2022-11-23T01:37:41.000Z"},
"mil": {
"milOn": False,
"lastUpdated": "2022-11-23T01:38:55.000Z",
"battery": {
"status": "normal",
"lastUpdated": "2022-11-23T01:37:41.000Z",
},
},
},
},
]
Expand All @@ -84,8 +90,14 @@
"fuelLevel": 27.3,
"isRunning": False,
"speed": 0,
"mil": {"milOn": False, "lastUpdated": "2020-01-01 12:00:00:000Z"},
"battery": {"status": "normal", "lastUpdated": "2020-04-25 12:00:00:000Z"},
"mil": {
"milOn": False,
"lastUpdated": "2020-01-01 12:00:00:000Z",
"battery": {
"status": "normal",
"lastUpdated": "2020-04-25 12:00:00:000Z",
},
},
},
}
]
7 changes: 5 additions & 2 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ async def test_car_battery_sensor(
entry = entity_registry.async_get("sensor.my_prius_car_battery")
assert entry is not None
state = hass.states.get("sensor.my_prius_car_battery")
assert state.state == const.MOCK_VEHICLES_RESPONSE[0]["stats"]["battery"]["status"]
assert (
state.state
== const.MOCK_VEHICLES_RESPONSE[0]["stats"]["mil"]["battery"]["status"]
)


async def test_sensor_update(
Expand Down Expand Up @@ -128,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"]["battery"]
del updated_response[0]["stats"]["mil"]["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")
Expand Down

0 comments on commit 55e6051

Please sign in to comment.