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

[casokitchen] Initial contribution #18243

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

weymann
Copy link
Contributor

@weymann weymann commented Feb 9, 2025

Binding to connect CASO Smart Kitchen devices.

Currently wine coolers are supported, development team told me more devices will follow.
Topic was discussed in forum and binding is present on Marketplace.

Signed-off-by: Bernd Weymann <[email protected]>
Signed-off-by: Bernd Weymann <[email protected]>
Signed-off-by: Bernd Weymann <[email protected]>
Signed-off-by: Bernd Weymann <[email protected]>
Signed-off-by: Bernd Weymann <[email protected]>
Signed-off-by: Bernd Weymann <[email protected]>
Signed-off-by: Bernd Weymann <[email protected]>
Signed-off-by: Bernd Weymann <[email protected]>
Signed-off-by: Bernd Weymann <[email protected]>
Signed-off-by: Bernd Weymann <[email protected]>
Signed-off-by: Bernd Weymann <[email protected]>
Signed-off-by: Bernd Weymann <[email protected]>
Signed-off-by: Bernd Weymann <[email protected]>
Signed-off-by: Bernd Weymann <[email protected]>
@weymann weymann requested a review from a team as a code owner February 9, 2025 17:30
@jlaur jlaur added the new binding If someone has started to work on a binding. For a new binding PR. label Feb 10, 2025
@lsiepel

This comment was marked as outdated.

Copy link
Contributor

@lsiepel lsiepel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution. Looked at all the files and left some comments. Let me know when you are ready.

@Activate
public CasoKitchenHandlerFactory(final @Reference HttpClientFactory httpClientFactory,
final @Reference TimeZoneProvider tzp) {
httpClient = httpClientFactory.getCommonHttpClient();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please store the factory and create a httpclient for each time a thing handler is created.

Comment on lines +16 to +17
<label>Desired Temperature</label>
<description>Desired Zone Temperature</description>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not wrong, but a more common convention is to use Target vs Desired.

}
}

private boolean checkConfig() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Within the flow it works as expected, but io would like to ask you to refactor this. The method is not only checking the config (as it's name suggests), it is also setting the Thing state.

  1. Maybe return the reason and set the thing state in the initialize method
  2. Another fix could be to change the method name.
  3. On top of the above i would propose to change the logich a bit:
  • make use of isBlank() instead of != EMPTY
  • prevend nested if's. : check condition and exit /return immediate.

if (responseStatus == 200) {
updateState(new ChannelUID(thing.getUID(), group, LIGHT), OnOffType.from(lr.lightOn));
} else {
logger.info("Call to {} responded with status {} reason {}", LIGHT_URL, response.getStatus(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.info("Call to {} responded with status {} reason {}", LIGHT_URL, response.getStatus(),
logger.warn("Call to {} responded with status {} reason {}", LIGHT_URL, response.getStatus(),

Comment on lines +179 to +185
Request req = httpClient.POST(LIGHT_URL);
req.header(HttpHeader.CONTENT_TYPE, "application/json");
req.header(HTTP_HEADER_API_KEY, configuration.apiKey);
req.content(new StringContentProvider(GSON.toJson(lr)));
try {
ContentResponse response = req.timeout(60, TimeUnit.SECONDS).send();
int responseStatus = response.getStatus();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice if you can extract the http request/response handling outside of this method. and make it somewhat generic for future use.

Comment on lines +209 to +217
StatusRequest requestContent = new StatusRequest(configuration.deviceId);
Request req = httpClient.POST(STATUS_URL);
req.header(HttpHeader.CONTENT_TYPE, "application/json");
req.header(HTTP_HEADER_API_KEY, configuration.apiKey);
req.content(new StringContentProvider(GSON.toJson(requestContent)));
try {
ContentResponse contentResponse = req.timeout(60, TimeUnit.SECONDS).send();
int responseStatus = contentResponse.getStatus();
String contentResult = contentResponse.getContentAsString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See other comment about extracting request/response. Maybe extracting it to an additionl class is a biut too much, but atleast extract it to another method.

</channel-type>
<channel-type id="hint">
<item-type>String</item-type>
<label> Hint</label>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<label> Hint</label>
<label>Hint</label>

<channel-type id="hint">
<item-type>String</item-type>
<label> Hint</label>
<description> Textual hint for device status</description>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<description> Textual hint for device status</description>
<description>Textual hint for device status</description>

Instant startWaiting = Instant.now();
while (states.size() < stateCount && startWaiting.plus(5, ChronoUnit.SECONDS).isAfter(Instant.now())) {
try {
wait(250);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you share some insights to why there a hardcoded wait?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new binding If someone has started to work on a binding. For a new binding PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants