keptenkurk / BS440

Python code to talk to Medisana BS440 bluetooth enabled bathroom scale
MIT License
50 stars 34 forks source link

Python 3 #99

Closed sgofferj closed 2 months ago

sgofferj commented 3 years ago

Many if not most Linux distros don't support Python 2 anymore. It would be nice if the code could be updated to Python 3, so it runs on a newer distro.

Tankyspanky commented 3 years ago

Yeah maybe time for a "update" :)

BS440.py /home/aad/BS440/BS440.py:192: DeprecationWarning: The SafeConfigParser class has been renamed to ConfigParser in Python 3.2. This alias will be removed in future versions. Use ConfigParser directly instead. config = SafeConfigParser()

And i also get a error on the BS440Domoticz.py on line 36 it looks like there is something missing there ??

I hope you read this and are willing to answer ;)

Because i would love to see it work

Tankyspanky commented 3 years ago

Bump :)

/home/aad/BS440/BS440.py:192: DeprecationWarning: The SafeConfigParser class has been renamed to ConfigParser in Python 3.2. This alias will be removed in future versions. Use ConfigParser directly instead. config = SafeConfigParser() 2021-08-26 00:14:03,970 INFO Configured plugins: BS440domoticz 2021-08-26 00:14:03,970 INFO Loading plugin: BS440domoticz Traceback (most recent call last): File "/home/aad/BS440/BS440.py", line 225, in mod = import(plugin) File "plugins/BS440domoticz.py", line 36 except Exception, e: ^ SyntaxError: invalid syntax

Tankyspanky commented 3 years ago

Jammer zag eruit als een mooi project om meer te kunnen integreren, maar het blijft achter in de tijd ... Python2 vs Python3

sgofferj commented 3 years ago

@Tankyspanky It's obvious that either the project is abandoned or the author is otherwise busy. Spamming the issue doesn't help in either case.

Tankyspanky commented 3 years ago

Sorry /hug

keptenkurk commented 3 years ago

Hi guys. It has been over 6 years since i prgrammed this BS440. Being an absolute NOOB on BLE, the BS440 and even Python programming alltogether i took me much time, but every minute was well spent since i learned so much googeling. The script is still in daily use at my home, but keeping it up to date is not at the top of my list currently. I even wonder if PyGatt is still usable and the right tool to use nowadays. And surely Python3 should be the interpreter to run on,

But i'm sure that with little effort, the syntax error in the comment above can be fixed. Pull requrests are welcomed.

aeff81 commented 2 years ago

Here's my patch to get the script running on Python 3.9:

diff --git a/BS440.py b/BS440.py
index 8049e2a..9698216 100644
--- a/BS440.py
+++ b/BS440.py
@@ -1,7 +1,7 @@
 from __future__ import print_function
 import pygatt.backends
 import logging
-from ConfigParser import SafeConfigParser
+from configparser import SafeConfigParser
 import time
 import subprocess
 from struct import *
@@ -55,12 +55,12 @@ def decodePerson(handle, values):

 def sanitize_timestamp(timestamp):
     retTS = 0
-    if timestamp + time_offset < sys.maxint:
+    if timestamp + time_offset < sys.maxsize:
         retTS = timestamp + time_offset
     else:
         retTS = timestamp

-    if timestamp >= sys.maxint:
+    if timestamp >= sys.maxsize:
         retTS = 0

     return retTS
creatvty commented 2 years ago

Hey, thanks for the help. I was able to make it work. Also I added now Auto Discovery for Homeassistant to the mqtt plugin https://github.com/creatvty/BS440-HA-AD

Boldfor commented 1 year ago

Hey, thanks for the help. I was able to make it work.

@creatvty & @aeff81, can you confirm that your new version is running under Python 3.9? I keep getting the following error:

Traceback (most recent call last):
  File "/home/pi/BS440-HA-AD/BS440.py", line 204, in <module>
    config.get('Program', 'loglevel').upper(),
  File "/usr/lib/python3.9/configparser.py", line 781, in get
    d = self._unify_values(section, vars)
  File "/usr/lib/python3.9/configparser.py", line 1149, in _unify_values
    raise NoSectionError(section) from None
configparser.NoSectionError: No section: 'Program'

Update: Sorry for spamming. Forgot to rename BS440.example.ini into BS440.ini.

Boldfor commented 1 year ago

@creatvty, please see my PR (#2) on fixing an issue around SafeConfigParser.

creatvty commented 1 year ago

Hey @Boldfor so you made it work? Cool stuff. I'll take a look.

Boldfor commented 1 year ago

@sgofferj, should be fixed and merged. Please have a look and close the issue.

sgofferj commented 1 year ago

I'll dig out an RPi and test it. Might take a moment, though because I repurposed the one I used for reading the scale.

sgofferj commented 2 months ago

Apologies for the delay. I finally dug out an RPi3 and installed it and it works. Thank you!