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

[automower] Add planner, calendar and command channels #8802

Merged
merged 3 commits into from
Mar 31, 2021

Conversation

marcinczeczko
Copy link
Contributor

I'd like to propose couple of improvements to the Automower binding:
- Added support for the planner and calendar data
- Added command channels
- Removed name channel
- Updated docs

Signed-off-by: Marcin Czeczko marcin.czeczko@gmail.com

@TravisBuddy
Copy link

Travis tests were successful

Hey @marcinczeczko,
we found no major flaws with your code. Still you might want to look at this logfile, as we usually suggest some optional improvements.

@fwolter
Copy link
Member

fwolter commented Oct 23, 2020

@maxpg Can you take a look?

@cpmeister cpmeister added the enhancement An enhancement or new feature for an existing add-on label Oct 24, 2020
@maxpg
Copy link

maxpg commented Nov 6, 2020

@fwolter Sorry for the delay, pretty busy currently. I try to have a look this weekend...

Copy link

@maxpg maxpg 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 your contribution. Definitely a major improvement to the binding. Also in the area of documentation.
Unfortunately I am not able to test the changes as my automower has already ended its season...

@@ -89,9 +110,24 @@ public AutomowerHandler(Thing thing) {

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (command instanceof RefreshType) {
Optional<AutomowerCommand> commandName = AutomowerCommand.fromChannelUID(channelUID);
Copy link

Choose a reason for hiding this comment

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

As you don't do anything with the AutomowerCommand in case the command is a refresh I would fetch the command in the else clause of the refresh check...

Copy link
Member

Choose a reason for hiding this comment

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

@marcinczeczko can you comment on this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, it's a good idea. Will fix that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Will update

new DateTimeType(ZonedDateTime.ofInstant(errorCodeTimestamp, ZoneId.systemDefault())));
long errorCodeTimestamp = mower.getAttributes().getMower().getErrorCodeTimestamp();
if (errorCodeTimestamp == 0L) {
updateState(CHANNEL_STATUS_ERROR_TIMESTAMP, UnDefType.NULL);
Copy link

Choose a reason for hiding this comment

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

Thanks for fixing the problem with the error timestamp :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem :)

| mower-status#planner-next-start | DateTime | R | The time for the next auto start. If the mower is charging then the value is the estimated time when it will be leaving the charging station. If the mower is about to start now, the value is NULL. |
| mower-status#planner-override-action | String | R | The action that overrides current planner operation. |
| mower-status#calendar-tasks | String | R | The JSON with the information about Automower planner. |
| mower#start | Number | W | Starts the automower for a duration |
Copy link

Choose a reason for hiding this comment

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

Cool, I like the new command channels. I tried to also do command channels in my initial contribution but they were rejected. But probably because of the way that I implemented them, they didn't fit well and were more like a workaround because I wanted to use actions.

Copy link
Member

@fwolter fwolter left a comment

Choose a reason for hiding this comment

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

There are some checkstyle warnings left. You could take a look at target/code-analysis/report.html.

@@ -89,9 +110,24 @@ public AutomowerHandler(Thing thing) {

@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (command instanceof RefreshType) {
Optional<AutomowerCommand> commandName = AutomowerCommand.fromChannelUID(channelUID);
Copy link
Member

Choose a reason for hiding this comment

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

@marcinczeczko can you comment on this?

Comment on lines 45 to 50
<channels>
<channel id="name" typeId="nameType"/>
<channel id="mode" typeId="modeType"/>
<channel id="activity" typeId="activityType"/>
<channel id="state" typeId="stateType"/>
<channel id="last-update" typeId="lastUpdateType"/>
<channel id="battery" typeId="batteryType"/>
<channel id="error-code" typeId="errorCodeType"/>
<channel id="error-timestamp" typeId="errorTimestampType"/>
</channels>
<channel-groups>
<channel-group id="mower-status" typeId="mowerStatus"/>
<channel-group id="mower" typeId="mowerCommands"/>
</channel-groups>
Copy link
Member

@fwolter fwolter Nov 19, 2020

Choose a reason for hiding this comment

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

The grouping of the Channels makes the binding incompatible with current configurations. That means existing users need to remove their mower Thing, re-add it and adjust their Items configuration. Although this breaking change is allowed during the OH 2.5.x -> 3.0.0 release, I think it would annoy users. Is this change really worth it?

Adding new Channels without touching existing ones is okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for that comment. I absolutely agree with that. Will update it accordingly

@fwolter fwolter added the awaiting feedback Awaiting feedback from the pull request author label Dec 6, 2020
@fwolter
Copy link
Member

fwolter commented Jan 13, 2021

@marcinczeczko What is the status of this PR?

@marcinczeczko
Copy link
Contributor Author

@fwolter - Sorry for not responding for long time. Lot of things were happening on my side that simple blocked myself from any contributions. But fortunately it's getting calm now and I plan to resurrect my PR

@marcinczeczko
Copy link
Contributor Author

I addressed all review comments in the latest commit.

@fwolter fwolter removed the awaiting feedback Awaiting feedback from the pull request author label Mar 2, 2021
Copy link
Member

@fwolter fwolter left a comment

Choose a reason for hiding this comment

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

You need to sign-off your commits. See https://www.openhab.org/docs/developer/contributing.html#sign-your-work The necessary commands are listed when you click on "Details" at the DCO check below.

Comment on lines 351 to 353
ZonedDateTime gmt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneOffset.UTC);
return ZonedDateTime.of(gmt.getYear(), gmt.getMonthValue(), gmt.getDayOfMonth(), gmt.getHour(), gmt.getMinute(),
gmt.getSecond(), gmt.getNano(), ZoneId.systemDefault());
Copy link
Member

Choose a reason for hiding this comment

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

The user can set an individual timezone in OH's settings. You can obtain it by injecting TimeZoneProvider.

Suggested change
ZonedDateTime gmt = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneOffset.UTC);
return ZonedDateTime.of(gmt.getYear(), gmt.getMonthValue(), gmt.getDayOfMonth(), gmt.getHour(), gmt.getMinute(),
gmt.getSecond(), gmt.getNano(), ZoneId.systemDefault());
LocalDateTime local = LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneOffset.UTC);
return ZonedDateTime.of(local, timeZoneProvider.getTimeZone());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed


<channel-type id="plannerOverrideActionType">
<item-type>String</item-type>
<label>The override action</label>
Copy link
Member

Choose a reason for hiding this comment

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

Words in labels should be capitalized (except prepositions and so on). See https://www.openhab.org/docs/developer/bindings/thing-xml.html#formatting-labels-and-descriptions

Suggested change
<label>The override action</label>
<label>Override Action</label>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed labels


<channel-type id="calendarTasksType">
<item-type>String</item-type>
<label>The information about the planner as JSON</label>
Copy link
Member

Choose a reason for hiding this comment

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

Labels are expected to be as short as possible. Guideline is 2-3 words with max 20-25 chars. See https://www.openhab.org/docs/developer/bindings/thing-xml.html#formatting-labels-and-descriptions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

	- Added support for the planner and calendar data
	- Added command channels
	- Updated docs

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>
@marcinczeczko
Copy link
Contributor Author

I pushed one more commit with the last changes.

groups. Improved the mower state update:
- Cache the last read state from API
- Use cached mower state so the items linked will always be up to date
  without the need to wait for API refresh period.
- Use timeZoneProvider to user user set timezone.

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>
Copy link
Member

@fwolter fwolter left a comment

Choose a reason for hiding this comment

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

You could re-request another review when you are finished making all changes. I will get notified, then.

*/
@NonNullByDefault
Copy link
Member

Choose a reason for hiding this comment

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

Did you remove this by intention?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I did it intentionally that time due to the new class field mowerState but apparently I forgot to clean it up. Already fixed it.

@marcinczeczko
Copy link
Contributor Author

You could re-request another review when you are finished making all changes. I will get notified, then.

Sorry I didn't know about re-request option :)

@marcinczeczko marcinczeczko requested a review from fwolter March 30, 2021 22:15
Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>
Copy link
Member

@fwolter fwolter left a comment

Choose a reason for hiding this comment

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

LGTM

@fwolter fwolter changed the title [Automower] Enhanced binding [automower] Add planner, calendar and command channels Mar 31, 2021
@fwolter fwolter merged commit 0eb48e6 into openhab:main Mar 31, 2021
@fwolter fwolter added this to the 3.1 milestone Mar 31, 2021
Daniel-42 pushed a commit to Daniel-42/openhab-addons that referenced this pull request Apr 6, 2021
* [Automower] Enhanced binding:
	- Added support for the planner and calendar data
	- Added command channels
	- Updated docs

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>

* [Automower] Fixed consts with channel ids after removal of channel
groups. Improved the mower state update:
- Cache the last read state from API
- Use cached mower state so the items linked will always be up to date
  without the need to wait for API refresh period.
- Use timeZoneProvider to user user set timezone.

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>

* Rolledback NotNullByDefault annotation

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>
themillhousegroup pushed a commit to themillhousegroup/openhab2-addons that referenced this pull request May 10, 2021
* [Automower] Enhanced binding:
	- Added support for the planner and calendar data
	- Added command channels
	- Updated docs

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>

* [Automower] Fixed consts with channel ids after removal of channel
groups. Improved the mower state update:
- Cache the last read state from API
- Use cached mower state so the items linked will always be up to date
  without the need to wait for API refresh period.
- Use timeZoneProvider to user user set timezone.

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>

* Rolledback NotNullByDefault annotation

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>
Signed-off-by: John Marshall <john.marshall.au@gmail.com>
computergeek1507 pushed a commit to computergeek1507/openhab-addons that referenced this pull request Jul 13, 2021
* [Automower] Enhanced binding:
	- Added support for the planner and calendar data
	- Added command channels
	- Updated docs

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>

* [Automower] Fixed consts with channel ids after removal of channel
groups. Improved the mower state update:
- Cache the last read state from API
- Use cached mower state so the items linked will always be up to date
  without the need to wait for API refresh period.
- Use timeZoneProvider to user user set timezone.

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>

* Rolledback NotNullByDefault annotation

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>
thinkingstone pushed a commit to thinkingstone/openhab-addons that referenced this pull request Nov 7, 2021
* [Automower] Enhanced binding:
	- Added support for the planner and calendar data
	- Added command channels
	- Updated docs

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>

* [Automower] Fixed consts with channel ids after removal of channel
groups. Improved the mower state update:
- Cache the last read state from API
- Use cached mower state so the items linked will always be up to date
  without the need to wait for API refresh period.
- Use timeZoneProvider to user user set timezone.

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>

* Rolledback NotNullByDefault annotation

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>
marcfischerboschio pushed a commit to bosch-io/openhab-addons that referenced this pull request May 5, 2022
* [Automower] Enhanced binding:
	- Added support for the planner and calendar data
	- Added command channels
	- Updated docs

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>

* [Automower] Fixed consts with channel ids after removal of channel
groups. Improved the mower state update:
- Cache the last read state from API
- Use cached mower state so the items linked will always be up to date
  without the need to wait for API refresh period.
- Use timeZoneProvider to user user set timezone.

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>

* Rolledback NotNullByDefault annotation

Signed-off-by: Marcin Czeczko <marcin.czeczko@gmail.com>
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/automower-missing-channels/122319/4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants