Class WattpilotClient

java.lang.Object
dev.digiried.wattpilot.WattpilotClient

@NonNullByDefault public class WattpilotClient extends Object
Client for the Fronius Wattpilot wallbox.
Author:
Florian Hotze - Initial contribution
  • Constructor Details

    • WattpilotClient

      public WattpilotClient(org.eclipse.jetty.client.HttpClient httpClient)
      Create a new Fronius Wattpilot client using the given HttpClient.
      Parameters:
      httpClient - the HTTP client to use, allows configuring HTTP settings
    • WattpilotClient

      public WattpilotClient(org.eclipse.jetty.client.HttpClient httpClient, int pingInterval, int pingTimeout)
      Creates a new Fronius Wattpilot client using the given HttpClient and the provided ping interval and timeout.
      Parameters:
      httpClient - the HTTP client to use, allows configuring HTTP settings
      pingInterval - the ping interval
      pingTimeout - the ping timeout; must be less than pingInterval
  • Method Details

    • addListener

      public void addListener(WattpilotClientListener listener)
      Adds a WattpilotClientListener to the client.
      Parameters:
      listener - the listener to add
    • removeListener

      public void removeListener(WattpilotClientListener listener)
      Removes a WattpilotClientListener from the client.
      Parameters:
      listener - the listener to remove
    • connect

      public CompletableFuture<@Nullable Void> connect(String host, String password) throws IOException
      Connect the client to the wallbox.

      Connection is established asynchronously. Either use the returned CompletableFuture or implement WattpilotClientListener.connected() and WattpilotClientListener.disconnected(java.lang.String, java.lang.Throwable) to get notified about connection establishment or failure.

      Parameters:
      host - the hostname or IP address of the wallbox
      password - the password to authenticate with
      Returns:
      future that completes once the client has successfully connected
      Throws:
      IOException - if the synchronous preparations for the connection establishment fail
    • disconnect

      public CompletableFuture<@Nullable Void> disconnect()
      Disconnect the client from the wallbox.

      This operation is idempotent, meaning it can be called multiple times without side effects.

      Returns:
      future that completes once the client has successfully disconnected
    • isConnected

      public boolean isConnected()
      Whether the client is connected to the wallbox.
      Returns:
      true if connected
    • getDeviceInfo

      public @Nullable WattpilotInfo getDeviceInfo()
      Get the WattpilotInfo of the wallbox.
      Returns:
      the device info or null if not available yet
    • getStatus

      public @Nullable WattpilotStatus getStatus()
      Get the current status of the wallbox.
      Returns:
      the current status or null if not available yet
    • sendCommand

      public CompletableFuture<CommandResponse> sendCommand(Command command)
      Send a Command to the wallbox and return a CompletableFuture that will be completed when the response is received.
      Parameters:
      command - the command to send
      Returns:
      a CompletableFuture that will be completed when the response is received, or completed exceptionally with an IOException if the command could not be sent