Beispiel #1
0
	def test_update_add(self):
		dl = DeviceList()

		dl.update(rf_address=RFAddr('122b65'), serial='123', name='foobar')
		self.assertEqual(dl, [
			Device(rf_address=RFAddr('122b65'), serial='123', name='foobar')
		])
Beispiel #2
0
	def test_for_room(self):
		dl = DeviceList()
		self.assertEqual(list(dl.for_room(0)), [])

		dev = Device(rf_address=RFAddr('122b65'), serial='123', name='foobar', room_id=1)
		dl.append(dev)
		self.assertEqual(list(dl.for_room(0)), [])
		self.assertEqual(list(dl.for_room(1)), [dev])
Beispiel #3
0
	def test_contains(self):
		dl = DeviceList()
		dl.append(Device(rf_address=RFAddr('122b65'), serial='123', name='foobar'))

		self.assertTrue('foobar' in dl)
		self.assertTrue(RFAddr('122b65') in dl)
		self.assertTrue(bytearray([0x12, 0x2b, 0x65]) in dl)
		self.assertFalse(True in dl)
		self.assertFalse(1 in dl)
Beispiel #4
0
	def test_update(self):
		for k, v in (
			('rf_address', '122b65'),
			('name', 'foobar'),
		):
			dl = DeviceList([
				Device(rf_address=RFAddr('122b65'), serial='123', name='foobar', room_id=0)
			])
			dl.update(room_id=1, **{k:v})

			self.assertEqual(dl, [
				Device(rf_address=RFAddr('122b65'), serial='123', name='foobar', room_id=1)
			])
Beispiel #5
0
	def test_get(self):
		dev = Device(rf_address=RFAddr('122b65'), serial='123', name='foobar')
		dl = DeviceList([dev])

		self.assertIsNone(dl.get())

		self.assertEqual(dl.get(rf_address='122b65'), dev)
		self.assertEqual(dl.get(rf_address='122b65', serial='123'), dev)
		self.assertEqual(dl.get(rf_address='122b65', serial='123', name='foobar'), dev)
		self.assertIsNone(dl.get(rf_address='122b65', serial='123', name='foobar', blah='blubb'))
		self.assertIsNone(dl.get(rf_address='foo'))