Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite to async #58

Merged
merged 40 commits into from
May 31, 2024
Merged

Rewrite to async #58

merged 40 commits into from
May 31, 2024

Conversation

Snuffy2
Copy link
Collaborator

@Snuffy2 Snuffy2 commented Apr 28, 2024

This is a behind the scenes rewrite to change to async functions. The existing Docker and Command-line settings didn't change so all previous setups will continue to work.

Changes

  • Change JuiceboxTelnet from telnetlib to telnetlib3 (Fixes Transition from deprecated python telnetlib #25)
    • This started the cascade of needing to update every other class to async as well
  • Update JuiceboxUDPCUpdater, JuiceboxMQTTHandler (fka. JuiceboxMessageHandler) to async and moved to separate files.
    • In JuiceboxMQTTHandler, built out framework that should better support sending commands from JPP to the JuiceBox as well as storing the latest value sent to HA. Hopefully this, along with the Experimental option below, will facilitate further development of controlling the JuiceBox from JPP/HA.
  • Updating PyProxy required essentially a full rewrite so renamed to JuiceboxMITM. Incorporated asyncio-dgram
  • Add EXPERIMENTAL option for users to opt in to the in development functions. Currently this exposes:
    • Data from JuiceBox and Data from EnelX sensors to HA
    • A MVP Text field to send "commands" to the JuiceBox
  • Improved logging including logging to both stderr and a file. Implement log rotation to keep 14 days of file logs.
  • Implemented aiorun and tini for better garbage management, thread cleanup, and graceful shutdowns
  • Attempted to incorporate better handling when connections or updates fail. This includes restarting connections, implementing timeouts to prevent freezing, as well as fully exiting the program when too many errors have occurred to allow a docker restart of the app.
  • Incorporate several items from implement some numbers to prepare to control charging current #55
    • Add ignore remote option, now called IGNORE_ENELX option to prevent commands from EnelX to going to the JuiceBox and data from the JuiceBox from going to EnelX
      • Any commands from EnelX will still be captured by JPP
    • Add Current Rating sensor
    • Add the parsed fields from the JuiceBox status messages as attributes in the Local Data experimental sensor
  • Moving away from SRC and DST in both the settings and the code as it was not clear what they should contain.
    • Deprecated the SRC option and replaced it with LOCAL_IP
    • Deprecated the DST option and replaced it with ENELX_IP
    • Current setups using SRC and DST will continue to work for now but should eventually be updated to the new terms.
  • Add LOCAL_PORT option (Fixes Add option for different local port #60)

telnetlib to telnetlib3
add aiorun
logging improvements
@Snuffy2 Snuffy2 force-pushed the Rewrite-to-async branch 3 times, most recently from c4dfaf9 to 4cd4fff Compare April 30, 2024 21:00
telnetlib to telnetlib3
add aiorun
logging improvements
add experimental options
@Snuffy2 Snuffy2 force-pushed the Rewrite-to-async branch 2 times, most recently from 72276cb to 5fcf79a Compare May 1, 2024 02:37
@Snuffy2 Snuffy2 force-pushed the Rewrite-to-async branch 2 times, most recently from 37136e5 to 605d061 Compare May 8, 2024 00:12
@Snuffy2 Snuffy2 marked this pull request as ready for review May 8, 2024 01:19
@Snuffy2
Copy link
Collaborator Author

Snuffy2 commented May 8, 2024

At this point, I believe this is ready for review and testing. I released it with the async_beta docker tag for testing as well.

services:
  juicepassproxy:
    image: ghcr.io/snicker/juicepassproxy:async_beta

   [...]

I'll likely end up making some more small tweaks and will remove some extraneous logging and commented out code.
@snicker
@ivanfmartinez
@FalconFour

@Snuffy2 Snuffy2 requested a review from snicker May 8, 2024 01:51
@ivanfmartinez
Copy link
Contributor

At this point, I believe this is ready for review and testing. I released it with the async_beta docker tag for testing as well.

services:
  juicepassproxy:
    image: ghcr.io/snicker/juicepassproxy:async_beta

   [...]

I'll likely end up making some more small tweaks and will remove some extraneous logging and commented out code. @snicker @ivanfmartinez @FalconFour

I will try to test on this weekend.

Thanks

@ivanfmartinez
Copy link
Contributor

@Snuffy2 I think that when using ignore_enel_x, the telnet to juicebox step can be skipped

juicepassproxy_tst | 2024-05-15 09:04:33 INFO [entrypoint.sh] IGNORE_ENELX: true
juicepassproxy_tst | 2024-05-15 09:04:33 INFO [entrypoint.sh] EXPERIMENTAL: true
juicepassproxy_tst | 2024-05-15 09:04:33 WARNING [main] Starting JuicePass Proxy v0.2.2 (Log Level: INFO)
juicepassproxy_tst | 2024-05-15 09:04:33 INFO [main] log_loc: /log/juicepassproxy.log
juicepassproxy_tst | 2024-05-15 09:04:33 INFO [main] config_loc: /config/juicepassproxy.yaml
juicepassproxy_tst | 2024-05-15 09:04:33 INFO [main] telnet timeout: 30
juicepassproxy_tst | 2024-05-15 09:05:03 WARNING [main] Error in getting EnelX Server and Port via Telnet. (TimeoutError: Telnet Connection Failed)
juicepassproxy_tst | 2024-05-15 09:05:03 INFO [main] enelx_server: jbv1.emotorwerks.com
juicepassproxy_tst | 2024-05-15 09:05:03 INFO [main] enelx_port: 8042
juicepassproxy_tst | 2024-05-15 09:05:03 INFO [main] local_addr: 172.30.0.2:8042
juicepassproxy_tst | 2024-05-15 09:05:03 INFO [main] enelx_addr: 158.47.1.128:8042

@ivanfmartinez
Copy link
Contributor

When I stopped charging the car, the current value did not change to 0, the proxy just stopped sending updates.

juicepassproxy_tst    | 2024-05-15 09:42:10  INFO      [ha_mqtt_discoverable.sensors] Setting Voltage to 133.0 using hmd/sensor/JuiceBox/Voltage/state
juicepassproxy_tst    | 2024-05-15 09:42:10  INFO      [ha_mqtt_discoverable.sensors] Setting Energy (Lifetime) to 4117615.0 using hmd/sensor/JuiceBox/Energy--Lifetime-/state
juicepassproxy_tst    | 2024-05-15 09:42:10  INFO      [ha_mqtt_discoverable.sensors] Setting Status to Charging using hmd/sensor/JuiceBox/Status/state
juicepassproxy_tst    | 2024-05-15 09:42:10  INFO      [ha_mqtt_discoverable.sensors] Setting Temperature to 69.8 using hmd/sensor/JuiceBox/Temperature/state
juicepassproxy_tst    | 2024-05-15 09:42:10  INFO      [ha_mqtt_discoverable.sensors] Setting Current Rating to 32.0 using hmd/sensor/JuiceBox/Current-Rating/state
juicepassproxy_tst    | 2024-05-15 09:42:10  INFO      [ha_mqtt_discoverable.sensors] Setting Frequency to 60.07 using hmd/sensor/JuiceBox/Frequency/state
juicepassproxy_tst    | 2024-05-15 09:42:10  INFO      [ha_mqtt_discoverable.sensors] Setting Energy (Session) to 1379.0 using hmd/sensor/JuiceBox/Energy--Session-/state
juicepassproxy_tst    | 2024-05-15 09:42:10  INFO      [ha_mqtt_discoverable.sensors] Setting Current to 12.0 using hmd/sensor/JuiceBox/Current/state
juicepassproxy_tst    | 2024-05-15 09:42:10  INFO      [ha_mqtt_discoverable.sensors] Setting Power to 1596.0 using hmd/sensor/JuiceBox/Power/state
juicepassproxy_tst    | 2024-05-15 09:42:10  INFO      [ha_mqtt_discoverable.sensors] Setting Data from JuiceBox to X:v09u,s001,F31,u00064112,V1330,L00004117615,S02,T21,M0024,C0024,m0032,t09,i45,e-0001,f6007,r99,b000,B0000000,P0,E0001379,A00120,p0995!ZHS: using hmd/sensor/JuiceBox/Data-from-JuiceBox/state
juicepassproxy_tst    | 2024-05-15 09:42:16  INFO      [ha_mqtt_discoverable.sensors] Setting Voltage to 133.4 using hmd/sensor/JuiceBox/Voltage/state
juicepassproxy_tst    | 2024-05-15 09:42:16  INFO      [ha_mqtt_discoverable.sensors] Setting Energy (Lifetime) to 4117618.0 using hmd/sensor/JuiceBox/Energy--Lifetime-/state
juicepassproxy_tst    | 2024-05-15 09:42:16  INFO      [ha_mqtt_discoverable.sensors] Setting Status to Plugged In using hmd/sensor/JuiceBox/Status/state
juicepassproxy_tst    | 2024-05-15 09:42:16  INFO      [ha_mqtt_discoverable.sensors] Setting Temperature to 69.8 using hmd/sensor/JuiceBox/Temperature/state
juicepassproxy_tst    | 2024-05-15 09:42:16  INFO      [ha_mqtt_discoverable.sensors] Setting Current Rating to 32.0 using hmd/sensor/JuiceBox/Current-Rating/state
juicepassproxy_tst    | 2024-05-15 09:42:16  INFO      [ha_mqtt_discoverable.sensors] Setting Frequency to 60.09 using hmd/sensor/JuiceBox/Frequency/state
juicepassproxy_tst    | 2024-05-15 09:42:16  INFO      [ha_mqtt_discoverable.sensors] Setting Power to 0.0 using hmd/sensor/JuiceBox/Power/state
juicepassproxy_tst    | 2024-05-15 09:42:16  INFO      [ha_mqtt_discoverable.sensors] Setting Data from JuiceBox to X:v09u,s001,F30,u00064118,V1334,L00004117618,S01,T21,M0024,C0024,m0032,t09,i46,e-0001,f6009,r99,b000,B0000000!YM7: using hmd/sensor/JuiceBox/Data-from-JuiceBox/state
juicepassproxy_tst    | 2024-05-15 09:42:17  INFO      [ha_mqtt_discoverable.sensors] Setting Voltage to 205.7 using hmd/sensor/JuiceBox/Voltage/state
juicepassproxy_tst    | 2024-05-15 09:42:17  INFO      [ha_mqtt_discoverable.sensors] Setting Energy (Lifetime) to 4117618.0 using hmd/sensor/JuiceBox/Energy--Lifetime-/state
juicepassproxy_tst    | 2024-05-15 09:42:17  INFO      [ha_mqtt_discoverable.sensors] Setting Status to Unplugged using hmd/sensor/JuiceBox/Status/state
juicepassproxy_tst    | 2024-05-15 09:42:17  INFO      [ha_mqtt_discoverable.sensors] Setting Temperature to 69.8 using hmd/sensor/JuiceBox/Temperature/state
juicepassproxy_tst    | 2024-05-15 09:42:17  INFO      [ha_mqtt_discoverable.sensors] Setting Current Rating to 32.0 using hmd/sensor/JuiceBox/Current-Rating/state
juicepassproxy_tst    | 2024-05-15 09:42:17  INFO      [ha_mqtt_discoverable.sensors] Setting Frequency to 60.09 using hmd/sensor/JuiceBox/Frequency/state
juicepassproxy_tst    | 2024-05-15 09:42:17  INFO      [ha_mqtt_discoverable.sensors] Setting Power to 0.0 using hmd/sensor/JuiceBox/Power/state
juicepassproxy_tst    | 2024-05-15 09:42:17  INFO      [ha_mqtt_discoverable.sensors] Setting Data from JuiceBox to X:v09u,s001,F10,u00064119,V2057,L00004117618,S00,T21,M0024,C0024,m0032,t09,i47,e-0001,f6009,r99,b000,B0000000!Z79: using hmd/sensor/JuiceBox/Data-from-JuiceBox/state


@Snuffy2
Copy link
Collaborator Author

Snuffy2 commented May 31, 2024

Will merge this PR into master.
It can be tested from the edge Docker tag until packaged into a release
For those previously testing with the async_beta Docker tag, please switch to edge

@Snuffy2
Copy link
Collaborator Author

Snuffy2 commented May 31, 2024

services:
  juicepassproxy:
    image: ghcr.io/snicker/juicepassproxy:edge

   [...]

@Snuffy2 Snuffy2 merged commit 44f7f0f into snicker:master May 31, 2024
@snicker
Copy link
Owner

snicker commented Jun 4, 2024

amazing work @Snuffy2, about to set up 0.3.0 locally!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option for different local port Transition from deprecated python telnetlib
3 participants