async def test_one_pt2262(hass, rfxtrx): """Test with 1 sensor.""" entry_data = create_rfx_test_cfg( devices={ "0913000022670e013970": { "data_bits": 4, "command_on": 0xE, "command_off": 0x7, } }) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() await hass.async_start() state = hass.states.get("binary_sensor.pt2262_22670e") assert state assert state.state == "off" # probably aught to be unknown assert state.attributes.get("friendly_name") == "PT2262 22670e" await rfxtrx.signal("0913000022670e013970") state = hass.states.get("binary_sensor.pt2262_22670e") assert state.state == "on" await rfxtrx.signal("09130000226707013d70") state = hass.states.get("binary_sensor.pt2262_22670e") assert state.state == "off"
async def test_state_restore(opp, rfxtrx, state, brightness): """State restoration.""" entity_id = "light.ac_213c7f2_16" mock_restore_cache( opp, [State(entity_id, state, attributes={ATTR_BRIGHTNESS: brightness})]) entry_data = create_rfx_test_cfg( devices={"0b1100cd0213c7f210020f51": { "signal_repetitions": 1 }}) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_opp(opp) await opp.config_entries.async_setup(mock_entry.entry_id) await opp.async_block_till_done() assert opp.states.get(entity_id).state == state assert opp.states.get(entity_id).attributes.get( ATTR_BRIGHTNESS) == brightness
async def test_off_delay_restore(hass, rfxtrx): """Make sure binary sensor restore as off, if off delay is active.""" mock_restore_cache( hass, [ State( "binary_sensor.ac_118cdea_2", "on", attributes={ATTR_EVENT: EVENT_AC_118CDEA_2_ON}, ) ], ) entry_data = create_rfx_test_cfg( devices={EVENT_AC_118CDEA_2_ON: { "off_delay": 5 }}) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() await hass.async_start() state = hass.states.get("binary_sensor.ac_118cdea_2") assert state assert state.state == "off"
async def test_pt2262_unconfigured(hass, rfxtrx): """Test with discovery for PT2262.""" entry_data = create_rfx_test_cfg(devices={ "0913000022670e013970": {}, "09130000226707013970": {} }) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() await hass.async_start() state = hass.states.get("binary_sensor.pt2262_22670e") assert state assert state.state == "off" # probably aught to be unknown assert state.attributes.get("friendly_name") == "PT2262 22670e" state = hass.states.get("binary_sensor.pt2262_226707") assert state assert state.state == "off" # probably aught to be unknown assert state.attributes.get("friendly_name") == "PT2262 226707"
async def test_several(hass, rfxtrx): """Test with 3.""" entry_data = create_rfx_test_cfg( devices={ "0b1100cd0213c7f230010f71": {}, "0b1100100118cdea02010f70": {}, "0b1100101118cdea02010f70": {}, }) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() state = hass.states.get("binary_sensor.ac_213c7f2_48") assert state assert state.state == "off" assert state.attributes.get("friendly_name") == "AC 213c7f2:48" state = hass.states.get("binary_sensor.ac_118cdea_2") assert state assert state.state == "off" assert state.attributes.get("friendly_name") == "AC 118cdea:2" state = hass.states.get("binary_sensor.ac_1118cdea_2") assert state assert state.state == "off" assert state.attributes.get("friendly_name") == "AC 1118cdea:2"
async def test_duplicate_cover(hass, rfxtrx): """Test with 2 duplicate covers.""" entry_data = create_rfx_test_cfg( devices={ "0b1400cd0213c7f20d010f51": { "signal_repetitions": 1 }, "0b1400cd0213c7f20d010f50": { "signal_repetitions": 1 }, }) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() state = hass.states.get("cover.lightwaverf_siemens_0213c7_242") assert state assert state.state == "closed" assert state.attributes.get( "friendly_name") == "LightwaveRF, Siemens 0213c7:242"
async def test_several_covers(hass, rfxtrx): """Test with 3 covers.""" entry_data = create_rfx_test_cfg( devices={ "0b1400cd0213c7f20d010f51": {}, "0A1400ADF394AB010D0060": {}, "09190000009ba8010100": {}, }) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() state = hass.states.get("cover.lightwaverf_siemens_0213c7_242") assert state assert state.state == "closed" assert state.attributes.get( "friendly_name") == "LightwaveRF, Siemens 0213c7:242" state = hass.states.get("cover.lightwaverf_siemens_f394ab_1") assert state assert state.state == "closed" assert state.attributes.get( "friendly_name") == "LightwaveRF, Siemens f394ab:1" state = hass.states.get("cover.rollertrol_009ba8_1") assert state assert state.state == "closed" assert state.attributes.get("friendly_name") == "RollerTrol 009ba8:1"
async def test_pt2262_duplicate_id(hass, rfxtrx): """Test with 1 sensor.""" entry_data = create_rfx_test_cfg( devices={ "0913000022670e013970": { "data_bits": 4, "command_on": 0xE, "command_off": 0x7, }, "09130000226707013970": { "data_bits": 4, "command_on": 0xE, "command_off": 0x7, }, }) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() await hass.async_start() state = hass.states.get("binary_sensor.pt2262_22670e") assert state assert state.state == STATE_UNKNOWN assert state.attributes.get("friendly_name") == "PT2262 22670e"
async def test_one_switch(hass, rfxtrx): """Test with 1 switch.""" entry_data = create_rfx_test_cfg(devices={"0b1100cd0213c7f210010f51": {}}) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() state = hass.states.get("switch.ac_213c7f2_16") assert state assert state.state == STATE_UNKNOWN assert state.attributes.get("friendly_name") == "AC 213c7f2:16" await hass.services.async_call( "switch", "turn_on", {"entity_id": "switch.ac_213c7f2_16"}, blocking=True ) state = hass.states.get("switch.ac_213c7f2_16") assert state.state == "on" await hass.services.async_call( "switch", "turn_off", {"entity_id": "switch.ac_213c7f2_16"}, blocking=True ) state = hass.states.get("switch.ac_213c7f2_16") assert state.state == "off" assert rfxtrx.transport.send.mock_calls == [ call(bytearray(b"\x0b\x11\x00\x00\x02\x13\xc7\xf2\x10\x01\x00\x00")), call(bytearray(b"\x0b\x11\x00\x00\x02\x13\xc7\xf2\x10\x00\x00\x00")), ]
async def test_rssi_sensor(hass, rfxtrx): """Test with 1 sensor.""" entry_data = create_rfx_test_cfg( devices={ "0913000022670e013b70": { "data_bits": 4, "command_on": 0xE, "command_off": 0x7, }, "0b1100cd0213c7f230010f71": {}, } ) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() await hass.async_start() state = hass.states.get("sensor.pt2262_22670e_rssi_numeric") assert state assert state.state == "unknown" assert state.attributes.get("friendly_name") == "PT2262 22670e Rssi numeric" assert ( state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == SIGNAL_STRENGTH_DECIBELS_MILLIWATT ) state = hass.states.get("sensor.ac_213c7f2_48_rssi_numeric") assert state assert state.state == "unknown" assert state.attributes.get("friendly_name") == "AC 213c7f2:48 Rssi numeric" assert ( state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == SIGNAL_STRENGTH_DECIBELS_MILLIWATT ) await rfxtrx.signal("0913000022670e013b70") await rfxtrx.signal("0b1100cd0213c7f230010f71") state = hass.states.get("sensor.pt2262_22670e_rssi_numeric") assert state assert state.state == "-64" state = hass.states.get("sensor.ac_213c7f2_48_rssi_numeric") assert state assert state.state == "-64" await rfxtrx.signal("0913000022670e013b60") await rfxtrx.signal("0b1100cd0213c7f230010f61") state = hass.states.get("sensor.pt2262_22670e_rssi_numeric") assert state assert state.state == "-72" state = hass.states.get("sensor.ac_213c7f2_48_rssi_numeric") assert state assert state.state == "-72"
async def test_switch_events(hass, rfxtrx): """Event test with 2 switches.""" entry_data = create_rfx_test_cfg( devices={ "0b1100cd0213c7f205010f51": { "signal_repetitions": 1 }, "0b1100cd0213c7f210010f51": { "signal_repetitions": 1 }, }) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() state = hass.states.get("switch.ac_213c7f2_16") assert state assert state.state == STATE_UNKNOWN assert state.attributes.get("friendly_name") == "AC 213c7f2:16" state = hass.states.get("switch.ac_213c7f2_5") assert state assert state.state == STATE_UNKNOWN assert state.attributes.get("friendly_name") == "AC 213c7f2:5" # "16: On" await rfxtrx.signal("0b1100100213c7f210010f70") assert hass.states.get("switch.ac_213c7f2_5").state == STATE_UNKNOWN assert hass.states.get("switch.ac_213c7f2_16").state == "on" # "16: Off" await rfxtrx.signal("0b1100100213c7f210000f70") assert hass.states.get("switch.ac_213c7f2_5").state == STATE_UNKNOWN assert hass.states.get("switch.ac_213c7f2_16").state == "off" # "5: On" await rfxtrx.signal("0b1100100213c7f205010f70") assert hass.states.get("switch.ac_213c7f2_5").state == "on" assert hass.states.get("switch.ac_213c7f2_16").state == "off" # "5: Off" await rfxtrx.signal("0b1100100213c7f205000f70") assert hass.states.get("switch.ac_213c7f2_5").state == "off" assert hass.states.get("switch.ac_213c7f2_16").state == "off" # "16: Group on" await rfxtrx.signal("0b1100100213c7f210040f70") assert hass.states.get("switch.ac_213c7f2_5").state == "on" assert hass.states.get("switch.ac_213c7f2_16").state == "on" # "16: Group off" await rfxtrx.signal("0b1100100213c7f210030f70") assert hass.states.get("switch.ac_213c7f2_5").state == "off" assert hass.states.get("switch.ac_213c7f2_16").state == "off"
async def setup_entry(hass, devices): """Construct a config setup.""" entry_data = create_rfx_test_cfg(devices=devices) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() await hass.async_start()
async def test_default_config(hass, rfxtrx): """Test with 0 sensor.""" entry_data = create_rfx_test_cfg(devices={}) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() assert len(hass.states.async_all()) == 0
async def test_several_lights(opp, rfxtrx): """Test with 3 lights.""" entry_data = create_rfx_test_cfg( devices={ "0b1100cd0213c7f230020f71": { "signal_repetitions": 1 }, "0b1100100118cdea02020f70": { "signal_repetitions": 1 }, "0b1100101118cdea02050f70": { "signal_repetitions": 1 }, }) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_opp(opp) await opp.config_entries.async_setup(mock_entry.entry_id) await opp.async_block_till_done() await opp.async_start() state = opp.states.get("light.ac_213c7f2_48") assert state assert state.state == "off" assert state.attributes.get("friendly_name") == "AC 213c7f2:48" state = opp.states.get("light.ac_118cdea_2") assert state assert state.state == "off" assert state.attributes.get("friendly_name") == "AC 118cdea:2" state = opp.states.get("light.ac_1118cdea_2") assert state assert state.state == "off" assert state.attributes.get("friendly_name") == "AC 1118cdea:2" await rfxtrx.signal("0b1100cd0213c7f230010f71") state = opp.states.get("light.ac_213c7f2_48") assert state assert state.state == "on" await rfxtrx.signal("0b1100cd0213c7f230000f71") state = opp.states.get("light.ac_213c7f2_48") assert state assert state.state == "off" await rfxtrx.signal("0b1100cd0213c7f230020f71") state = opp.states.get("light.ac_213c7f2_48") assert state assert state.state == "on" assert state.attributes.get("brightness") == 255
async def test_connect_with_protocols(hass): """Test that we attempt to set protocols.""" entry_data = create_rfx_test_cfg(device="/dev/ttyUSBfake", protocols=SOME_PROTOCOLS) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) with patch.object(rfxtrxmod, "Connect") as connect: await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() connect.assert_called_once_with("/dev/ttyUSBfake", ANY, modes=SOME_PROTOCOLS)
async def test_off_delay(hass, rfxtrx, timestep): """Test with discovery.""" entry_data = create_rfx_test_cfg( devices={"0b1100100118cdea02010f70": { "off_delay": 5 }}) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() await hass.async_start() state = hass.states.get("binary_sensor.ac_118cdea_2") assert state assert state.state == "off" await rfxtrx.signal("0b1100100118cdea02010f70") state = hass.states.get("binary_sensor.ac_118cdea_2") assert state assert state.state == "on" await timestep(4) state = hass.states.get("binary_sensor.ac_118cdea_2") assert state assert state.state == "on" await timestep(4) state = hass.states.get("binary_sensor.ac_118cdea_2") assert state assert state.state == "off" await rfxtrx.signal("0b1100100118cdea02010f70") state = hass.states.get("binary_sensor.ac_118cdea_2") assert state assert state.state == "on" await timestep(3) await rfxtrx.signal("0b1100100118cdea02010f70") await timestep(4) state = hass.states.get("binary_sensor.ac_118cdea_2") assert state assert state.state == "on" await timestep(4) state = hass.states.get("binary_sensor.ac_118cdea_2") assert state assert state.state == "off"
async def test_one(hass, rfxtrx): """Test with 1 sensor.""" entry_data = create_rfx_test_cfg(devices={"0b1100cd0213c7f230010f71": {}}) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() state = hass.states.get("binary_sensor.ac_213c7f2_48") assert state assert state.state == STATE_UNKNOWN assert state.attributes.get("friendly_name") == "AC 213c7f2:48"
async def test_unknown_event_code(opp, rfxtrx): """Test with 3 switches.""" entry_data = create_rfx_test_cfg(devices={"1234567890": {"signal_repetitions": 1}}) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_opp(opp) await opp.config_entries.async_setup(mock_entry.entry_id) await opp.async_block_till_done() conf_entries = opp.config_entries.async_entries(DOMAIN) assert len(conf_entries) == 1 entry = conf_entries[0] assert entry.state == config_entries.ConfigEntryState.LOADED
async def test_update_of_sensors(hass, rfxtrx): """Test with 3 sensors.""" entry_data = create_rfx_test_cfg(devices={ "0a52080705020095220269": {}, "0a520802060100ff0e0269": {}, }) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() await hass.async_start() state = hass.states.get( "sensor.wt260_wt260h_wt440h_wt450_wt450h_05_02_temperature") assert state assert state.state == "unknown" state = hass.states.get( "sensor.wt260_wt260h_wt440h_wt450_wt450h_06_01_temperature") assert state assert state.state == "unknown" state = hass.states.get( "sensor.wt260_wt260h_wt440h_wt450_wt450h_06_01_humidity") assert state assert state.state == "unknown" await rfxtrx.signal("0a520802060101ff0f0269") await rfxtrx.signal("0a52080705020085220269") state = hass.states.get( "sensor.wt260_wt260h_wt440h_wt450_wt450h_05_02_temperature") assert state assert state.state == "13.3" state = hass.states.get( "sensor.wt260_wt260h_wt440h_wt450_wt450h_06_01_temperature") assert state assert state.state == "51.1" state = hass.states.get( "sensor.wt260_wt260h_wt440h_wt450_wt450h_06_01_humidity") assert state assert state.state == "15"
async def test_state_restore(hass, rfxtrx, state, event): """State restoration.""" entity_id = "sensor.wt260_wt260h_wt440h_wt450_wt450h_07_01_temperature" mock_restore_cache(hass, [State(entity_id, state, attributes={ATTR_EVENT: event})]) entry_data = create_rfx_test_cfg(devices={"0a520801070100b81b0279": {}}) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() assert hass.states.get(entity_id).state == state
async def test_state_restore(hass, rfxtrx, state): """State restoration.""" entity_id = "switch.ac_213c7f2_16" mock_restore_cache(hass, [State(entity_id, state)]) entry_data = create_rfx_test_cfg(devices={"0b1100cd0213c7f210010f51": {}}) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() assert hass.states.get(entity_id).state == state
async def test_state_restore(hass, rfxtrx, state, event): """State restoration.""" entity_id = "binary_sensor.ac_213c7f2_48" mock_restore_cache(hass, [State(entity_id, state, attributes={ATTR_EVENT: event})]) entry_data = create_rfx_test_cfg(devices={"0b1100cd0213c7f230010f71": {}}) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() assert hass.states.get(entity_id).state == state
async def test_one_sensor_no_datatype(hass, rfxtrx): """Test with 1 sensor.""" entry_data = create_rfx_test_cfg(devices={"0a52080705020095220269": {}}) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() base_id = "sensor.wt260_wt260h_wt440h_wt450_wt450h_05_02" base_name = "WT260,WT260H,WT440H,WT450,WT450H 05:02" state = hass.states.get(f"{base_id}_temperature") assert state assert state.state == "unknown" assert state.attributes.get("friendly_name") == f"{base_name} Temperature" assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS state = hass.states.get(f"{base_id}_humidity") assert state assert state.state == "unknown" assert state.attributes.get("friendly_name") == f"{base_name} Humidity" assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE state = hass.states.get(f"{base_id}_humidity_status") assert state assert state.state == "unknown" assert state.attributes.get( "friendly_name") == f"{base_name} Humidity status" assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) is None state = hass.states.get(f"{base_id}_signal_strength") assert state assert state.state == "unknown" assert state.attributes.get( "friendly_name") == f"{base_name} Signal strength" assert (state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == SIGNAL_STRENGTH_DECIBELS_MILLIWATT) state = hass.states.get(f"{base_id}_battery") assert state assert state.state == "unknown" assert state.attributes.get("friendly_name") == f"{base_name} Battery" assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == PERCENTAGE
async def test_send(hass, rfxtrx): """Test configuration.""" entry_data = create_rfx_test_cfg(device="/dev/null", devices={}) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() await hass.services.async_call( "rfxtrx", "send", {"event": "0a520802060101ff0f0269"}, blocking=True ) assert rfxtrx.transport.send.mock_calls == [ call(bytearray(b"\x0a\x52\x08\x02\x06\x01\x01\xff\x0f\x02\x69")) ]
async def test_repetitions(hass, rfxtrx, repetitions): """Test signal repetitions.""" entry_data = create_rfx_test_cfg( devices={"0b1100cd0213c7f230020f71": {"signal_repetitions": repetitions}} ) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() await hass.services.async_call( "light", "turn_on", {"entity_id": "light.ac_213c7f2_48"}, blocking=True ) await hass.async_block_till_done() assert rfxtrx.transport.send.call_count == repetitions
async def test_one_sensor(hass, rfxtrx): """Test with 1 sensor.""" entry_data = create_rfx_test_cfg(devices={"0a52080705020095220269": {}}) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() state = hass.states.get("sensor.wt260_wt260h_wt440h_wt450_wt450h_05_02_temperature") assert state assert state.state == "unknown" assert ( state.attributes.get("friendly_name") == "WT260,WT260H,WT440H,WT450,WT450H 05:02 Temperature" ) assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == TEMP_CELSIUS
async def test_one_pt2262_switch(hass, rfxtrx): """Test with 1 PT2262 switch.""" entry_data = create_rfx_test_cfg( devices={ "0913000022670e013970": { "data_bits": 4, "command_on": 0xE, "command_off": 0x7, } }) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() state = hass.states.get("switch.pt2262_22670e") assert state assert state.state == STATE_UNKNOWN assert state.attributes.get("friendly_name") == "PT2262 22670e" await hass.services.async_call("switch", "turn_on", {"entity_id": "switch.pt2262_22670e"}, blocking=True) state = hass.states.get("switch.pt2262_22670e") assert state.state == "on" await hass.services.async_call("switch", "turn_off", {"entity_id": "switch.pt2262_22670e"}, blocking=True) state = hass.states.get("switch.pt2262_22670e") assert state.state == "off" assert rfxtrx.transport.send.mock_calls == [ call(bytearray(b"\x09\x13\x00\x00\x22\x67\x0e\x01\x39\x00")), call(bytearray(b"\x09\x13\x00\x00\x22\x67\x0f\x01\x39\x00")), ]
async def test_one_cover(opp, rfxtrx): """Test with 1 cover.""" entry_data = create_rfx_test_cfg( devices={"0b1400cd0213c7f20d010f51": { "signal_repetitions": 1 }}) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_opp(opp) await opp.config_entries.async_setup(mock_entry.entry_id) await opp.async_block_till_done() state = opp.states.get("cover.lightwaverf_siemens_0213c7_242") assert state await opp.services.async_call( "cover", "open_cover", {"entity_id": "cover.lightwaverf_siemens_0213c7_242"}, blocking=True, ) await opp.services.async_call( "cover", "close_cover", {"entity_id": "cover.lightwaverf_siemens_0213c7_242"}, blocking=True, ) await opp.services.async_call( "cover", "stop_cover", {"entity_id": "cover.lightwaverf_siemens_0213c7_242"}, blocking=True, ) assert rfxtrx.transport.send.mock_calls == [ call(bytearray(b"\n\x14\x00\x00\x02\x13\xc7\xf2\x0f\x00\x00")), call(bytearray(b"\n\x14\x00\x00\x02\x13\xc7\xf2\r\x00\x00")), call(bytearray(b"\n\x14\x00\x00\x02\x13\xc7\xf2\x0e\x00\x00")), ]
async def test_state_restore(opp, rfxtrx, state): """State restoration.""" entity_id = "cover.lightwaverf_siemens_0213c7_242" mock_restore_cache(opp, [State(entity_id, state)]) entry_data = create_rfx_test_cfg( devices={"0b1400cd0213c7f20d010f51": { "signal_repetitions": 1 }}) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_opp(opp) await opp.config_entries.async_setup(mock_entry.entry_id) await opp.async_block_till_done() assert opp.states.get(entity_id).state == state
async def test_pt2262_switch_events(hass, rfxtrx): """Test with 1 PT2262 switch.""" entry_data = create_rfx_test_cfg( devices={ "0913000022670e013970": { "signal_repetitions": 1, "data_bits": 4, "command_on": 0xE, "command_off": 0x7, } } ) mock_entry = MockConfigEntry(domain="rfxtrx", unique_id=DOMAIN, data=entry_data) mock_entry.add_to_hass(hass) await hass.config_entries.async_setup(mock_entry.entry_id) await hass.async_block_till_done() state = hass.states.get("switch.pt2262_22670e") assert state assert state.state == STATE_UNKNOWN assert state.attributes.get("friendly_name") == "PT2262 22670e" # "Command: 0xE" await rfxtrx.signal("0913000022670e013970") assert hass.states.get("switch.pt2262_22670e").state == "on" # "Command: 0x0" await rfxtrx.signal("09130000226700013970") assert hass.states.get("switch.pt2262_22670e").state == "on" # "Command: 0x7" await rfxtrx.signal("09130000226707013d70") assert hass.states.get("switch.pt2262_22670e").state == "off" # "Command: 0x1" await rfxtrx.signal("09130000226701013d70") assert hass.states.get("switch.pt2262_22670e").state == "off"