def test_mqtt_load_persistence(self):
    'Test load persistence file for MQTTGateway.'
    sensor = self._add_sensor(1)
    sensor.children[1] = ChildSensor(1, self.gateway.const.Presentation.S_HUM)
    sensor.children[1].values[self.gateway.const.SetReq.V_HUM] = '20'
    with tempfile.TemporaryDirectory() as temp_dir:
        self.gateway.persistence_file = os.path.join(temp_dir, 'file.json')
        self.gateway._save_sensors()
        del self.gateway.sensors[1]
        self.assertNotIn(1, self.gateway.sensors)
        self.gateway._safe_load_sensors()
    self.assertEqual(self.gateway.sensors[1].children[1].id, sensor.children[1].id)
    self.assertEqual(self.gateway.sensors[1].children[1].type, sensor.children[1].type)
    self.assertEqual(self.gateway.sensors[1].children[1].values, sensor.children[1].values)
    calls = [mock.call('/1/1/1/+/+', self.gateway.recv, 0), mock.call('/1/1/2/+/+', self.gateway.recv, 0), mock.call('/1/+/4/+/+', self.gateway.recv, 0)]
    self.mock_sub.assert_has_calls(calls)
Test load persistence file for MQTTGateway.
def test_mqtt_load_persistence(self):
    
    sensor = self._add_sensor(1)
    sensor.children[1] = ChildSensor(1, self.gateway.const.Presentation.S_HUM)
    sensor.children[1].values[self.gateway.const.SetReq.V_HUM] = '20'
    with tempfile.TemporaryDirectory() as temp_dir:
        self.gateway.persistence_file = os.path.join(temp_dir, 'file.json')
        self.gateway._save_sensors()
        del self.gateway.sensors[1]
        self.assertNotIn(1, self.gateway.sensors)
        self.gateway._safe_load_sensors()
    self.assertEqual(self.gateway.sensors[1].children[1].id, sensor.children[1].id)
    self.assertEqual(self.gateway.sensors[1].children[1].type, sensor.children[1].type)
    self.assertEqual(self.gateway.sensors[1].children[1].values, sensor.children[1].values)
    calls = [mock.call('/1/1/1/+/+', self.gateway.recv, 0), mock.call('/1/1/2/+/+', self.gateway.recv, 0), mock.call('/1/+/4/+/+', self.gateway.recv, 0)]
    self.mock_sub.assert_has_calls(calls)