Exemplo n.º 1
0
	def test_prefix_slash(self):
		settings = {
			"client": self.mock,
			"prefix": "/testname/"
		}
		config.PERSISTENCE = [persistence.Redis(**settings)]
		persistence.set("lights/fan", "value")
		self.mock.set.assert_called_once_with("/testname/lights/fan", "value")
		self.mock.publish.assert_called_once_with("/testname/lights/fan", "value")
Exemplo n.º 2
0
	def test_retain_default_true(self):
		settings = {
			"_publish": self.mock,
		}
		config.PERSISTENCE = [persistence.MQTT(**settings)]
		persistence.set("lights/fan", "value")
		call_args = self.mock.single.call_args
		self.assertEqual(call_args[0][0], "lights/fan")
		self.assertEqual(call_args[1]['retain'], True)
Exemplo n.º 3
0
	def test_set_no_publish(self):
		settings = {
			"client": self.mock,
			"publish": False,
		}
		config.PERSISTENCE = [persistence.Redis(**settings)]
		persistence.set("lights/fan", "value")
		self.mock.set.assert_called_once_with("lights/fan", "value")
		self.mock.publish.assert_not_called()
Exemplo n.º 4
0
	def test_prefix_slash(self):
		settings = {
			"_publish": self.mock,
			"prefix": "/testname/"
		}
		config.PERSISTENCE = [persistence.MQTT(**settings)]
		persistence.set("lights/fan", "value")
		call_args = self.mock.single.call_args
		self.assertEqual(call_args[0][0], "/testname/lights/fan")
		self.assertEqual(call_args[1]['payload'], "value")
Exemplo n.º 5
0
	def test_set_custom_prefix(self):
		settings = {
			"_publish": self.mock,
			"discovery_prefix": "myhass",
		}
		config.PERSISTENCE = [persistence.MQTTHomeAssistant(**settings)]
		persistence.set("lights/fan", "value")
		call_args = self.mock.single.call_args
		self.assertEqual(call_args[0][0], "myhass/light/lights_fan/state")
		self.assertEqual(call_args[1]['payload'], "value")
Exemplo n.º 6
0
	def test_set_only_publish(self):
		settings = {
			"client": self.mock,
			"db": None,
		}
		config.PERSISTENCE = [persistence.Redis(**settings)]
		persistence.set("lights/fan", "value")
		self.assertEqual(None, persistence.get("lights/fan"))
		self.mock.set.assert_not_called()
		self.mock.get.assert_not_called()
		self.mock.publish.assert_called_once_with("lights/fan", "value")
Exemplo n.º 7
0
 def _set(self, state):
     """ Saves the given state to persistence """
     persistence.set(self._state_path(), state)
     pubsub.publish({'device': self, 'state': state})
Exemplo n.º 8
0
	def test_failure(self):
		# should swallow errors when setting
		import paho.mqtt
		self.mock.single.side_effect = paho.mqtt.MQTTException("Failure")
		persistence.set("lights/fan", "value")
Exemplo n.º 9
0
	def test_set(self):
		persistence.set("lights/fan", "value")
		call_args = self.mock.single.call_args
		self.assertEqual(call_args[0][0], "lights/fan")
		self.assertEqual(call_args[1]['payload'], "value")
Exemplo n.º 10
0
	def test_saved_to_right_place(self):
		key = "key_name"
		data = "Test"
		persistence.set(key, data)
		dir_contents = os.listdir(self._dirname)
		self.assertEqual(set([key]), set(dir_contents))
Exemplo n.º 11
0
	def test_failure(self):
		# should swallow errors when setting
		self.mock.get.side_effect = IOError("Failure")
		self.mock.set.side_effect = IOError("Failure")
		persistence.get("lights/fan")
		persistence.set("lights/fan", "value")
Exemplo n.º 12
0
	def test_get_wrong_name(self):
		key = "key_name"
		data = "Test"
		persistence.set(key, data)
		self.assertEqual(None, persistence.get(key+"Wrong"))
Exemplo n.º 13
0
	def test_set(self):
		persistence.set("lights/fan", "value")
		self.mock.set.assert_called_once_with("lights/fan", "value")
		self.mock.publish.assert_called_once_with("lights/fan", "value")
Exemplo n.º 14
0
	def test_save(self):
		key = "key_name"
		data = "Test"
		persistence.set(key, data)
		self.assertEqual(data, persistence.get(key))