def test_read_rain_collector_type(self, mock_read_config_setting):
		mock_read_config_setting.return_value = six.int2byte(0b10101110)

		collector_type = RainCollectorTypeSerial(self.communicator.read_rain_collector_type())

		self.assertEqual(RainCollectorTypeSerial.millimeters_0_1, collector_type)
		mock_read_config_setting.assert_called_once_with('2B', '01')

		mock_read_config_setting.reset_mock()

		mock_read_config_setting.return_value = six.int2byte(0b10011110)

		collector_type = RainCollectorTypeSerial(self.communicator.read_rain_collector_type())

		self.assertEqual(RainCollectorTypeSerial.millimeters_0_2, collector_type)
		mock_read_config_setting.assert_called_once_with('2B', '01')

		mock_read_config_setting.reset_mock()

		mock_read_config_setting.return_value = six.int2byte(0b10001110)

		collector_type = RainCollectorTypeSerial(self.communicator.read_rain_collector_type())

		self.assertEqual(RainCollectorTypeSerial.inches_0_01, collector_type)
		mock_read_config_setting.assert_called_once_with('2B', '01')
	def test_millimeters_0_1(self):
		self.assertEqual(RainCollectorTypeSerial.millimeters_0_1, RainCollectorTypeSerial(0x20))

		self.assertAlmostEqual(
			Decimal('0.00393701'),
			RainCollectorTypeSerial.millimeters_0_1.clicks_to_inches(1),
			delta=0.000001,
		)
		self.assertAlmostEqual(
			Decimal('0.275591'),
			RainCollectorTypeSerial.millimeters_0_1.clicks_to_inches(70),
			delta=0.000001,
		)

		self.assertEqual(Decimal('0.01'), RainCollectorTypeSerial.millimeters_0_1.clicks_to_centimeters(1))
		self.assertEqual(Decimal('0.70'), RainCollectorTypeSerial.millimeters_0_1.clicks_to_centimeters(70))
	def test_millimeters_0_2(self):
		self.assertEqual(RainCollectorTypeSerial.millimeters_0_2, RainCollectorTypeSerial(0x10))

		self.assertAlmostEqual(
			Decimal('0.00787402'),
			RainCollectorTypeSerial.millimeters_0_2.clicks_to_inches(1),
			delta=0.000001,
		)
		self.assertAlmostEqual(
			Decimal('0.551181'),
			RainCollectorTypeSerial.millimeters_0_2.clicks_to_inches(70),
			delta=0.000001,
		)

		self.assertEqual(Decimal('0.02'), RainCollectorTypeSerial.millimeters_0_2.clicks_to_centimeters(1))
		self.assertEqual(Decimal('1.40'), RainCollectorTypeSerial.millimeters_0_2.clicks_to_centimeters(70))
	def test_inches_0_01(self):
		self.assertEqual(RainCollectorTypeSerial.inches_0_01, RainCollectorTypeSerial(0x00))

		self.assertEqual(Decimal('0.01'), RainCollectorTypeSerial.inches_0_01.clicks_to_inches(1))
		self.assertEqual(Decimal('0.70'), RainCollectorTypeSerial.inches_0_01.clicks_to_inches(70))

		self.assertAlmostEqual(
			Decimal('0.0254'),
			RainCollectorTypeSerial.inches_0_01.clicks_to_centimeters(1),
			delta=0.000001,
		)
		self.assertAlmostEqual(
			Decimal('1.778'),
			RainCollectorTypeSerial.inches_0_01.clicks_to_centimeters(70),
			delta=0.000001,
		)
Exemple #5
0
	if ack == chr(curses.ascii.ACK):
		print 'Expected ACK received...'
	else:
		print 'Unknown ACK received: %s...' % ack
	setup_bits = sock.recv(1)
	crc = sock.recv(2)
	handle.write(ack)
	handle.write(setup_bits)
	handle.write(crc)
	handle.write('\n')
	print 'CRC: %s vs %s = result %s...' % (
		calculate_weatherlink_crc(setup_bits),
		struct.unpack_from('<h', crc)[0],
		calculate_weatherlink_crc(setup_bits + crc),
	)
	collector_type = RainCollectorTypeSerial(ord(setup_bits) & 0x30)
	print 'Rain collector type is %s.' % collector_type
	print

	print 'Requesting loop packets...'
	sock.sendall('LPS 2 30\n')  # "request loop packets," "type LOOP2," "30 packets"

	ack = sock.recv(1)
	if ack == chr(curses.ascii.ACK):
		print 'Expected ACK received...'
	else:
		print 'Unknown ACK received: %s...' % ack
	handle.write(struct.pack('<B', ord(ack)))

	sock_file = sock.makefile()
	for i in range(0, 15):