-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
base: main
Are you sure you want to change the base?
Conversation
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]>
Signed-off-by: Bernd Weymann <[email protected]>
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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.
<label>Desired Temperature</label> | ||
<description>Desired Zone Temperature</description> |
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
- Maybe return the reason and set the thing state in the initialize method
- Another fix could be to change the method name.
- 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(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger.info("Call to {} responded with status {} reason {}", LIGHT_URL, response.getStatus(), | |
logger.warn("Call to {} responded with status {} reason {}", LIGHT_URL, response.getStatus(), |
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(); |
There was a problem hiding this comment.
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.
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(); |
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<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); |
There was a problem hiding this comment.
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?
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.