-
-
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
[miio] add miot protocol & conditions #7404
Conversation
* 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>
Travis tests were successfulHey @marcelrv, |
Travis tests were successfulHey @marcelrv, |
*/ | ||
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 |
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.
Is this a todo or a comment?
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.
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.
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.
You can leave this as is.
* @param condition | ||
* @param deviceVariables | ||
* @param value | ||
* @return value is case firmware is matching, return null if not |
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.
* @return value is case firmware is matching, return null if not | |
* @return value in case firmware is matching, return null if not |
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.
done
if (intVal > 0 && intVal < 99) { | ||
return value; | ||
} | ||
} catch (ClassCastException e) { |
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 check for this before trying to cast it rather than catching the exception?
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.
yes, didn't find it at first, but found a number check.
done
} | ||
} | ||
|
||
public void setPiid(Integer piid) { |
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.
If this is non-null by default why not make this a primitive?
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.
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
} | ||
updateProperties(properties); |
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.
Why not just do:
} | |
updateProperties(properties); | |
} | |
deviceVariables.putAll(properties); | |
updateProperties(properties); |
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.
Excellent suggestion...done
Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
Travis tests were successfulHey @marcelrv, |
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 |
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.
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()); |
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.
This calculation would look better using bit-shift operators instead of multiplication.
(color.getRed() * 65536) + (color.getGreen() * 256) + color.getBlue()); | |
(color.getRed() << 16) + (color.getGreen() << 8) + color.getBlue()); |
Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
Travis tests were successfulHey @marcelrv, |
Manually checked sign-off |
* [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>
* [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>
* [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>
* [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>
* [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>
* [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>
* [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>
* [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>
* [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>
* [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>
* [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: Marcel Verpaalen marcel@verpaalen.com