[miio] improve zhimi fan channels (#10882)

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
This commit is contained in:
Marcel
2021-06-20 20:58:05 +02:00
committed by GitHub
parent f73553347e
commit 6a7e240060
5 changed files with 360 additions and 158 deletions

View File

@@ -52,6 +52,7 @@ public enum MiIoQuantiyTypes {
LITRE(Units.LITRE, "liter"),
LUX(Units.LUX),
RADIANS(Units.RADIAN, "radians"),
DEGREE(Units.DEGREE_ANGLE, "degree"),
KILOWATT_HOUR(Units.KILOWATT_HOUR, "kwh", "kWH"),
SQUARE_METRE(SIUnits.SQUARE_METRE, "square_meter", "squaremeter"),
PERCENT(Units.PERCENT, "percentage"),

View File

@@ -12,8 +12,6 @@
*/
package org.openhab.binding.miio.internal.basic;
import java.util.concurrent.TimeUnit;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,12 +28,13 @@ import com.google.gson.JsonPrimitive;
public class Conversions {
private static final Logger LOGGER = LoggerFactory.getLogger(Conversions.class);
public static JsonElement secondsToHours(JsonElement seconds) {
long hours = TimeUnit.SECONDS.toHours(seconds.getAsInt());
return new JsonPrimitive(hours);
public static JsonElement secondsToHours(JsonElement seconds) throws ClassCastException {
double value = seconds.getAsDouble() / 3600;
return new JsonPrimitive(value);
}
public static JsonElement yeelightSceneConversion(JsonElement intValue) {
public static JsonElement yeelightSceneConversion(JsonElement intValue)
throws ClassCastException, IllegalStateException {
switch (intValue.getAsInt()) {
case 1:
return new JsonPrimitive("color");
@@ -54,17 +53,17 @@ public class Conversions {
}
}
public static JsonElement divideTen(JsonElement value10) {
public static JsonElement divideTen(JsonElement value10) throws ClassCastException, IllegalStateException {
double value = value10.getAsDouble() / 10.0;
return new JsonPrimitive(value);
}
public static JsonElement divideHundred(JsonElement value10) {
public static JsonElement divideHundred(JsonElement value10) throws ClassCastException, IllegalStateException {
double value = value10.getAsDouble() / 100.0;
return new JsonPrimitive(value);
}
public static JsonElement tankLevel(JsonElement value12) {
public static JsonElement tankLevel(JsonElement value12) throws ClassCastException, IllegalStateException {
// 127 without water tank. 120 = 100% water
if (value12.getAsInt() == 127) {
return new JsonPrimitive(-1);
@@ -75,20 +74,25 @@ public class Conversions {
}
public static JsonElement execute(String transfortmation, JsonElement value) {
switch (transfortmation.toUpperCase()) {
case "YEELIGHTSCENEID":
return yeelightSceneConversion(value);
case "SECONDSTOHOURS":
return secondsToHours(value);
case "/10":
return divideTen(value);
case "/100":
return divideHundred(value);
case "TANKLEVEL":
return tankLevel(value);
default:
LOGGER.debug("Transformation {} not found. Returning '{}'", transfortmation, value.toString());
return value;
try {
switch (transfortmation.toUpperCase()) {
case "YEELIGHTSCENEID":
return yeelightSceneConversion(value);
case "SECONDSTOHOURS":
return secondsToHours(value);
case "/10":
return divideTen(value);
case "/100":
return divideHundred(value);
case "TANKLEVEL":
return tankLevel(value);
default:
LOGGER.debug("Transformation {} not found. Returning '{}'", transfortmation, value.toString());
return value;
}
} catch (ClassCastException | IllegalStateException e) {
LOGGER.debug("Transformation {} failed. Returning '{}'", transfortmation, value.toString());
return value;
}
}
}

View File

@@ -9,7 +9,6 @@
"property": "power",
"friendlyName": "Power",
"channel": "power",
"channelType": "power",
"type": "Switch",
"refresh": true,
"actions": [
@@ -27,7 +26,6 @@
"property": "angle_enable",
"friendlyName": "Rotation",
"channel": "angleEnable",
"channelType": "angleEnable",
"type": "Switch",
"refresh": true,
"actions": [
@@ -35,64 +33,101 @@
"command": "set_angle_enable",
"parameterType": "ONOFF"
}
],
"category": "switch",
"tags": [
"Switch"
]
},
{
"property": "use_time",
"friendlyName": "Run Time",
"channel": "usedhours",
"channelType": "usedhours",
"type": "Number:Time",
"unit": "hours",
"refresh": true,
"transformation": "SecondsToHours",
"ChannelGroup": "Status",
"actions": [],
"category": "time"
"category": "time",
"tags": [
"Measurement",
"Duration"
]
},
{
"property": "angle",
"friendlyName": "Angle",
"channel": "angle",
"channelType": "angle",
"type": "Number",
"type": "Number:Angle",
"unit": "degree",
"stateDescription": {
"options": [
{
"value": "30",
"label": "30"
},
{
"value": "60",
"label": "60"
},
{
"value": "90",
"label": "90"
},
{
"value": "120",
"label": "120"
}
]
},
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_angle",
"parameterType": "NUMBER"
}
]
],
"category": "incline",
"tags": [
"Setpoint"
],
"readmeComment": "Value mapping `[\"30\"\u003d\"30\",\"60\"\u003d\"60\",\"90\"\u003d\"90\",\"120\"\u003d\"120\"]`"
},
{
"property": "poweroff_time",
"friendlyName": "Timer",
"friendlyName": "Power-Off Timer",
"channel": "poweroffTime",
"channelType": "poweroffTime",
"type": "Number",
"type": "Number:Time",
"unit": "hours",
"refresh": true,
"ChannelGroup": "actions",
"transformation": "SecondsToHours",
"actions": [
{
"command": "set_poweroff_time",
"parameterType": "NUMBER"
}
],
"category": "time",
"tags": [
"Setpoint",
"Duration"
]
},
{
"property": "buzzer",
"friendlyName": "Buzzer",
"channel": "buzzer",
"channelType": "buzzer",
"type": "Switch",
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_buzzer",
"parameterType": "ONOFF"
}
],
"category": "soundvolume",
"tags": [
"Switch"
]
},
{
@@ -100,14 +135,34 @@
"friendlyName": "LED",
"channel": "led_b",
"type": "Number",
"stateDescription": {
"options": [
{
"value": "0",
"label": "Bright"
},
{
"value": "1",
"label": "Dimmed"
},
{
"value": "2",
"label": "Off"
}
]
},
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_led_b",
"parameterType": "NUMBER"
}
]
],
"category": "light",
"tags": [
"Control"
],
"readmeComment": "Value mapping `[\"0\"\u003d\"Bright\",\"1\"\u003d\"Dimmed\",\"2\"\u003d\"Off\"]`"
},
{
"property": "child_lock",
@@ -115,83 +170,130 @@
"channel": "child_lock",
"type": "Switch",
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_child_lock",
"parameterType": "ONOFF"
}
],
"category": "lock",
"tags": [
"Control"
]
},
{
"property": "speed_level",
"friendlyName": "Speed Level",
"channel": "speedLevel",
"channelType": "speedLevel",
"type": "Number",
"type": "Dimmer",
"stateDescription": {
"minimum": 1,
"maximum": 100,
"step": 1,
"pattern": "%.0f %%"
},
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_speed_level",
"parameterType": "NUMBER"
}
],
"category": "fan",
"tags": [
"Setpoint",
"Level"
]
},
{
"property": "speed",
"friendlyName": "Speed",
"channel": "speed",
"channelType": "speed",
"type": "Number",
"stateDescription": {
"pattern": "%.0f RPM",
"readOnly": true
},
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_speed",
"parameterType": "NUMBER"
}
"actions": [],
"category": "fan",
"tags": [
"Measurement",
"Level"
]
},
{
"property": "natural_level",
"friendlyName": "Natural Level",
"channel": "naturalLevel",
"channelType": "naturalLevel",
"type": "Number",
"type": "Dimmer",
"stateDescription": {
"minimum": 1,
"maximum": 100,
"step": 1,
"pattern": "%.0f %%"
},
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_natural_level",
"parameterType": "NUMBER"
}
],
"category": "flow",
"tags": [
"Setpoint",
"Level"
]
},
{
"property": "ac_power",
"friendlyName": "AC Power",
"channel": "acPower",
"channelType": "acPower",
"type": "Switch",
"stateDescription": {
"readOnly": true
},
"refresh": true,
"ChannelGroup": "Status",
"actions": []
"actions": [],
"category": "poweroutlet_eu",
"tags": [
"Switch"
]
},
{
"property": "",
"friendlyName": "Move Direction",
"channel": "move",
"channelType": "move",
"type": "String",
"stateDescription": {
"options": [
{
"value": "",
"label": "None"
},
{
"value": "left",
"label": "Left"
},
{
"value": "right",
"label": "Right"
}
]
},
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_move",
"parameterType": "STRING"
}
]
],
"category": "movecontrol",
"tags": [
"Control"
],
"readmeComment": "Value mapping `[\"\"\u003d\"None\",\"left\"\u003d\"Left\",\"right\"\u003d\"Right\"]`"
}
]
}

