Light API client on java, when there are no python libraries for integrations

It will be nice, if it will be native API on java, because sometimes there is no python library for integration, but there is only java library. This layer can communicate with HA by WebSocket, and if community have java lib, it should be easy to connect with HA. For example, here no python integration Devi Smart but there is java integration. It will be easy for developer not to think about authorization, about support stable websocket connection and auto reconnect, about finding API methods in documentation, it will be nice to use javadocs in code, and just select methods.

I started writing WebSocket API client in Kotlin, which is compatible with Java

I wrote a Java lib to use for one of my own projects when I needed to communicate with home assistant using websockets. It includes types for most stuff, but there might be need to add some fields to the attribute class (and maybe others as well) since it’s dependent on what your specific HA instance has installed.
Feel free to try it out and don’t hesitate to give me a shout if something doesn’t work! :slight_smile:

Just realized that nick2525:s project is a copy of mine (just less updated) and converted to Kotlin.
If you don’t believe me then look at the source history :grin:
Anyway, imitation is the greatest form of flattery! :blush:

1 Like

@APayerl yes, first I try to fork it, but i have to change everything to be on Kotlin, so I will link your project, when I will create readme and will be on will not be some users. Also, it did’t work for me, so I changed @param:JsonProperty(“result”) val result: Result
@param:JsonProperty(“result”) val result: List Also, I try to fork and another repo on Java rewrite to Kotlin, and support fork, it is very hard. I have a different philosophy on the obligatory fields, sorting of fields. Projects will diverge greatly in the future, but as soon as there is a readme - I will link to your project.

Hehe alright! Just wanted to inform if someone else came here and read. Just so you know, I use my project in a Kotlin app, so it’s usable as is in Kotlin :wink:. But if you have another idea how you want to make the project going forward then have fun! :slight_smile:

Edit: The issue you mentioned has been changed a couple of days ago in my rep too! :wink:

1 Like

@APayerl I added link to your project and created README

1 Like

It seems there are too many parameters for API, perhaps you need to somehow separate the attributes by integrations for example, I have already 126 lines

The way I have solved this issue is to have getters for the properties I’m primarily interested in and then I have a get function where you specify the property you want.

Hello people.
Is there any progress on this project?

I try to keep my project (GitHub - APayerl/HomeAssistantWS: Java library to ease use of the Home Assistant WebSocket API.) updated mainly when I relize something is"off"… I use it for a android app project at home. I welcome issue requests and/or pull requests! :blush:

Unfortunately, I stopped the project, because I realized that HA is not strongly typed, has poor standardization, and is not suitable for the API at all. Even within the official components, the fields are named differently, so the API will take millions of lines of code and constantly break

@nick2525 - do you have any examples for HA having inconsistency with respect to APIs.

I have been trying both WebThings(previously part of Mozilla) and HomeAssistant for my home project. My main purpose to try these are for their APIs (which I use inside my own project mainly for zigbee devices).

When comparing HA and WebThings for API. The websocket API for WebThings is very straight forward and simple to use (pass auth in header etc). However, WebThings doesn’t seem to have much active development (last release 1.0 was in 2020).

I tried @APayerl’s library, which is pretty cool and makes life easy. However, was curious to know if you experienced things breaking very frequently because of HA changing their API standards?

I have not noticed anything so far but my project I use my api wrapper for is on a break at the moment so I can’t say anything definite!

You may look at API client code. Pay particular attention to the almost infinite nesting of one object within another.

Tried your library with the latest release of HA and everything seems to be working fine. Mainly was interested in fetching the current, previous state of zigbee devices.

got it. I’m guessing they keep adding additional device details in the json response.