Ejemplo n.º 1
0
	def test_discovery_custom_prefix(self):
		device_settings = {
			"name": "fake",
			"label": "Fake Device"
		}
		settings = {
			"_publish": self.mock,
			"discovery_prefix": "myhass",
			"discovery_devices": [
				drivers.FakeFan(**device_settings),
				drivers.FakeLight(**device_settings)
			]
		}
		config.PERSISTENCE = [persistence.MQTTHomeAssistant(**settings)]
		msgs = self.mock.multiple.call_args[0][0]
		self.assertEqual(2, len(msgs))	# two devices were announced
		self.assertEqual('myhass/fan/fans_fake/config', msgs[0]['topic'])
		self.assertEqual('myhass/light/lights_fake/config', msgs[1]['topic'])
		fan = json.loads(msgs[0]['payload'])
		desired_fan = {
			'name': 'Fake Device',
			'state_topic': 'myhass/fan/fans_fake/state',
			'command_topic': 'myhass/fan/fans_fake/set',
			'speed_state_topic': 'myhass/fan/fans_fake_speed/state',
			'speed_command_topic': 'myhass/fan/fans_fake_speed/set',
			'payload_off': 'OFF',
			'payload_low_speed': '1',
			'payload_medium_speed': '2',
			'payload_high_speed': '3',
			'speeds': ['low', 'medium', 'high']
		}
		self.assertEqual(desired_fan, fan)
Ejemplo n.º 2
0
 def test_fan_speed_firsttime(self):
     with pubsub.subscribe() as event_source:
         fan = drivers.FakeFan(name="test", label="Test")
         fan.subdevices['speed'].set_state("2")
         self.assertEqual("ON", fan.get_state())
         self.assertEqual("ON", fan.subdevices['power'].get_state())
         self.assertEqual("2", fan.subdevices['speed'].get_state())
         self.assertEqual("2", fan.subdevices['command'].get_state())
         # collect events
         events = events_summary(event_source)
     self.assertEqual("ON", events['fans/test'])
     self.assertEqual("ON", events['fans/test/power'])
     self.assertEqual("2", events['fans/test/speed'])
     self.assertEqual("2", events['fans/test/command'])
Ejemplo n.º 3
0
 def test_state(self):
     light = drivers.FakeLight(name="test", label="Test")
     light.set_state("ON")
     self.assertEqual("ON", light.get_state())
     light.set_state("OFF")
     self.assertEqual("OFF", light.get_state())
     self.assertEqual(set(["ON", "OFF"]), set(light.get_available_states()))
     fan = drivers.FakeFan(name="test", label="Test")
     self.assertEqual(set(["OFF", "ON"]), set(fan.get_available_states()))
     self.assertEqual(set(["OFF", "ON"]),
                      set(fan.subdevices['power'].get_available_states()))
     self.assertEqual(set(["1", "2", "3"]),
                      set(fan.subdevices['speed'].get_available_states()))
     self.assertEqual(set(["0", "1", "2", "3"]),
                      set(fan.subdevices['command'].get_available_states()))
Ejemplo n.º 4
0
 def test_class(self):
     fan = drivers.FakeFan(name="test", label="Test")
     self.assertEqual('fans', fan.get_class())
     light = drivers.FakeLight(name="test", label="Test")
     self.assertEqual('lights', light.get_class())
Ejemplo n.º 5
0
 def test_create(self):
     dev = drivers.FakeFan(name="test", label="Test")
     dev = drivers.FakeLight(name="test", label="Test")