Closed DavidDeSloovere closed 5 years ago
I'm actualy improving this even more now.
@jesserizzo My first PR from a few weeks back add support for the original envoy (Envoy-C). But after some refactoring that got broken.
This PR fixes the detection.
Detection is also a lot more efficient now. Only on the first call will the model be detected and saved in the "model" variable. It could still use some improvements:
(You should know I don't know any python except for what I wrote/learned for this envoy_reader, but I have been writing code for 20 years now.)
Don't know if there is still a need for and len(response.json()) == 3
@DavidDeSloovere
Instead of Model S and C maybe characterize them by feature set "supports_consumption" and "production_only" or something. The reason for this is there are some Envoy S that don't have the hardware for measuring consumption installed. This code should work for them, the len(response.json()) == 3
would detect them as a C.
Also, you're going back and forth between self.host
and self.url
Other than that, looks great. Thanks.
@jesserizzo It's a bit more than just supporting consumption or not I think. Because json properties are also different. So I refactored towards that, eliminating the try/except flow. Don't know if it's the same in python, but exceptions are expensive in .NET and shouldn't be used for control flow.
Using self.host in message and self.url in requests. Also refactored those.
@DavidDeSloovere Looks great, thanks!
Out of curiosity, how does this get on PyPi now?
I just upload it manually. Which I just did. Thanks again.
Do you mind if I do the PR for the home assistant component? Haven't done one in that project yet and would like to try.
Absolutely, go right ahead.
The 200 check was ok, but the check on
response.json()
threw and exception. When requestion production.json, the original envoy redirects to /error (and still returning 200, bad practice).Should be tested for Envoy S just to be sure.