basnijholt / miflora

☘️🌑🌼πŸ₯€πŸ‘ Mi Flora Plant sensor Python package
MIT License
362 stars 99 forks source link

Fix BluetoothInterface instantiation using positional arguments #134

Closed LaurentKol closed 4 years ago

LaurentKol commented 4 years ago

I was getting following error when trying to instantiate MiFloraPoller:

$ python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from miflora.miflora_poller import MiFloraPoller
>>> from btlewrap.bluepy import BluepyBackend
>>> poller = MiFloraPoller(mac='C4:7C:8D:xx:xx:xx', backend=BluepyBackend)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/.local/lib/python3.7/site-packages/miflora/miflora_poller.py", line 37, in __init__
    self._bt_interface = BluetoothInterface(backend, adapter)
TypeError: __init__() takes 2 positional arguments but 3 were given
>>>

I checked out master and replaced version I installed via pip3 and still getting same error. Using positional arguments fixes it for me so I thought I make a quick pull-request.

$ python3
Python 3.7.3 (default, Apr  3 2019, 05:39:12)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from miflora.miflora_poller import MiFloraPoller
>>> from btlewrap.bluepy import BluepyBackend
>>> poller = MiFloraPoller(mac='C4:7C:8D:xx:xx:xx', backend=BluepyBackend)
>>> poller.firmware_version()
'3.1.9'

I'm guessing this is related to my version of Python / modules so here's some info on my system:

$ pip3 install miflora
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting miflora
  Downloading https://www.piwheels.org/simple/miflora/miflora-0.5-py3-none-any.whl
Collecting btlewrap>=0.0.4 (from miflora)
  Downloading https://www.piwheels.org/simple/btlewrap/btlewrap-0.0.7-py3-none-any.whl
Collecting typing<4,>=3 (from btlewrap>=0.0.4->miflora)
  Downloading https://files.pythonhosted.org/packages/fe/2e/b480ee1b75e6d17d2993738670e75c1feeb9ff7f64452153cf018051cc92/typing-3.7.4.1-py3-none-any.whl
Installing collected packages: typing, btlewrap, miflora
Successfully installed btlewrap-0.0.7 miflora-0.5 typing-3.7.4.1

$ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:    10
Codename:   buster
eric-johnson commented 4 years ago

I was considering making a PR with this exact same change (which works for me), but it looks like #133 is the real fix here.

LaurentKol commented 4 years ago

Thanks for your comment, I'm just happy it's already taken care of and will close this PR.