Skip to content

Commit

Permalink
More test cases and round up of speed to int
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarons committed Jan 13, 2023
1 parent ff29315 commit e1a657b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
5 changes: 2 additions & 3 deletions custom_components/bouncie/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def update_car_info_attributes(vehicle_info):
key="car-odometer",
icon="mdi:counter",
name="Car Odometer",
device_class=SensorDeviceClass.DISTANCE,
native_unit_of_measurement="mi",
state_class=SensorStateClass.TOTAL_INCREASING,
value_fn=lambda vehicle_info: int(vehicle_info["stats"]["odometer"]),
Expand All @@ -94,9 +93,9 @@ def update_car_info_attributes(vehicle_info):
key="car-speed",
icon="mdi:speedometer",
name="Car Speed",
state_class=SensorStateClass.MEASUREMENT,
device_class=SensorDeviceClass.SPEED,
native_unit_of_measurement="mph",
value_fn=lambda vehicle_info: vehicle_info["stats"]["speed"],
value_fn=lambda vehicle_info: int(vehicle_info["stats"]["speed"]),
extra_attrs_fn=update_car_stats_attributes,
),
BouncieSensorEntityDescription(
Expand Down
2 changes: 1 addition & 1 deletion tests/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
},
"fuelLevel": 29.411764705882355,
"isRunning": False,
"speed": 0,
"speed": 123.2446465,
"mil": {"milOn": False, "lastUpdated": "2022-11-23T01:38:55.000Z"},
"battery": {"status": "normal", "lastUpdated": "2022-11-23T01:37:41.000Z"},
},
Expand Down
62 changes: 62 additions & 0 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,68 @@ async def test_car_info_sensor(hass: HomeAssistant) -> None:
assert state.attributes["imei"] == const.MOCK_VEHICLES_RESPONSE[0]["imei"]


async def test_car_odometer_sensor(hass: HomeAssistant) -> None:
"""Test getting all vehicles."""
await setup_platform(hass, SENSOR_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("sensor.my_prius_car_odometer")
assert entry is not None
state = hass.states.get("sensor.my_prius_car_odometer")
assert state.state == "120508"


async def test_car_address_sensor(hass: HomeAssistant) -> None:
"""Test getting all vehicles."""
await setup_platform(hass, SENSOR_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("sensor.my_prius_car_address")
assert entry is not None
state = hass.states.get("sensor.my_prius_car_address")
assert (
state.state == const.MOCK_VEHICLES_RESPONSE[0]["stats"]["location"]["address"]
)


async def test_car_fuel_sensor(hass: HomeAssistant) -> None:
"""Test getting all vehicles."""
await setup_platform(hass, SENSOR_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("sensor.my_prius_car_fuel")
assert entry is not None
state = hass.states.get("sensor.my_prius_car_fuel")
assert state.state == "29"


async def test_car_speed_sensor(hass: HomeAssistant) -> None:
"""Test getting all vehicles."""
await setup_platform(hass, SENSOR_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("sensor.my_prius_car_speed")
assert entry is not None
state = hass.states.get("sensor.my_prius_car_speed")
assert state.state == str(int(const.MOCK_VEHICLES_RESPONSE[0]["stats"]["speed"]))


async def test_car_mil_sensor(hass: HomeAssistant) -> None:
"""Test getting all vehicles."""
await setup_platform(hass, SENSOR_DOMAIN)
entity_registry = er.async_get(hass)
entry = entity_registry.async_get("sensor.my_prius_car_mil")
assert entry is not None
state = hass.states.get("sensor.my_prius_car_mil")
assert state.state == str(const.MOCK_VEHICLES_RESPONSE[0]["stats"]["mil"]["milOn"])


async def test_car_battery_sensor(hass: HomeAssistant) -> None:
"""Test getting all vehicles."""
await setup_platform(hass, SENSOR_DOMAIN)
entity_registry = er.async_get(hass)
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"]


async def test_sensor_update(hass: HomeAssistant) -> None:
"""Test sensor auto-update."""
_, mock_controller = await setup_platform(hass, SENSOR_DOMAIN)
Expand Down

0 comments on commit e1a657b

Please sign in to comment.