async def test_race_condition(hass, monkeypatch): """Test race condition for unknown components.""" domain = "light" config = {"rflink": {"port": "/dev/ttyABC0"}, domain: {"platform": "rflink"}} tmp_entity = TMP_ENTITY.format("test3") # setup mocking rflink module event_callback, _, _, _ = await mock_rflink(hass, config, domain, monkeypatch) # test event for new unconfigured sensor event_callback({"id": "test3", "command": "off"}) event_callback({"id": "test3", "command": "on"}) # tmp_entity added to EVENT_KEY_COMMAND assert tmp_entity in hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_COMMAND]["test3"] # tmp_entity must no be added to EVENT_KEY_SENSOR assert tmp_entity not in hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_SENSOR]["test3"] await hass.async_block_till_done() # test state of new sensor new_sensor = hass.states.get(f"{domain}.test3") assert new_sensor assert new_sensor.state == "off" event_callback({"id": "test3", "command": "on"}) await hass.async_block_till_done() # tmp_entity must be deleted from EVENT_KEY_COMMAND assert tmp_entity not in hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_COMMAND]["test3"] # test state of new sensor new_sensor = hass.states.get(f"{domain}.test3") assert new_sensor assert new_sensor.state == "on"
async def async_added_to_hass(self): """Register update callback.""" # Remove temporary bogus entity_id if added tmp_entity = TMP_ENTITY.format(self._device_id) if tmp_entity in self.hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_SENSOR][ self._device_id]: self.hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_SENSOR][ self._device_id].remove(tmp_entity) # Register id and aliases self.hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_SENSOR][ self._device_id].append(self.entity_id) if self._aliases: for _id in self._aliases: self.hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_SENSOR][ _id].append(self.entity_id) async_dispatcher_connect(self.hass, SIGNAL_AVAILABILITY, self._availability_callback) async_dispatcher_connect(self.hass, SIGNAL_HANDLE_EVENT.format(self.entity_id), self.handle_event_callback) # Process the initial event now that the entity is created if self._initial_event: self.handle_event_callback(self._initial_event)
async def async_added_to_hass(self): """Register update callback.""" # Remove temporary bogus entity_id if added tmp_entity = TMP_ENTITY.format(self._device_id) if tmp_entity in self.hass.data[DATA_ENTITY_LOOKUP][ EVENT_KEY_SENSOR][self._device_id]: self.hass.data[DATA_ENTITY_LOOKUP][ EVENT_KEY_SENSOR][self._device_id].remove(tmp_entity) # Register id and aliases self.hass.data[DATA_ENTITY_LOOKUP][ EVENT_KEY_SENSOR][self._device_id].append(self.entity_id) if self._aliases: for _id in self._aliases: self.hass.data[DATA_ENTITY_LOOKUP][ EVENT_KEY_SENSOR][_id].append(self.entity_id) async_dispatcher_connect(self.hass, SIGNAL_AVAILABILITY, self._availability_callback) async_dispatcher_connect(self.hass, SIGNAL_HANDLE_EVENT.format(self.entity_id), self.handle_event_callback) # Process the initial event now that the entity is created if self._initial_event: self.handle_event_callback(self._initial_event)
async def test_race_condition(hass, monkeypatch): """Test race condition for unknown components.""" domain = 'light' config = { 'rflink': { 'port': '/dev/ttyABC0', }, domain: { 'platform': 'rflink', }, } tmp_entity = TMP_ENTITY.format('test3') # setup mocking rflink module event_callback, _, _, _ = await mock_rflink(hass, config, domain, monkeypatch) # test event for new unconfigured sensor event_callback({ 'id': 'test3', 'command': 'off', }) event_callback({ 'id': 'test3', 'command': 'on', }) # tmp_entity added to EVENT_KEY_COMMAND assert tmp_entity in hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_COMMAND][ 'test3'] # tmp_entity must no be added to EVENT_KEY_SENSOR assert tmp_entity not in hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_SENSOR][ 'test3'] await hass.async_block_till_done() # test state of new sensor new_sensor = hass.states.get(domain + '.test3') assert new_sensor assert new_sensor.state == 'off' event_callback({ 'id': 'test3', 'command': 'on', }) await hass.async_block_till_done() # tmp_entity must be deleted from EVENT_KEY_COMMAND assert tmp_entity not in hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_COMMAND][ 'test3'] # test state of new sensor new_sensor = hass.states.get(domain + '.test3') assert new_sensor assert new_sensor.state == 'on'
async def test_race_condition(hass, monkeypatch): """Test race condition for unknown components.""" domain = 'light' config = { 'rflink': { 'port': '/dev/ttyABC0', }, domain: { 'platform': 'rflink', }, } tmp_entity = TMP_ENTITY.format('test3') # setup mocking rflink module event_callback, _, _, _ = await mock_rflink( hass, config, domain, monkeypatch) # test event for new unconfigured sensor event_callback({ 'id': 'test3', 'command': 'off', }) event_callback({ 'id': 'test3', 'command': 'on', }) # tmp_entity added to EVENT_KEY_COMMAND assert tmp_entity in hass.data[DATA_ENTITY_LOOKUP][ EVENT_KEY_COMMAND]['test3'] # tmp_entity must no be added to EVENT_KEY_SENSOR assert tmp_entity not in hass.data[DATA_ENTITY_LOOKUP][ EVENT_KEY_SENSOR]['test3'] await hass.async_block_till_done() # test state of new sensor new_sensor = hass.states.get(domain+'.test3') assert new_sensor assert new_sensor.state == 'off' event_callback({ 'id': 'test3', 'command': 'on', }) await hass.async_block_till_done() # tmp_entity must be deleted from EVENT_KEY_COMMAND assert tmp_entity not in hass.data[DATA_ENTITY_LOOKUP][ EVENT_KEY_COMMAND]['test3'] # test state of new sensor new_sensor = hass.states.get(domain+'.test3') assert new_sensor assert new_sensor.state == 'on'
async def test_race_condition(hass, monkeypatch): """Test race condition for unknown components.""" config = { "rflink": { "port": "/dev/ttyABC0" }, DOMAIN: { "platform": "rflink" } } tmp_entity = TMP_ENTITY.format("test3") # setup mocking rflink module event_callback, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch) # test event for new unconfigured sensor event_callback({ "id": "test3", "sensor": "battery", "value": "ok", "unit": "" }) event_callback({ "id": "test3", "sensor": "battery", "value": "ko", "unit": "" }) # tmp_entity added to EVENT_KEY_SENSOR assert tmp_entity in hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_SENSOR][ "test3"] # tmp_entity must no be added to EVENT_KEY_COMMAND assert tmp_entity not in hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_COMMAND][ "test3"] await hass.async_block_till_done() # test state of new sensor updated_sensor = hass.states.get("sensor.test3") assert updated_sensor # test state of new sensor new_sensor = hass.states.get(DOMAIN + ".test3") assert new_sensor assert new_sensor.state == "ok" event_callback({ "id": "test3", "sensor": "battery", "value": "ko", "unit": "" }) await hass.async_block_till_done() # tmp_entity must be deleted from EVENT_KEY_COMMAND assert tmp_entity not in hass.data[DATA_ENTITY_LOOKUP][EVENT_KEY_SENSOR][ "test3"] # test state of new sensor new_sensor = hass.states.get(DOMAIN + ".test3") assert new_sensor assert new_sensor.state == "ko"