[livisismarthome] Add support for rebooting the smart home controller (#16969)

Signed-off-by: Sven Strohschein <sven.strohschein@gmail.com>
Signed-off-by: Sven Strohschein <novanic@gmx.de>
This commit is contained in:
Sven Strohschein 2024-12-29 00:26:00 +01:00 committed by GitHub
parent e2571d6f09
commit 7b986e03d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 101 additions and 2 deletions

View File

@ -93,6 +93,7 @@ However, only devices will appear that are added in the LIVISI SmartHome app bef
| moldWarning | Switch | Active, if the measured humidity is too low (ON/OFF) | RST, RST2, WRT | | moldWarning | Switch | Active, if the measured humidity is too low (ON/OFF) | RST, RST2, WRT |
| motionCount | Number | Number of detected motions, increases with each detected motion | WMD, WMDO | | motionCount | Number | Number of detected motions, increases with each detected motion | WMD, WMDO |
| operationMode | String | The mode of a thermostat (auto/manual) | RST, RST2, WRT | | operationMode | String | The mode of a thermostat (auto/manual) | RST, RST2, WRT |
| restart | Switch | Restarts the device (stateless switch) | SHC (bridge) |
| rollershutter | Rollershutter | Controls a roller shutter | ISR2 | | rollershutter | Rollershutter | Controls a roller shutter | ISR2 |
| targetTemperature | Number | Sets the target temperature in °C (min 6 °C, max 30 °C) | RST, RST2, WRT | | targetTemperature | Number | Sets the target temperature in °C (min 6 °C, max 30 °C) | RST, RST2, WRT |
| siren | Switch | Switches the siren (ON/OFF) | SIR | | siren | Switch | Switches the siren (ON/OFF) | SIR |

View File

@ -184,6 +184,7 @@ public class LivisiBindingConstants {
public static final String CHANNEL_DISK = "disk"; public static final String CHANNEL_DISK = "disk";
public static final String CHANNEL_MEMORY = "memory"; public static final String CHANNEL_MEMORY = "memory";
public static final String CHANNEL_OPERATION_STATUS = "status"; public static final String CHANNEL_OPERATION_STATUS = "status";
public static final String CHANNEL_RESTART = "restart";
// List of channel parameters // List of channel parameters
public static final String INVERT_CHANNEL_PARAMETER = "invert"; public static final String INVERT_CHANNEL_PARAMETER = "invert";

View File

@ -33,6 +33,7 @@ import org.eclipse.jetty.http.HttpStatus;
import org.openhab.binding.livisismarthome.internal.LivisiBindingConstants; import org.openhab.binding.livisismarthome.internal.LivisiBindingConstants;
import org.openhab.binding.livisismarthome.internal.client.api.entity.StatusResponseDTO; import org.openhab.binding.livisismarthome.internal.client.api.entity.StatusResponseDTO;
import org.openhab.binding.livisismarthome.internal.client.api.entity.action.ActionDTO; import org.openhab.binding.livisismarthome.internal.client.api.entity.action.ActionDTO;
import org.openhab.binding.livisismarthome.internal.client.api.entity.action.RestartActionDTO;
import org.openhab.binding.livisismarthome.internal.client.api.entity.action.ShutterActionDTO; import org.openhab.binding.livisismarthome.internal.client.api.entity.action.ShutterActionDTO;
import org.openhab.binding.livisismarthome.internal.client.api.entity.action.ShutterActionType; import org.openhab.binding.livisismarthome.internal.client.api.entity.action.ShutterActionType;
import org.openhab.binding.livisismarthome.internal.client.api.entity.action.StateActionSetterDTO; import org.openhab.binding.livisismarthome.internal.client.api.entity.action.StateActionSetterDTO;
@ -265,6 +266,15 @@ public class LivisiClient {
executePost(createActionURL(), new ShutterActionDTO(capabilityId, rollerShutterAction)); executePost(createActionURL(), new ShutterActionDTO(capabilityId, rollerShutterAction));
} }
/**
* Restarts the SHC (bridge) device
*/
public void setRestartAction(@Nullable final String bridgeDeviceId) throws IOException {
if (bridgeDeviceId != null) {
executePost(createActionURL(), new RestartActionDTO(bridgeDeviceId));
}
}
/** /**
* Sets a new state of a VariableActuator. * Sets a new state of a VariableActuator.
*/ */

View File

@ -29,6 +29,7 @@ public class ActionParamsDTO {
private StringActionParamDTO operationMode; private StringActionParamDTO operationMode;
private StringActionParamDTO rampDirection; private StringActionParamDTO rampDirection;
private StringActionParamDTO activeChannel; private StringActionParamDTO activeChannel;
private StringActionParamDTO reason;
/** /**
* @return the onState * @return the onState
@ -141,4 +142,18 @@ public class ActionParamsDTO {
public void setActiveChannel(StringActionParamDTO activeChannel) { public void setActiveChannel(StringActionParamDTO activeChannel) {
this.activeChannel = activeChannel; this.activeChannel = activeChannel;
} }
/**
* @return the reason (for example the reason to restart the controller)
*/
public StringActionParamDTO getReason() {
return reason;
}
/**
* @param reason the reason (for example the reason to restart the controller)
*/
public void setReason(StringActionParamDTO reason) {
this.reason = reason;
}
} }

View File

