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

[miio] add miot protocol & conditions #7404

Merged
merged 4 commits into from
Apr 18, 2020
Merged

Conversation

marcelrv
Copy link
Contributor

@marcelrv marcelrv commented Apr 17, 2020

Signed-off-by: Marcel Verpaalen marcel@verpaalen.com

* Add miot protocol handling openhab#7276
* Add first 2 miot devices (airpurifiers mb3 & ma4)
* Add conditional commands
* Change brightness to dimmers openhab#4388
* Apply conditions for dimmers
* Remove obsolete (pre)parameters from actions


Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
@marcelrv marcelrv requested a review from cpmeister April 17, 2020 20:53
@marcelrv marcelrv linked an issue Apr 17, 2020 that may be closed by this pull request
@TravisBuddy
Copy link

Travis tests were successful

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

@marcelrv marcelrv added the enhancement An enhancement or new feature for an existing add-on label Apr 17, 2020
@TravisBuddy
Copy link

Travis tests were successful

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

*/
private static @Nullable JsonElement firmwareCheck(MiIoDeviceActionCondition condition,
Map<String, Object> deviceVariables, @Nullable JsonElement value) {
// TODO: placeholder for firmware version check to allow for firmware dependent actions
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a todo or a comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It indeed is a placeholder for now for something I want to implement in a further version.
It does require still bit of researching on the format of the various firmware version strings Xiaomi is using.

if it is disturbing I can remove the whole function until it is actually used.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can leave this as is.

* @param condition
* @param deviceVariables
* @param value
* @return value is case firmware is matching, return null if not
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
* @return value is case firmware is matching, return null if not
* @return value in case firmware is matching, return null if not

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

if (intVal > 0 && intVal < 99) {
return value;
}
} catch (ClassCastException e) {
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 check for this before trying to cast it rather than catching the exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, didn't find it at first, but found a number check.
done

}
}

public void setPiid(Integer piid) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is non-null by default why not make this a primitive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These siid & piid Integers are only used for miot protocol devices, I use it to determine if it is a miot device by comparing to null in the isMiot function.

in the further functions I don't want to do this checking anymore hence the conversion here to primitive

Comment on lines 379 to 380
}
updateProperties(properties);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just do:

Suggested change
}
updateProperties(properties);
}
deviceVariables.putAll(properties);
updateProperties(properties);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excellent suggestion...done

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
@TravisBuddy
Copy link

Travis tests were successful

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

@marcelrv
Copy link
Contributor Author

thanks @cpmeister made the suggested updates.

String param = para.get(i).getAsString();
// This is a miot parameter
String param;
if (para.get(i).isJsonObject()) { // miot channel
Copy link
Contributor

Choose a reason for hiding this comment

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

You should cache para.get(i) in a local variable for reuse.

Color color = Color.getHSBColor(hsb.getHue().floatValue() / 360,
hsb.getSaturation().floatValue() / 100, hsb.getBrightness().floatValue() / 100);
value = new JsonPrimitive(
(color.getRed() * 65536) + (color.getGreen() * 256) + color.getBlue());
Copy link
Contributor

Choose a reason for hiding this comment

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

This calculation would look better using bit-shift operators instead of multiplication.

Suggested change
(color.getRed() * 65536) + (color.getGreen() * 256) + color.getBlue());
(color.getRed() << 16) + (color.getGreen() << 8) + color.getBlue());

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
@TravisBuddy
Copy link

Travis tests were successful

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

@cpmeister
Copy link
Contributor

Manually checked sign-off

@cpmeister cpmeister merged commit 94b422e into openhab:2.5.x Apr 18, 2020
@cpmeister cpmeister added this to the 2.5.4 milestone Apr 18, 2020
@marcelrv marcelrv deleted the miio-miot branch April 18, 2020 18:46
yfre pushed a commit to yfre/openhab-addons that referenced this pull request Apr 27, 2020
* [miio] add miot protocol & conditions

