use of org.openhab.core.types.RefreshType in project openhab-addons by openhab.
the class DaikinMadokaHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
logger.debug("[{}] Channel: {}, Command: {}", super.thing.getUID().getId(), channelUID, command);
if (command instanceof RefreshType) {
// The binding will notify updates on channels
return;
}
switch(channelUID.getId()) {
case DaikinMadokaBindingConstants.CHANNEL_ID_CLEAN_FILTER_INDICATOR:
OnOffType cleanFilterOrder = (OnOffType) command;
if (cleanFilterOrder == OnOffType.OFF) {
resetCleanFilterIndicator();
}
break;
case DaikinMadokaBindingConstants.CHANNEL_ID_SETPOINT:
try {
QuantityType<Temperature> setpoint = (QuantityType<Temperature>) command;
submitCommand(new SetSetpointCommand(setpoint, setpoint));
} catch (Exception e) {
logger.warn("Data received is not a valid temperature.", e);
}
break;
case DaikinMadokaBindingConstants.CHANNEL_ID_EYE_BRIGHTNESS:
try {
logger.debug("Set eye brightness with value {}, {}", command.getClass().getName(), command);
PercentType p = (PercentType) command;
submitCommand(new SetEyeBrightnessCommand(p));
} catch (Exception e) {
logger.warn("Data received is not a valid Eye Brightness status", e);
}
break;
case DaikinMadokaBindingConstants.CHANNEL_ID_ONOFF_STATUS:
try {
OnOffType oot = (OnOffType) command;
submitCommand(new SetPowerstateCommand(oot));
} catch (Exception e) {
logger.warn("Data received is not a valid on/off status", e);
}
break;
case DaikinMadokaBindingConstants.CHANNEL_ID_FAN_SPEED:
try {
DecimalType fanSpeed = (DecimalType) command;
FanSpeed fs = FanSpeed.valueOf(fanSpeed.intValue());
submitCommand(new SetFanspeedCommand(fs, fs));
} catch (Exception e) {
logger.warn("Data received is not a valid FanSpeed status", e);
}
break;
case DaikinMadokaBindingConstants.CHANNEL_ID_OPERATION_MODE:
try {
StringType operationMode = (StringType) command;
OperationMode m = OperationMode.valueOf(operationMode.toFullString());
submitCommand(new SetOperationmodeCommand(m));
} catch (Exception e) {
logger.warn("Data received is not a valid OPERATION MODE", e);
}
break;
case DaikinMadokaBindingConstants.CHANNEL_ID_HOMEBRIDGE_MODE:
try {
// Homebridge are discrete value different from Daikin
// 0 - Off
// 1 - Heating
// 2 - Cooling
// 3 - Auto
DecimalType homebridgeMode = (DecimalType) command;
switch(homebridgeMode.intValue()) {
case // Off
0:
submitCommand(new SetPowerstateCommand(OnOffType.OFF));
break;
case // Heating
1:
submitCommand(new SetOperationmodeCommand(OperationMode.HEAT));
if (madokaSettings.getOnOffState() == OnOffType.OFF) {
submitCommand(new SetPowerstateCommand(OnOffType.ON));
}
break;
case // Cooling
2:
submitCommand(new SetOperationmodeCommand(OperationMode.COOL));
if (madokaSettings.getOnOffState() == OnOffType.OFF) {
submitCommand(new SetPowerstateCommand(OnOffType.ON));
}
break;
case // Auto
3:
submitCommand(new SetOperationmodeCommand(OperationMode.AUTO));
if (madokaSettings.getOnOffState() == OnOffType.OFF) {
submitCommand(new SetPowerstateCommand(OnOffType.ON));
}
break;
default:
// Invalid Value - in case of new FW
logger.warn("Invalid value received for channel {}. Ignoring.", channelUID);
break;
}
} catch (Exception e) {
logger.warn("Data received is not a valid HOMEBRIDGE OPERATION MODE", e);
}
break;
case DaikinMadokaBindingConstants.CHANNEL_ID_HOMEKIT_TARGET_HEATING_COOLING_MODE:
try {
StringType homekitOperationMode = (StringType) command;
switch(homekitOperationMode.toString()) {
case "Off":
submitCommand(new SetPowerstateCommand(OnOffType.OFF));
break;
case "CoolOn":
submitCommand(new SetOperationmodeCommand(OperationMode.COOL));
if (madokaSettings.getOnOffState() == OnOffType.OFF) {
submitCommand(new SetPowerstateCommand(OnOffType.ON));
}
break;
case "HeatOn":
submitCommand(new SetOperationmodeCommand(OperationMode.HEAT));
if (madokaSettings.getOnOffState() == OnOffType.OFF) {
submitCommand(new SetPowerstateCommand(OnOffType.ON));
}
break;
case "Auto":
submitCommand(new SetOperationmodeCommand(OperationMode.AUTO));
if (madokaSettings.getOnOffState() == OnOffType.OFF) {
submitCommand(new SetPowerstateCommand(OnOffType.ON));
}
break;
default:
break;
}
} catch (Exception e) {
logger.info("Error while setting mode through HomeKIt received Mode");
}
default:
break;
}
}
use of org.openhab.core.types.RefreshType in project openhab-addons by openhab.
the class DaliRgbHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
try {
if (CHANNEL_COLOR.equals(channelUID.getId())) {
boolean queryDeviceState = false;
if (command instanceof HSBType) {
PercentType[] rgb = ((HSBType) command).toRGB();
for (int i = 0; i < 3; i++) {
byte dimmValue = (byte) ((rgb[i].floatValue() * DALI_SWITCH_100_PERCENT) / 100);
getBridgeHandler().sendCommand(new DaliDAPCCommand(DaliAddress.createShortAddress(outputs.get(i)), dimmValue));
}
} else if (command instanceof OnOffType) {
if ((OnOffType) command == OnOffType.ON) {
for (Integer output : outputs) {
getBridgeHandler().sendCommand(new DaliDAPCCommand(DaliAddress.createShortAddress(output), (byte) DALI_SWITCH_100_PERCENT));
}
} else {
for (Integer output : outputs) {
getBridgeHandler().sendCommand(DaliStandardCommand.createOffCommand(DaliAddress.createShortAddress(output)));
}
}
} else if (command instanceof IncreaseDecreaseType) {
if ((IncreaseDecreaseType) command == IncreaseDecreaseType.INCREASE) {
for (Integer output : outputs) {
getBridgeHandler().sendCommand(DaliStandardCommand.createUpCommand(DaliAddress.createShortAddress(output)));
}
} else {
for (Integer output : outputs) {
getBridgeHandler().sendCommand(DaliStandardCommand.createDownCommand(DaliAddress.createShortAddress(output)));
}
}
queryDeviceState = true;
} else if (command instanceof RefreshType) {
queryDeviceState = true;
}
if (queryDeviceState) {
CompletableFuture<@Nullable NumericMask> responseR = getBridgeHandler().sendCommandWithResponse(DaliStandardCommand.createQueryActualLevelCommand(DaliAddress.createShortAddress(outputs.get(0))), DaliResponse.NumericMask.class);
CompletableFuture<@Nullable NumericMask> responseG = getBridgeHandler().sendCommandWithResponse(DaliStandardCommand.createQueryActualLevelCommand(DaliAddress.createShortAddress(outputs.get(1))), DaliResponse.NumericMask.class);
CompletableFuture<@Nullable NumericMask> responseB = getBridgeHandler().sendCommandWithResponse(DaliStandardCommand.createQueryActualLevelCommand(DaliAddress.createShortAddress(outputs.get(2))), DaliResponse.NumericMask.class);
CompletableFuture.allOf(responseR, responseG, responseB).thenAccept(x -> {
@Nullable NumericMask r = responseR.join(), g = responseG.join(), b = responseB.join();
if (r != null && !r.mask && g != null && !g.mask && b != null && !b.mask) {
Integer rValue = r.value != null ? r.value : 0;
Integer gValue = g.value != null ? g.value : 0;
Integer bValue = b.value != null ? b.value : 0;
updateState(channelUID, HSBType.fromRGB((int) (rValue.floatValue() * 255 / DALI_SWITCH_100_PERCENT), (int) (gValue.floatValue() * 255 / DALI_SWITCH_100_PERCENT), (int) (bValue.floatValue() * 255 / DALI_SWITCH_100_PERCENT)));
}
}).exceptionally(e -> {
logger.warn("Error querying device status: {}", e.getMessage());
return null;
});
}
}
} catch (DaliException e) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.COMMUNICATION_ERROR, e.getMessage());
}
}
use of org.openhab.core.types.RefreshType in project openhab-addons by openhab.
the class DanfossAirUnitHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
if (command instanceof RefreshType) {
updateAllChannels();
} else {
try {
DanfossAirUnit localAirUnit = this.airUnit;
if (localAirUnit != null) {
Channel channel = Channel.getByName(channelUID.getIdWithoutGroup());
DanfossAirUnitWriteAccessor writeAccessor = channel.getWriteAccessor();
if (writeAccessor != null) {
updateState(channelUID, writeAccessor.access(localAirUnit, command));
}
} else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.NONE, "@text/offline.connection-not-initialized");
return;
}
} catch (IllegalArgumentException e) {
logger.debug("Ignoring unknown channel id: {}", channelUID.getIdWithoutGroup(), e);
} catch (IOException ioe) {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.OFFLINE.COMMUNICATION_ERROR, ioe.getMessage());
}
}
}
use of org.openhab.core.types.RefreshType in project openhab-addons by openhab.
the class DenonMarantzConnector method sendInputCommand.
public void sendInputCommand(Command command, int zone) throws UnsupportedCommandTypeException {
String zonePrefix;
switch(zone) {
case 1:
zonePrefix = "SI";
break;
case 2:
case 3:
case 4:
zonePrefix = "Z" + zone;
break;
default:
throw new UnsupportedCommandTypeException("Zone must be in range [1-4], zone: " + zone);
}
String cmd = zonePrefix;
if (command instanceof StringType) {
cmd += command.toString();
} else if (command instanceof RefreshType) {
cmd += "?";
} else {
throw new UnsupportedCommandTypeException();
}
internalSendCommand(cmd);
}
use of org.openhab.core.types.RefreshType in project openhab-addons by openhab.
the class ElectroluxAirHandler method handleCommand.
@Override
public void handleCommand(ChannelUID channelUID, Command command) {
logger.debug("Command received: {}", command);
if (CHANNEL_STATUS.equals(channelUID.getId()) || command instanceof RefreshType) {
update();
} else {
ElectroluxPureA9DTO dto = getElectroluxPureA9DTO();
ElectroluxDeltaAPI api = getElectroluxDeltaAPO();
if (api != null && dto != null) {
if (CHANNEL_WORK_MODE.equals(channelUID.getId())) {
if (command.toString().equals(COMMAND_WORKMODE_POWEROFF)) {
api.workModePowerOff(dto.getPncId());
} else if (command.toString().equals(COMMAND_WORKMODE_AUTO)) {
api.workModeAuto(dto.getPncId());
} else if (command.toString().equals(COMMAND_WORKMODE_MANUAL)) {
api.workModeManual(dto.getPncId());
}
} else if (CHANNEL_FAN_SPEED.equals(channelUID.getId())) {
api.setFanSpeedLevel(dto.getPncId(), Integer.parseInt(command.toString()));
} else if (CHANNEL_IONIZER.equals(channelUID.getId())) {
if (command == OnOffType.OFF) {
api.setIonizer(dto.getPncId(), "false");
} else if (command == OnOffType.ON) {
api.setIonizer(dto.getPncId(), "true");
} else {
logger.debug("Unknown command! {}", command);
}
}
}
}
}
Aggregations