@ -0,0 +1,36 @@
/**
* Copyright (c) 2010-2024 Contributors to the openHAB project
*
* See the NOTICE file(s) distributed with this work for additional
* information.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.openhab.binding.livisismarthome.internal.client.api.entity.action;
import org.openhab.binding.livisismarthome.internal.client.api.entity.link.LinkDTO;
/**
* Special {@link ActionDTO} to execute a restart.
*
* @author Sven Strohschein - Initial contribution
*/
public class RestartActionDTO extends ActionDTO {
private static final String ACTION_TYPE_RESTART = "Restart";
private static final String CONSTANT = "Constant";
private static final String DEFAULT_RESTART_REASON = "The openHAB binding requested to restart the smart home controller.";
public RestartActionDTO(String deviceId) {
setType(ACTION_TYPE_RESTART);
setTarget(LinkDTO.LINK_TYPE_DEVICE + deviceId);
final ActionParamsDTO params = new ActionParamsDTO();
params.setReason(new StringActionParamDTO(CONSTANT, DEFAULT_RESTART_REASON));
setParams(params);
}
}

View File

@ -67,6 +67,7 @@ import org.openhab.core.auth.client.oauth2.OAuthClientService;
import org.openhab.core.auth.client.oauth2.OAuthException; import org.openhab.core.auth.client.oauth2.OAuthException;
import org.openhab.core.auth.client.oauth2.OAuthFactory; import org.openhab.core.auth.client.oauth2.OAuthFactory;
import org.openhab.core.auth.client.oauth2.OAuthResponseException; import org.openhab.core.auth.client.oauth2.OAuthResponseException;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.library.types.QuantityType; import org.openhab.core.library.types.QuantityType;
import org.openhab.core.library.types.StringType; import org.openhab.core.library.types.StringType;
import org.openhab.core.library.unit.Units; import org.openhab.core.library.unit.Units;
@ -132,7 +133,17 @@ public class LivisiBridgeHandler extends BaseBridgeHandler
@Override @Override
public void handleCommand(final ChannelUID channelUID, final Command command) { public void handleCommand(final ChannelUID channelUID, final Command command) {
// not needed if (CHANNEL_RESTART.equals(channelUID.getId())) {
commandRestart(command);
} else {
logger.debug("UNSUPPORTED channel {} for bridge {}.", channelUID.getId(), bridgeId);
}
}
private void commandRestart(Command command) {
if (OnOffType.ON.equals(command)) {
commandRestart();
}
} }
@Override @Override
@ -821,6 +832,19 @@ public class LivisiBridgeHandler extends BaseBridgeHandler
(capabilityId) -> client.setRollerShutterAction(capabilityId, action)); (capabilityId) -> client.setRollerShutterAction(capabilityId, action));
} }
/**
* Restarts the SHC (bridge) device
*/
public void commandRestart() {
try {
client.setRestartAction(bridgeId);
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.NONE, "Restarting...");
} catch (IOException e) {
handleClientException(e);
}
}
private void executeCommand(final String deviceId, final String capabilityType, private void executeCommand(final String deviceId, final String capabilityType,
final CommandExecutor commandExecutor) { final CommandExecutor commandExecutor) {
try { try {

View File

@ -225,7 +225,7 @@ public class LivisiDeviceHandler extends BaseThingHandler implements DeviceStatu
} }
private void commandSwitchSiren(Command command, String notificationSound, LivisiBridgeHandler bridgeHandler) { private void commandSwitchSiren(Command command, String notificationSound, LivisiBridgeHandler bridgeHandler) {
if (command instanceof OnOffType && OnOffType.ON.equals(command)) { if (OnOffType.ON.equals(command)) {
bridgeHandler.commandSwitchSiren(deviceId, notificationSound); bridgeHandler.commandSwitchSiren(deviceId, notificationSound);
} else { } else {
bridgeHandler.commandSwitchSiren(deviceId, SIREN_NONE); bridgeHandler.commandSwitchSiren(deviceId, SIREN_NONE);

View File

@ -128,6 +128,8 @@ channel-type.livisismarthome.powerGenerationWatt.label = Current Power Generatio
channel-type.livisismarthome.powerGenerationWatt.description = The current power generation (Watt) channel-type.livisismarthome.powerGenerationWatt.description = The current power generation (Watt)
channel-type.livisismarthome.pushButtonCounter.label = Button Pushed Count channel-type.livisismarthome.pushButtonCounter.label = Button Pushed Count
channel-type.livisismarthome.pushButtonCounter.description = The count of button pushes. channel-type.livisismarthome.pushButtonCounter.description = The count of button pushes.
channel-type.livisismarthome.restartAction.label = Restart
channel-type.livisismarthome.restartAction.description = Restarts the device
channel-type.livisismarthome.rollerShutterActuator.label = Blinds Position channel-type.livisismarthome.rollerShutterActuator.label = Blinds Position
channel-type.livisismarthome.rollerShutterActuator.description = Controls the blinds (percent) channel-type.livisismarthome.rollerShutterActuator.description = Controls the blinds (percent)
channel-type.livisismarthome.smokeDetectorSensor.label = Smoke channel-type.livisismarthome.smokeDetectorSensor.label = Smoke

View File

@ -13,6 +13,7 @@
<channel id="cpu" typeId="cpuUsage"/> <channel id="cpu" typeId="cpuUsage"/>
<channel id="disk" typeId="diskUsage"/> <channel id="disk" typeId="diskUsage"/>
<channel id="memory" typeId="memoryUsage"/> <channel id="memory" typeId="memoryUsage"/>
<channel id="restart" typeId="restart"/>
</channels> </channels>
<representation-property>id</representation-property> <representation-property>id</representation-property>

View File

@ -389,4 +389,13 @@
<state readOnly="true"/> <state readOnly="true"/>
</channel-type> </channel-type>
<!-- RebootAction -->
<channel-type id="restart" advanced="true">
<item-type>Switch</item-type>
<label>Restart</label>
<description>Restarts the device</description>
<category>Switch</category>
<autoUpdatePolicy>veto</autoUpdatePolicy>
</channel-type>
</thing:thing-descriptions> </thing:thing-descriptions>