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

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

Merged
merged 15 commits into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions bundles/org.openhab.binding.livisismarthome/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
| 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 |
| restart | Switch | Restarts the device (stateless switch) | SHC (bridge) |
| rollershutter | Rollershutter | Controls a roller shutter | ISR2 |
| 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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ public class LivisiBindingConstants {
public static final String CHANNEL_DISK = "disk";
public static final String CHANNEL_MEMORY = "memory";
public static final String CHANNEL_OPERATION_STATUS = "status";
public static final String CHANNEL_RESTART = "restart";

// List of channel parameters
public static final String INVERT_CHANNEL_PARAMETER = "invert";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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.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.ShutterActionType;
import org.openhab.binding.livisismarthome.internal.client.api.entity.action.StateActionSetterDTO;
Expand Down Expand Up @@ -265,6 +266,15 @@ public void setRollerShutterAction(final String capabilityId, final ShutterActio
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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class ActionParamsDTO {
private StringActionParamDTO operationMode;
private StringActionParamDTO rampDirection;
private StringActionParamDTO activeChannel;
private StringActionParamDTO reason;

/**
* @return the onState
Expand Down Expand Up @@ -141,4 +142,18 @@ public StringActionParamDTO getActiveChannel() {
public void setActiveChannel(StringActionParamDTO 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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.openhab.core.auth.client.oauth2.OAuthException;
import org.openhab.core.auth.client.oauth2.OAuthFactory;
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.StringType;
import org.openhab.core.library.unit.Units;
Expand Down Expand Up @@ -132,7 +133,17 @@ public LivisiBridgeHandler(final Bridge bridge, final OAuthFactory oAuthFactory,

@Override
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
Expand Down Expand Up @@ -821,6 +832,19 @@ public void commandSetRollerShutterStop(final String deviceId, final ShutterActi
(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,
final CommandExecutor commandExecutor) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private void commandSwitchAlarm(Command command, LivisiBridgeHandler bridgeHandl
}

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);
} else {
bridgeHandler.commandSwitchSiren(deviceId, SIREN_NONE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.pushButtonCounter.label = Button Pushed Count
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.description = Controls the blinds (percent)
channel-type.livisismarthome.smokeDetectorSensor.label = Smoke
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<channel id="cpu" typeId="cpuUsage"/>
<channel id="disk" typeId="diskUsage"/>
<channel id="memory" typeId="memoryUsage"/>
<channel id="restart" typeId="restart"/>
</channels>

<representation-property>id</representation-property>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,13 @@
<state readOnly="true"/>
</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>
jlaur marked this conversation as resolved.
Show resolved Hide resolved
<autoUpdatePolicy>veto</autoUpdatePolicy>
</channel-type>

</thing:thing-descriptions>