Skip to content
This repository has been archived by the owner on Aug 29, 2024. It is now read-only.

Commit

Permalink
* fixed broken testcase
Browse files Browse the repository at this point in the history
* fixed lint warning
  • Loading branch information
ChristianKuehnel committed Nov 27, 2017
1 parent b016655 commit 12c1180
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
24 changes: 14 additions & 10 deletions plantgw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,7 @@ def __init__(self, config_file_path):
with open(config_file_path, 'r') as config_file:
config = yaml.load(config_file)

timeform = '%a, %d %b %Y %H:%M:%S'
logform = '%(asctime)s %(levelname)-8s %(message)s'
if 'logfile' in config:
logfile = os.path.abspath(os.path.expanduser(config['logfile']))
if 'debug' in config:
logging.basicConfig(filename=logfile, level=logging.DEBUG, datefmt=timeform, format=logform)
else:
logging.basicConfig(filename=logfile, level=logging.INFO, datefmt=timeform, format=logform)
else:
logging.basicConfig(level=logging.DEBUG, datefmt=timeform, format=logform)
self._configure_logging(config)

self.interface = 0
if 'interface' in config:
Expand Down Expand Up @@ -81,6 +72,19 @@ def __init__(self, config_file_path):
fail_silent = 'fail_silent' in sensor_config
self.sensors.append(SensorConfig(sensor_config['mac'], sensor_config['alias'], fail_silent))

@staticmethod
def _configure_logging(config):
timeform = '%a, %d %b %Y %H:%M:%S'
logform = '%(asctime)s %(levelname)-8s %(message)s'
if 'logfile' in config:
logfile = os.path.abspath(os.path.expanduser(config['logfile']))
if 'debug' in config:
logging.basicConfig(filename=logfile, level=logging.DEBUG, datefmt=timeform, format=logform)
else:
logging.basicConfig(filename=logfile, level=logging.INFO, datefmt=timeform, format=logform)
else:
logging.basicConfig(level=logging.DEBUG, datefmt=timeform, format=logform)


class SensorConfig(object):
"""Stores the configuration of a sensor."""
Expand Down
4 changes: 2 additions & 2 deletions plantgw/test/test_misensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ def test_format_bytes(self):
@mock.patch('plantgw.misensor.Peripheral')
def test_decode_38(self, mock_peripheral):
test_data = self._str2bytearray("62 1d 32 2e 38 2e 36")
s = Sensor('11:22:33')
s = Sensor('11:22:33', 0)
s._decode_38(test_data)
self.assertEqual(s.battery, 98)
self.assertEqual(s.version, '2.8.6')

@mock.patch('plantgw.misensor.Peripheral')
def test_decode_35(self, mock_peripheral):
test_data = self._str2bytearray("ce 00 00 35 00 00 00 1c c8 00 02 3c 00 fb 34 9b")
s = Sensor('11:22:33')
s = Sensor('11:22:33', 0)
s._decode_35(test_data)
self.assertEqual(s.temperature, 20.6)
self.assertEqual(s.moisture, 28)
Expand Down

0 comments on commit 12c1180

Please sign in to comment.