@@ -323,6 +323,27 @@ async def test_sensor_without_unit_does_not_crash(
323323 assert state .attributes .get ("unit_of_measurement" ) is None
324324
325325
326+ async def test_sensor_uses_registry_unit (
327+ hass : HomeAssistant ,
328+ init_integration ,
329+ ) -> None :
330+ """Test sensor unit is available when the entity is registered."""
331+ victron_hub , mock_config_entry = init_integration
332+
333+ await inject_message (victron_hub , "N/123/battery/0/Dc/0/Current" , '{"value": 10.5}' )
334+ await finalize_injection (victron_hub )
335+ await hass .async_block_till_done ()
336+
337+ entity_registry = er .async_get (hass )
338+ entities = er .async_entries_for_config_entry (
339+ entity_registry , mock_config_entry .entry_id
340+ )
341+ assert len (entities ) > 0
342+
343+ entity = next (entry for entry in entities if entry .translation_key == "battery_current" )
344+ assert entity .unit_of_measurement == "A"
345+
346+
326347async def test_monetary_sensor_uses_ha_currency (
327348 hass : HomeAssistant ,
328349 init_integration ,
@@ -340,6 +361,7 @@ async def test_monetary_sensor_uses_ha_currency(
340361 entity_registry , mock_config_entry .entry_id
341362 )
342363 assert len (entities ) == 1
364+ assert entities [0 ].unit_of_measurement == "EUR"
343365
344366 state = hass .states .get (entities [0 ].entity_id )
345367 assert state is not None
@@ -1091,4 +1113,3 @@ async def test_number_with_step(
10911113 assert state is not None
10921114 assert float (state .state ) == 57.6
10931115 assert state .attributes .get ("step" ) == 0.1
1094-
0 commit comments