* Add miot protocol handling openhab#7276
* Add first 2 miot devices (airpurifiers mb3 & ma4)
* Add conditional commands
* Change brightness to dimmers openhab#4388
* Apply conditions for dimmers
* Remove obsolete (pre)parameters from actions

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
Signed-off-by: Eugen Freiter <freiter@gmx.de>
markus7017 pushed a commit to markus7017/openhab-addons that referenced this pull request May 29, 2020
* [miio] add miot protocol & conditions

* Add miot protocol handling openhab#7276
* Add first 2 miot devices (airpurifiers mb3 & ma4)
* Add conditional commands
* Change brightness to dimmers openhab#4388
* Apply conditions for dimmers
* Remove obsolete (pre)parameters from actions

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
LoungeFlyZ pushed a commit to LoungeFlyZ/openhab2-addons that referenced this pull request Jun 8, 2020
* [miio] add miot protocol & conditions

* Add miot protocol handling openhab#7276
* Add first 2 miot devices (airpurifiers mb3 & ma4)
* Add conditional commands
* Change brightness to dimmers openhab#4388
* Apply conditions for dimmers
* Remove obsolete (pre)parameters from actions

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
J-N-K pushed a commit to J-N-K/openhab-addons that referenced this pull request Jul 14, 2020
* [miio] add miot protocol & conditions

* Add miot protocol handling openhab#7276
* Add first 2 miot devices (airpurifiers mb3 & ma4)
* Add conditional commands
* Change brightness to dimmers openhab#4388
* Apply conditions for dimmers
* Remove obsolete (pre)parameters from actions

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
CSchlipp pushed a commit to CSchlipp/openhab-addons that referenced this pull request Jul 26, 2020
* [miio] add miot protocol & conditions

* Add miot protocol handling openhab#7276
* Add first 2 miot devices (airpurifiers mb3 & ma4)
* Add conditional commands
* Change brightness to dimmers openhab#4388
* Apply conditions for dimmers
* Remove obsolete (pre)parameters from actions

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
Signed-off-by: CSchlipp <christian@schlipp.de>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* [miio] add miot protocol & conditions

* Add miot protocol handling openhab#7276
* Add first 2 miot devices (airpurifiers mb3 & ma4)
* Add conditional commands
* Change brightness to dimmers openhab#4388
* Apply conditions for dimmers
* Remove obsolete (pre)parameters from actions

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* [miio] add miot protocol & conditions

* Add miot protocol handling openhab#7276
* Add first 2 miot devices (airpurifiers mb3 & ma4)
* Add conditional commands
* Change brightness to dimmers openhab#4388
* Apply conditions for dimmers
* Remove obsolete (pre)parameters from actions

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* [miio] add miot protocol & conditions

* Add miot protocol handling openhab#7276
* Add first 2 miot devices (airpurifiers mb3 & ma4)
* Add conditional commands
* Change brightness to dimmers openhab#4388
* Apply conditions for dimmers
* Remove obsolete (pre)parameters from actions

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
andrewfg pushed a commit to andrewfg/openhab-addons that referenced this pull request Aug 31, 2020
* [miio] add miot protocol & conditions

* Add miot protocol handling openhab#7276
* Add first 2 miot devices (airpurifiers mb3 & ma4)
* Add conditional commands
* Change brightness to dimmers openhab#4388
* Apply conditions for dimmers
* Remove obsolete (pre)parameters from actions

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
DaanMeijer pushed a commit to DaanMeijer/openhab-addons that referenced this pull request Sep 1, 2020
* [miio] add miot protocol & conditions

* Add miot protocol handling openhab#7276
* Add first 2 miot devices (airpurifiers mb3 & ma4)
* Add conditional commands
* Change brightness to dimmers openhab#4388
* Apply conditions for dimmers
* Remove obsolete (pre)parameters from actions

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
Signed-off-by: Daan Meijer <daan@studioseptember.nl>
markus7017 pushed a commit to markus7017/openhab-addons that referenced this pull request Sep 19, 2020
* [miio] add miot protocol & conditions

* Add miot protocol handling openhab#7276
* Add first 2 miot devices (airpurifiers mb3 & ma4)
* Add conditional commands
* Change brightness to dimmers openhab#4388
* Apply conditions for dimmers
* Remove obsolete (pre)parameters from actions

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
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.

[miio] Brightness Channel as Dimmer
3 participants