StephanJoubert / home_assistant_solarman

Home Assistant component for Solarman collectors used with a variety of inverters.
Apache License 2.0
507 stars 191 forks source link

Update sensor.py #587

Open CrazyUs3r opened 1 month ago

CrazyUs3r commented 1 month ago

The warning you're seeing is because Python is treating \S as an invalid escape sequence within the regular expression. In Python strings, the backslash \ is used as an escape character, so \S without a preceding r (indicating a raw string) is problematic.

To fix this, you should use a raw string for your regular expression. This way, backslashes are treated literally, not as escape characters. Here's the corrected line of code:

python

if uom and (re.match(r"\S+", uom)):

By adding the r before the string, it tells Python to treat the backslashes as literal characters. This should resolve the SyntaxWarning.

githubDante commented 1 month ago

If you add Closes #559 in the description the issue will be closed automatically if/when this is merged :wink:

sofkaski commented 6 days ago

If you add Closes #559 in the description the issue will be closed automatically if/when this is merged 😉

You could do this for example in this way in the commit message:

Fix regexp definition in sensor.py

Closes #559.

In general commit messages should be more descriptive. E.g. if you use git log --oneline it is nice to get already some hint what the change is about. Then in the body of the commit message you can tell more what has been changed and why. In this case link to the issue is likely enough.