From bbd3ce4b0aef9d768a3e8c8330e23685825e39a2 Mon Sep 17 00:00:00 2001 From: ratcash Date: Tue, 27 Mar 2018 20:55:35 +0200 Subject: [PATCH] renamed module to mitemp_bt --- .coveragerc | 2 +- README.md | 19 ++++++------ demo.py | 4 +-- mitemp.py | 20 ++++++------- {mitemp => mitemp_bt}/__init__.py | 0 .../mitemp_bt_poller.py | 2 +- setup.py | 2 +- test/integration_tests/test_everything.py | 6 ++-- ...emp_poller.py => test_mitemp_bt_poller.py} | 30 +++++++++---------- test/unit_tests/test_parse.py | 6 ++-- test/unit_tests/test_versioncheck.py | 4 +-- tox.ini | 4 +-- 12 files changed, 49 insertions(+), 50 deletions(-) rename {mitemp => mitemp_bt}/__init__.py (100%) rename mitemp/mitemp_poller.py => mitemp_bt/mitemp_bt_poller.py (99%) rename test/unit_tests/{test_mitemp_poller.py => test_mitemp_bt_poller.py} (82%) diff --git a/.coveragerc b/.coveragerc index ad1d349..edfad4a 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,5 +1,5 @@ [run] -source = mitemp +source = mitemp_bt omit = diff --git a/README.md b/README.md index 324fb67..1cf2371 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -# mitemp - Library for Xiaomi Mi Temperature and Humidity Sensor (v2) with Bleutooth LE and the LCD display - +# mitemp_bt - Library for Xiaomi Mi Temperature and Humidity Sensor (v2) with Bleutooth LE and the LCD display This library lets you read sensor data from a Xiaomi Mi BluetoothLE Temperature and Humidity sensor. @@ -27,10 +26,10 @@ binaray available on your machine. Example to use the bluez/gatttool wrapper: ```python -from mitemp.mitemp_poller import MiTempPoller +from mitemp_bt.mitemp_bt_poller import MiTempBtPoller from btlewrap.gatttool import GatttoolBackend -poller = MiTempPoller('some mac address', GatttoolBackend) +poller = MiTempBtPoller('some mac address', GatttoolBackend) ``` ### bluepy @@ -39,10 +38,10 @@ To use the [bluepy](https://github.com/IanHarvey/bluepy) library you have to ins Example to use the bluepy backend: ```python -from mitemp.mitemp_poller import MiTempPoller +from mitemp_bt.mitemp_bt_poller import MiTempBtPoller from btlewrap.bluepy import BluepyBackend -poller = MiTempPoller('some mac address', BluepyBackend) +poller = MiTempBtPoller('some mac address', BluepyBackend) ``` ### pygatt @@ -52,7 +51,7 @@ install the bluepy library on your machine. In most cases this can be done via: Example to use the pygatt backend: ```python -from mitemp.mitemp_poller import MiTempPoller +from mitemp_bt.mitemp_bt_poller import MiTempBtPoller from btlewrap.pygatt import PygattBackend poller = MiTempPoller('some mac address', PygattBackend) @@ -63,9 +62,9 @@ please have a look at [CONTRIBUTING.md](CONTRIBUTING.md) ---- -## Projects Depending on `mitemp` +## Projects Depending on `mitemp_bt` The following shows a selected list of projects using this library: -* https://github.com/ThomDietrich/miflora-mqtt-daemon - An MQTT Client/Daemon for Smart Home solution integration -* https://home-assistant.io/components/sensor.miflora/ - Integration in Home Assistant +* https://github.com/ThomDietrich/mitemp_bt-mqtt-daemon - An MQTT Client/Daemon for Smart Home solution integration +* https://home-assistant.io/components/sensor.mitemp_bt/ - Integration in Home Assistant diff --git a/demo.py b/demo.py index 3684526..af9607f 100755 --- a/demo.py +++ b/demo.py @@ -7,7 +7,7 @@ import sys from btlewrap import available_backends, BluepyBackend, GatttoolBackend, PygattBackend -from mitemp.mitemp_poller import MiTempPoller, \ +from mitemp_bt.mitemp_bt_poller import MiTempBtPoller, \ MI_TEMPERATURE, MI_HUMIDITY, MI_BATTERY @@ -21,7 +21,7 @@ def valid_mitemp_mac(mac, pat=re.compile(r"4C:65:A8:[0-9A-F]{2}:[0-9A-F]{2}:[0-9 def poll(args): """Poll data from the sensor.""" backend = _get_backend(args) - poller = MiTempPoller(args.mac, backend) + poller = MiTempBtPoller(args.mac, backend) print("Getting data from Mi Temperature and Humidity Sensor") print("FW: {}".format(poller.firmware_version())) print("Name: {}".format(poller.name())) diff --git a/mitemp.py b/mitemp.py index d22e131..8ff5a4c 100644 --- a/mitemp.py +++ b/mitemp.py @@ -2,7 +2,7 @@ Support for Xiaomi Mi Temp BLE environmental sensor. For more details about this platform, please refer to the documentation at -https://home-assistant.io/components/sensor.mitemp/ +https://home-assistant.io/components/sensor.mitemp_bt/ """ import logging @@ -16,7 +16,7 @@ ) -REQUIREMENTS = ['mitemp==0.0.1'] +REQUIREMENTS = ['mitemp_bt==0.0.1'] _LOGGER = logging.getLogger(__name__) @@ -30,7 +30,7 @@ DEFAULT_UPDATE_INTERVAL = 300 DEFAULT_FORCE_UPDATE = False DEFAULT_MEDIAN = 3 -DEFAULT_NAME = 'Mi Temp' +DEFAULT_NAME = 'MiTemp BT' DEFAULT_RETRIES = 2 DEFAULT_TIMEOUT = 10 @@ -57,8 +57,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None): - """Set up the MiTemp sensor.""" - from mitemp import mitemp_poller + """Set up the MiTempBt sensor.""" + from mitemp_bt import mitemp_bt_poller try: import bluepy.btle # noqa: F401 # pylint: disable=unused-variable from btlewrap import BluepyBackend @@ -66,10 +66,10 @@ def setup_platform(hass, config, add_devices, discovery_info=None): except ImportError: from btlewrap import GatttoolBackend backend = GatttoolBackend - _LOGGER.debug('MiTemp is using %s backend.', backend.__name__) + _LOGGER.debug('MiTempBt is using %s backend.', backend.__name__) cache = config.get(CONF_CACHE) - poller = mitemp_poller.MiTempPoller( + poller = mitemp_bt_poller.MiTempBtPoller( config.get(CONF_MAC), cache_timeout=cache, adapter=config.get(CONF_ADAPTER), backend=backend) force_update = config.get(CONF_FORCE_UPDATE) @@ -87,14 +87,14 @@ def setup_platform(hass, config, add_devices, discovery_info=None): if prefix: name = "{} {}".format(prefix, name) - devs.append(MiTempSensor( + devs.append(MiTempBtSensor( poller, parameter, name, unit, force_update, median)) add_devices(devs) -class MiTempSensor(Entity): - """Implementing the MiTemp sensor.""" +class MiTempBtSensor(Entity): + """Implementing the MiTempBt sensor.""" def __init__(self, poller, parameter, name, unit, force_update, median): """Initialize the sensor.""" diff --git a/mitemp/__init__.py b/mitemp_bt/__init__.py similarity index 100% rename from mitemp/__init__.py rename to mitemp_bt/__init__.py diff --git a/mitemp/mitemp_poller.py b/mitemp_bt/mitemp_bt_poller.py similarity index 99% rename from mitemp/mitemp_poller.py rename to mitemp_bt/mitemp_bt_poller.py index 2b2a553..e85b010 100644 --- a/mitemp/mitemp_poller.py +++ b/mitemp_bt/mitemp_bt_poller.py @@ -20,7 +20,7 @@ _LOGGER = logging.getLogger(__name__) -class MiTempPoller(object): +class MiTempBtPoller(object): """" A class to read data from Mi Temp plant sensors. """ diff --git a/setup.py b/setup.py index 1c143f9..5dee0ce 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( - name='mitemp', + name='mitemp_bt', version='0.0.1', description='Library to read data from Mi Temperature and Humidity Sensor (V2) with LCD display', url='https://github.com/open-homeautomation/mitemp', diff --git a/test/integration_tests/test_everything.py b/test/integration_tests/test_everything.py index 3e699c1..9e033da 100644 --- a/test/integration_tests/test_everything.py +++ b/test/integration_tests/test_everything.py @@ -3,8 +3,8 @@ import pytest from btlewrap.gatttool import GatttoolBackend from btlewrap.bluepy import BluepyBackend -from mitemp.mitemp_poller import (MiTempPoller, MI_TEMPERATURE, - MI_HUMIDITY, MI_BATTERY) +from mitemp_bt.mitemp_bt_poller import (MiTempBtPoller, MI_TEMPERATURE, + MI_HUMIDITY, MI_BATTERY) class TestEverythingGatt(unittest.TestCase): @@ -24,7 +24,7 @@ def test_everything(self): real sensor close by. """ assert hasattr(self, "mac") - poller = MiTempPoller(self.mac, self.backend_type) + poller = MiTempBtPoller(self.mac, self.backend_type) self.assertIsNotNone(poller.firmware_version()) self.assertIsNotNone(poller.name()) self.assertIsNotNone(poller.parameter_value(MI_TEMPERATURE)) diff --git a/test/unit_tests/test_mitemp_poller.py b/test/unit_tests/test_mitemp_bt_poller.py similarity index 82% rename from test/unit_tests/test_mitemp_poller.py rename to test/unit_tests/test_mitemp_bt_poller.py index 0e4ed00..01ee8a4 100644 --- a/test/unit_tests/test_mitemp_poller.py +++ b/test/unit_tests/test_mitemp_bt_poller.py @@ -3,11 +3,11 @@ from test.helper import MockBackend, ConnectExceptionBackend, RWExceptionBackend from btlewrap.base import BluetoothBackendException -from mitemp.mitemp_poller import MiTempPoller, MI_TEMPERATURE, MI_HUMIDITY, MI_BATTERY +from mitemp_bt.mitemp_bt_poller import MiTempBtPoller, MI_TEMPERATURE, MI_HUMIDITY, MI_BATTERY -class TestMiTempPoller(unittest.TestCase): - """Tests for the MiTempPoller class.""" +class TestMiTempBtPoller(unittest.TestCase): + """Tests for the MiTempBtPoller class.""" # access to protected members is fine in testing # pylint: disable = protected-access @@ -16,11 +16,11 @@ class TestMiTempPoller(unittest.TestCase): def test_format_bytes(self): """Test conversion of bytes to string.""" - self.assertEqual('AA BB 00', MiTempPoller._format_bytes([0xAA, 0xBB, 0x00])) + self.assertEqual('AA BB 00', MiTempBtPoller._format_bytes([0xAA, 0xBB, 0x00])) def test_read_battery(self): """Test reading the battery level.""" - poller = MiTempPoller(self.TEST_MAC, MockBackend) + poller = MiTempBtPoller(self.TEST_MAC, MockBackend) backend = self._get_backend(poller) backend.battery_level = 50 self.assertEqual(50, poller.battery_level()) @@ -29,7 +29,7 @@ def test_read_battery(self): def test_read_version(self): """Test reading the version number.""" - poller = MiTempPoller(self.TEST_MAC, MockBackend) + poller = MiTempBtPoller(self.TEST_MAC, MockBackend) backend = self._get_backend(poller) backend.set_version('00.00.11') self.assertEqual('00.00.11', poller.firmware_version()) @@ -40,7 +40,7 @@ def test_read_measurements(self): Here we expect some data being written to the sensor. """ - poller = MiTempPoller(self.TEST_MAC, MockBackend) + poller = MiTempBtPoller(self.TEST_MAC, MockBackend) backend = self._get_backend(poller) backend.temperature = 56.7 @@ -49,7 +49,7 @@ def test_read_measurements(self): def test_name(self): """Check reading of the sensor name.""" - poller = MiTempPoller(self.TEST_MAC, MockBackend) + poller = MiTempBtPoller(self.TEST_MAC, MockBackend) backend = self._get_backend(poller) backend.name = 'my sensor name' @@ -57,7 +57,7 @@ def test_name(self): def test_clear_cache(self): """Test with negative temperature.""" - poller = MiTempPoller(self.TEST_MAC, MockBackend) + poller = MiTempBtPoller(self.TEST_MAC, MockBackend) backend = self._get_backend(poller) self.assertFalse(poller.cache_available()) @@ -82,7 +82,7 @@ def test_no_answer_data(self): Check that this triggers the right exception. """ - poller = MiTempPoller(self.TEST_MAC, MockBackend) + poller = MiTempBtPoller(self.TEST_MAC, MockBackend) backend = self._get_backend(poller) backend.handle_0x0010_raw = None with self.assertRaises(BluetoothBackendException): @@ -93,7 +93,7 @@ def test_no_answer_name(self): Check that this triggers the right exception. """ - poller = MiTempPoller(self.TEST_MAC, MockBackend) + poller = MiTempBtPoller(self.TEST_MAC, MockBackend) backend = self._get_backend(poller) backend.handle_0x03_raw = None with self.assertRaises(BluetoothBackendException): @@ -104,14 +104,14 @@ def test_no_answer_firmware_version(self): Check that this triggers the right exception. """ - poller = MiTempPoller(self.TEST_MAC, MockBackend) + poller = MiTempBtPoller(self.TEST_MAC, MockBackend) backend = self._get_backend(poller) backend.handle_0x0024_raw = None self.assertTrue(poller.firmware_version() is None) def test_connect_exception(self): """Test reaction when getting a BluetoothBackendException.""" - poller = MiTempPoller(self.TEST_MAC, ConnectExceptionBackend, retries=0) + poller = MiTempBtPoller(self.TEST_MAC, ConnectExceptionBackend, retries=0) with self.assertRaises(BluetoothBackendException): poller.firmware_version() with self.assertRaises(BluetoothBackendException): @@ -123,7 +123,7 @@ def test_connect_exception(self): def test_rw_exception(self): """Test reaction when getting a BluetoothBackendException.""" - poller = MiTempPoller(self.TEST_MAC, RWExceptionBackend, retries=0) + poller = MiTempBtPoller(self.TEST_MAC, RWExceptionBackend, retries=0) with self.assertRaises(BluetoothBackendException): poller.firmware_version() with self.assertRaises(BluetoothBackendException): @@ -135,5 +135,5 @@ def test_rw_exception(self): @staticmethod def _get_backend(poller): - """Get the backend from a MiTempPoller object.""" + """Get the backend from a MiTempBtPoller object.""" return poller._bt_interface._backend diff --git a/test/unit_tests/test_parse.py b/test/unit_tests/test_parse.py index 8821168..cc3a91c 100644 --- a/test/unit_tests/test_parse.py +++ b/test/unit_tests/test_parse.py @@ -5,7 +5,7 @@ import unittest from datetime import datetime from test.helper import MockBackend -from mitemp.mitemp_poller import MiTempPoller, MI_TEMPERATURE, MI_HUMIDITY +from mitemp_bt.mitemp_bt_poller import MiTempBtPoller, MI_TEMPERATURE, MI_HUMIDITY class KNXConversionTest(unittest.TestCase): @@ -14,8 +14,8 @@ class KNXConversionTest(unittest.TestCase): # pylint: disable=protected-access def test_parsing(self): - """Does the Mi TEMP data parser works correctly?""" - poller = MiTempPoller(None, MockBackend) + """Does the Mi TEMP BT data parser works correctly?""" + poller = MiTempBtPoller(None, MockBackend) data = bytes([0x54, 0x3d, 0x32, 0x35, 0x2e, 0x36, 0x20, 0x48, 0x3d, 0x32, 0x33, 0x2e, 0x36, 0x00]) poller._cache = data diff --git a/test/unit_tests/test_versioncheck.py b/test/unit_tests/test_versioncheck.py index 29e44f8..9488dea 100644 --- a/test/unit_tests/test_versioncheck.py +++ b/test/unit_tests/test_versioncheck.py @@ -15,7 +15,7 @@ def test_py2(self): if sys.version_info >= self.MIN_SUPPORTED_VERSION: return try: - import mitemp # noqa: F401 # pylint: disable=unused-variable + import mitemp_bt # noqa: F401 # pylint: disable=unused-variable self.fail('Should have thrown an exception') except ValueError as val_err: self.assertIn('version', str(val_err)) @@ -24,4 +24,4 @@ def test_py3(self): """Make sure newer python versions do not throw an exception.""" if sys.version_info < self.MIN_SUPPORTED_VERSION: return - import mitemp # noqa: F401 # pylint: disable=unused-variable + import mitemp_bt # noqa: F401 # pylint: disable=unused-variable diff --git a/tox.ini b/tox.ini index a94c684..4a84347 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,7 @@ deps = -rrequirements.txt -rrequirements-test.txt passenv = TRAVIS TRAVIS_* -commands = pytest --cov=mitemp --timeout=10 test/unit_tests +commands = pytest --cov=mitemp_bt --timeout=10 test/unit_tests [testenv:py27] # only run unit tests as they do not need additional hardware @@ -33,4 +33,4 @@ commands=flake8 [testenv:pylint] basepython = python3 skip_install = true -commands = pylint -j4 mitemp test setup.py demo.py +commands = pylint -j4 mitemp_bt test setup.py demo.py