@@ -580,31 +580,55 @@ async def test_rpc_polling_sensor(
580580async def test_rpc_sleeping_sensor (
581581 hass : HomeAssistant ,
582582 mock_rpc_device : Mock ,
583- device_registry : DeviceRegistry ,
584583 monkeypatch : pytest .MonkeyPatch ,
585584) -> None :
586585 """Test RPC online sleeping sensor."""
587586 entity_id = f"{ SENSOR_DOMAIN } .test_name_temperature"
588587 monkeypatch .setattr (mock_rpc_device , "connected" , False )
589588 monkeypatch .setitem (mock_rpc_device .status ["sys" ], "wakeup_period" , 1000 )
590- entry = await init_integration (hass , 2 , sleep_period = 1000 )
589+ await init_integration (hass , 2 , sleep_period = 1000 )
591590
592591 # Sensor should be created when device is online
593592 assert hass .states .get (entity_id ) is None
594593
595- register_entity (
596- hass ,
597- SENSOR_DOMAIN ,
598- "test_name_temperature" ,
599- "temperature:0-temperature_0" ,
600- entry ,
594+ # Make device online
595+ mock_rpc_device .mock_online ()
596+ await hass .async_block_till_done (wait_background_tasks = True )
597+
598+ assert (state := hass .states .get (entity_id ))
599+ assert state .state == "22.9"
600+
601+ mutate_rpc_device_status (monkeypatch , mock_rpc_device , "temperature:0" , "tC" , 23.4 )
602+ mock_rpc_device .mock_update ()
603+
604+ assert (state := hass .states .get (entity_id ))
605+ assert state .state == "23.4"
606+
607+
608+ async def test_rpc_sleeping_sensor_with_channel_name (
609+ hass : HomeAssistant ,
610+ mock_rpc_device : Mock ,
611+ monkeypatch : pytest .MonkeyPatch ,
612+ ) -> None :
613+ """Test RPC online sleeping sensor with channel name."""
614+ name = "test channel name"
615+ entity_id = f"{ SENSOR_DOMAIN } .test_name_test_channel_name_temperature"
616+ monkeypatch .setitem (
617+ mock_rpc_device .config , "temperature:0" , {"id" : 0 , "name" : name }
601618 )
619+ monkeypatch .setattr (mock_rpc_device , "connected" , False )
620+ monkeypatch .setitem (mock_rpc_device .status ["sys" ], "wakeup_period" , 1000 )
621+ await init_integration (hass , 2 , sleep_period = 1000 )
622+
623+ # Sensor should be created when device is online
624+ assert hass .states .get (entity_id ) is None
602625
603626 # Make device online
604627 mock_rpc_device .mock_online ()
605628 await hass .async_block_till_done (wait_background_tasks = True )
606629
607630 assert (state := hass .states .get (entity_id ))
631+ assert state .attributes ["friendly_name" ] == f"Test name { name } temperature"
608632 assert state .state == "22.9"
609633
610634 mutate_rpc_device_status (monkeypatch , mock_rpc_device , "temperature:0" , "tC" , 23.4 )
0 commit comments