View File

@@ -10,7 +10,6 @@
"property": "power",
"friendlyName": "Power",
"channel": "power",
"channelType": "power",
"type": "Switch",
"refresh": true,
"actions": [
@@ -28,7 +27,6 @@
"property": "angle_enable",
"friendlyName": "Rotation",
"channel": "angleEnable",
"channelType": "angleEnable",
"type": "Switch",
"refresh": true,
"actions": [
@@ -36,64 +34,101 @@
"command": "set_angle_enable",
"parameterType": "ONOFF"
}
],
"category": "switch",
"tags": [
"Switch"
]
},
{
"property": "use_time",
"friendlyName": "Run Time",
"channel": "usedhours",
"channelType": "usedhours",
"type": "Number:Time",
"unit": "hours",
"refresh": true,
"transformation": "SecondsToHours",
"ChannelGroup": "Status",
"actions": [],
"category": "time"
"category": "time",
"tags": [
"Measurement",
"Duration"
]
},
{
"property": "angle",
"friendlyName": "Angle",
"channel": "angle",
"channelType": "angle",
"type": "Number",
"type": "Number:Angle",
"unit": "degree",
"stateDescription": {
"options": [
{
"value": "30",
"label": "30"
},
{
"value": "60",
"label": "60"
},
{
"value": "90",
"label": "90"
},
{
"value": "120",
"label": "120"
}
]
},
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_angle",
"parameterType": "NUMBER"
}
]
],
"category": "incline",
"tags": [
"Setpoint"
],
"readmeComment": "Value mapping `[\"30\"\u003d\"30\",\"60\"\u003d\"60\",\"90\"\u003d\"90\",\"120\"\u003d\"120\"]`"
},
{
"property": "poweroff_time",
"friendlyName": "Timer",
"friendlyName": "Power-Off Timer",
"channel": "poweroffTime",
"channelType": "poweroffTime",
"type": "Number",
"type": "Number:Time",
"unit": "hours",
"refresh": true,
"ChannelGroup": "actions",
"transformation": "SecondsToHours",
"actions": [
{
"command": "set_poweroff_time",
"parameterType": "NUMBER"
}
],
"category": "time",
"tags": [
"Setpoint",
"Duration"
]
},
{
"property": "buzzer",
"friendlyName": "Buzzer",
"channel": "buzzer",
"channelType": "buzzer",
"type": "Switch",
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_buzzer",
"parameterType": "ONOFF"
}
],
"category": "soundvolume",
"tags": [
"Switch"
]
},
{
@@ -101,14 +136,34 @@
"friendlyName": "LED",
"channel": "led_b",
"type": "Number",
"stateDescription": {
"options": [
{
"value": "0",
"label": "Bright"
},
{
"value": "1",
"label": "Dimmed"
},
{
"value": "2",
"label": "Off"
}
]
},
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_led_b",
"parameterType": "NUMBER"
}
]
],
"category": "light",
"tags": [
"Control"
],
"readmeComment": "Value mapping `[\"0\"\u003d\"Bright\",\"1\"\u003d\"Dimmed\",\"2\"\u003d\"Off\"]`"
},
{
"property": "child_lock",
@@ -116,52 +171,70 @@
"channel": "child_lock",
"type": "Switch",
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_child_lock",
"parameterType": "ONOFF"
}
],
"category": "lock",
"tags": [
"Control"
]
},
{
"property": "speed_level",
"friendlyName": "Speed Level",
"channel": "speedLevel",
"channelType": "speedLevel",
"type": "Number",
"type": "Dimmer",
"stateDescription": {
"minimum": 1,
"maximum": 100,
"step": 1,
"pattern": "%.0f %%"
},
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_speed_level",
"parameterType": "NUMBER"
}
],
"category": "fan",
"tags": [
"Setpoint",
"Level"
]
},
{
"property": "speed",
"friendlyName": "Speed",
"channel": "speed",
"channelType": "speed",
"type": "Number",
"stateDescription": {
"pattern": "%.0f RPM",
"readOnly": true
},
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_speed",
"parameterType": "NUMBER"
}
"actions": [],
"category": "fan",
"tags": [
"Measurement",
"Level"
]
},
{
"property": "natural_level",
"friendlyName": "Natural Level",
"channel": "naturalLevel",
"channelType": "naturalLevel",
"type": "Number",
"type": "Dimmer",
"stateDescription": {
"minimum": 1,
"maximum": 100,
"step": 1,
"pattern": "%.0f %%"
},
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_natural_level",
@@ -204,21 +277,25 @@
"property": "ac_power",
"friendlyName": "AC Power",
"channel": "acPower",
"channelType": "acPower",
"type": "String",
"type": "Switch",
"stateDescription": {
"readOnly": true
},
"refresh": true,
"ChannelGroup": "Status",
"actions": []
"actions": [],
"category": "poweroutlet_eu",
"tags": [
"Switch"
]
},
{
"property": "bat_charge",
"friendlyName": "Battery Charge",
"channel": "mode",
"channelType": "mode",
"type": "String",
"refresh": true,
"ChannelGroup": "actions",
"actions": []
"actions": [],
"category": "batterylevel"
},
{
"property": "battery",
@@ -227,23 +304,41 @@
"channelType": "system:battery-level",
"type": "Number",
"refresh": true,
"ChannelGroup": "Status",
"actions": []
},
{
"property": "",
"friendlyName": "Move Direction",
"channel": "move",
"channelType": "move",
"type": "String",
"stateDescription": {
"options": [
{
"value": "",
"label": "None"
},
{
"value": "left",
"label": "Left"
},
{
"value": "right",
"label": "Right"
}
]
},
"refresh": true,
"ChannelGroup": "actions",
"actions": [
{
"command": "set_move",
"parameterType": "STRING"
}
]
],
"category": "movecontrol",
"tags": [
"Control"
],
"readmeComment": "Value mapping `[\"\"\u003d\"None\",\"left\"\u003d\"Left\",\"right\"\u003d\"Right\"]`"
}
]
}