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

Add support for FritzBox 6690 #66

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- uses: actions/setup-java@v4
with:
distribution: 'adopt'
java-version: 11
java-version: 21

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK 17
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Setup Pages
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [11, 17, 21, 23]
java: [21, 23]
env:
DEFAULT_JAVA: 11
DEFAULT_JAVA: 21

steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 3 additions & 3 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.targetPlatform=21
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.compliance=21
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
Expand Down Expand Up @@ -113,7 +113,7 @@ org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=11
org.eclipse.jdt.core.compiler.source=21
org.eclipse.jdt.core.formatter.align_assignment_statements_on_columns=false
org.eclipse.jdt.core.formatter.align_fields_grouping_blank_lines=2147483647
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [1.8.0] - unreleased

- [#66](https://github.com/kaklakariada/fritzbox-java-api/pull/66) Add support for FritzBox 6690 (contributed by Manfred)
- [#65](https://github.com/kaklakariada/fritzbox-java-api/pull/65) Upgrade dependencies

## [1.7.0] - 2023-10-07

### Added

- [#29](https://github.com/kaklakariada/fritzbox-java-api/issues/29) Add support for login via Pbkdf2 challenge-response (propsed by [@linnex81](https://github.com/linnex81))
- [#29](https://github.com/kaklakariada/fritzbox-java-api/issues/29) Add support for login via Pbkdf2 challenge-response (proposed by [@linnex81](https://github.com/linnex81))
- [#58](https://github.com/kaklakariada/fritzbox-java-api/pull/58) Datatime attribute added in devicestats XML response since Fritz OS 7.50 (thanks to [@LutzHelling](https://github.com/LutzHelling))

### Fixed
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ version = '1.7.0'

java {
toolchain {
def javaVersion = project.hasProperty('javaVersion') ? project.getProperty('javaVersion') : 11
def javaVersion = project.hasProperty('javaVersion') ? project.getProperty('javaVersion') : 21
languageVersion = JavaLanguageVersion.of(javaVersion)
}
withJavadocJar()
Expand Down Expand Up @@ -56,6 +56,7 @@ license {
exclude('**/deviceList*Payload.xml')
exclude('devicelist6840.xml')
exclude('**/FritzOS29/*.xml')
exclude('**/FritzBox6690/*.xml')
}

jacocoTestReport {
Expand Down
19 changes: 6 additions & 13 deletions src/main/java/com/github/kaklakariada/fritzbox/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@
*/
package com.github.kaklakariada.fritzbox;

import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.io.*;
import java.nio.file.*;
import java.util.Optional;
import java.util.Properties;

Expand All @@ -39,11 +35,7 @@ private Config(final Properties properties) {
}

public static Config read() {
return read(DEFAULT_CONFIG);
}

private static Config read(final Path configFile) {
final Path file = configFile.normalize();
final Path file = DEFAULT_CONFIG.normalize();
return new Config(loadProperties(file));
}

Expand Down Expand Up @@ -74,8 +66,9 @@ public String getPassword() {
}

private String getMandatoryValue(final String param) {
return getOptionalValue(param).orElseThrow(
() -> new IllegalStateException("Property '" + param + "' not found in config file"));
return getOptionalValue(param)
.orElseThrow(
() -> new IllegalStateException("Property '" + param + "' not found in config file"));
}

private Optional<String> getOptionalValue(final String param) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public enum EnergyStatsTimeRange {

private final String command;

private EnergyStatsTimeRange(String command) {
EnergyStatsTimeRange(String command) {
this.command = command;
}
}
Expand All @@ -58,7 +58,7 @@ public String getEnergyStatistics(String deviceId, EnergyStatsTimeRange timeRang
private String executeDeviceCommand(String deviceId, String command) {
final QueryParameters parameters = QueryParameters.builder().add("command", command).add("id", deviceId)
.add("xhr", "1").build();
final String statisticsJson = session.getAutenticated(QUERY_PATH, parameters, String.class);
final String statisticsJson = session.getAuthenticated(QUERY_PATH, parameters, String.class);
LOG.trace("Got statistics json for command '{}': {}", command, statisticsJson);
return statisticsJson;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
*/
package com.github.kaklakariada.fritzbox;

import java.io.Serial;

public class FritzBoxException extends RuntimeException {

@Serial
private static final long serialVersionUID = 1L;

public FritzBoxException(String message, Throwable cause) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class FritzBoxSession {
private static final Logger LOG = LoggerFactory.getLogger(FritzBoxSession.class);

private static final String LOGIN_PATH = "/login_sid.lua";
private static final String WEBCM_PATH = "/home/home.lua";
private static final String WEB_CM_PATH = "/home/home.lua";
private static final String EMPTY_SESSION_ID = "0000000000000000";

private String sid;
Expand Down Expand Up @@ -81,7 +81,7 @@ private String createResponse(final String challenge, final String password) {
return ChallengeResponse.getAlgorithm(challenge).calculateResponse(challenge, password);
}

public <T> T getAutenticated(final String path, final QueryParameters parameters, final Class<T> resultType) {
public <T> T getAuthenticated(final String path, final QueryParameters parameters, final Class<T> resultType) {
if (sid == null) {
throw new FritzBoxException("Not logged in, session id is null");
}
Expand All @@ -90,8 +90,11 @@ public <T> T getAutenticated(final String path, final QueryParameters parameters
}

public void logout() {
httpTemplate.get(WEBCM_PATH, QueryParameters.builder().add("sid", sid).add("logout", "1").build(),
String.class);
final QueryParameters q = QueryParameters.builder()
.add("sid", sid)
.add("logout", "1")
.build();
httpTemplate.get(WEB_CM_PATH, q, String.class);
LOG.debug("Logged out, invalidate sid");
sid = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.github.kaklakariada.fritzbox;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import org.slf4j.Logger;
Expand All @@ -37,7 +38,8 @@ public class HomeAutomation {
private final FritzBoxSession session;

private enum Param {
PARAM("param"), LEVEL("level"), TARGET("target");
PARAM("param"), LEVEL("level"), TARGET("target"),
;

private final String name;

Expand All @@ -63,7 +65,7 @@ public static HomeAutomation connect(final String baseUrl, final String username

public DeviceList getDeviceListInfos() {
final DeviceList deviceList = executeCommand("getdevicelistinfos", DeviceList.class);
LOG.trace("Found {} devices, devicelist version: {}", deviceList.getDevices().size(),
LOG.trace("Found {} devices, device list version: {}", deviceList.getDevices().size(),
deviceList.getApiVersion());
return deviceList;
}
Expand All @@ -74,7 +76,7 @@ public Device getDeviceInfos(final String deviceAin) {

private <T> T executeCommand(final String command, final Class<T> resultType) {
final QueryParameters parameters = QueryParameters.builder().add("switchcmd", command).build();
return session.getAutenticated(HOME_AUTOMATION_PATH, parameters, resultType);
return session.getAuthenticated(HOME_AUTOMATION_PATH, parameters, resultType);
}

private <T> T executeParamCommand(final String deviceAin, final String command, final String parameter,
Expand All @@ -99,11 +101,14 @@ private <T> T executeDeviceCommand(final String deviceAin, final String command,
if (parameter != null) {
paramBuilder.add(paramName.name, parameter);
}
return session.getAutenticated(HOME_AUTOMATION_PATH, paramBuilder.build(), responseType);
return session.getAuthenticated(HOME_AUTOMATION_PATH, paramBuilder.build(), responseType);
}

public List<String> getSwitchList() {
final String switches = executeCommand("getswitchlist", String.class);
if (switches == null) {
return Collections.emptyList();
}
final List<String> idList = Arrays.asList(switches.split(","));
LOG.trace("Got switch list string '{}': {}", switches, idList);
return idList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@
*/
package com.github.kaklakariada.fritzbox;

import java.io.Serial;

import com.github.kaklakariada.fritzbox.model.SessionInfo;

public class LoginFailedException extends FritzBoxException {

@Serial
private static final long serialVersionUID = 1L;

public LoginFailedException(SessionInfo session) {
super("Login failed, blocked for " + session.getBlockTime() + " min");
super("Login failed, blocked for " + session.getBlockTime() + " minutes.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
*/
package com.github.kaklakariada.fritzbox;

import java.io.Serial;

public class MissingClassException extends RuntimeException {

@Serial
private static final long serialVersionUID = 1L;

public MissingClassException(String message, Throwable cause) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/github/kaklakariada/fritzbox/TestBlind.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public TestBlind() throws InterruptedException {
LOG.warn("No blind devices found");
return;
}
final int wasPercenClosed = blindDevices.get(0).getLevelControl().getLevelpercentage();
final int wasPercenClosed = blindDevices.get(0).getLevelControl().getLevelPercentage();

toggleBlindOpenClose();

Expand Down Expand Up @@ -108,7 +108,7 @@ private void togglePercentOpen() throws InterruptedException {
return;
}
showStatus(blindDevices);
final int wasPercenClosed = blindDevices.get(0).getLevelControl().getLevelpercentage();
final int wasPercenClosed = blindDevices.get(0).getLevelControl().getLevelPercentage();
final int newPercenClosed = wasPercenClosed == 0 ? 50 : wasPercenClosed / 2;

setPercentOpen(blindDevices.get(0), newPercenClosed);
Expand Down Expand Up @@ -150,7 +150,7 @@ private void showStatus(final List<Device> blindDevices) {
final String message = String.format("%-15s Mode: %s Percent-Closed: %s%%",
blind.getName(),
blind.getBlind().getMode(),
blind.getLevelControl().getLevelpercentage());
blind.getLevelControl().getLevelPercentage());
LOG.info(message);
});
}
Expand Down
15 changes: 4 additions & 11 deletions src/main/java/com/github/kaklakariada/fritzbox/TestDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,13 @@
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;
import java.util.Properties;
import java.util.*;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.kaklakariada.fritzbox.EnergyStatisticsService.EnergyStatsTimeRange;
import com.github.kaklakariada.fritzbox.model.homeautomation.AbstractDeviceStatistics;
import com.github.kaklakariada.fritzbox.model.homeautomation.Device;
import com.github.kaklakariada.fritzbox.model.homeautomation.DeviceList;
import com.github.kaklakariada.fritzbox.model.homeautomation.MeasurementUnit;
import com.github.kaklakariada.fritzbox.model.homeautomation.PowerMeter;
import com.github.kaklakariada.fritzbox.model.homeautomation.Statistics;
import com.github.kaklakariada.fritzbox.model.homeautomation.*;

public class TestDriver {
private static final Logger LOG = LoggerFactory.getLogger(TestDriver.class);
Expand Down Expand Up @@ -74,7 +67,7 @@ private static void testEnergyStats(final HomeAutomation homeAutomation, final S
}

private static void testEnergyStatsNew(final HomeAutomation homeAutomation, final String ain) {
final Optional<AbstractDeviceStatistics> energy = homeAutomation.getBasicStatistics(ain).getEnergy();
final Optional<Energy> energy = homeAutomation.getBasicStatistics(ain).getEnergy();
if (energy.isEmpty()) {
LOG.error("No Statistics for energy consumption gathered");
return;
Expand All @@ -99,7 +92,7 @@ private static void testEnergyStatsNew(final HomeAutomation homeAutomation, fina
}

private static void testVoltageStatsNew(final HomeAutomation homeAutomation, final String ain) {
final Optional<AbstractDeviceStatistics> power = homeAutomation.getBasicStatistics(ain).getPower();
final Optional<Power> power = homeAutomation.getBasicStatistics(ain).getPower();
if (power.isEmpty()) {
LOG.error("No Statistics for power consumption gathered");
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public TestHkrDriver() {
showTemperatures(hkrDevices);

final String ain = hkrDevices.get(0).getIdentifier().replaceAll("\\s*", "");
final double wasTemperature = getCelsius(hkrDevices.get(0).getHkr().getTsoll());
final double wasTemperature = getCelsius(hkrDevices.get(0).getHkr().getTSoll());
final double newTsoll = 25D;
LOG.info("");
LOG.info("Changing temperature of {} (ain='{}')to {} degrees", hkrDevices.get(0).getName(), ain,
Expand Down Expand Up @@ -87,8 +87,8 @@ private void showTemperatures(final List<Device> hkrDevices) {
hkrDevices.forEach(hkr -> {
final String message = String.format("%-15s tist: %s(%s\u00B0), tsoll: %s(%s\u00B0)",
hkr.getName(),
hkr.getHkr().getTist(), getCelsius(hkr.getHkr().getTist()),
hkr.getHkr().getTsoll(), getCelsius(hkr.getHkr().getTsoll()));
hkr.getHkr().getTIst(), getCelsius(hkr.getHkr().getTIst()),
hkr.getHkr().getTSoll(), getCelsius(hkr.getHkr().getTSoll()));
LOG.info(message);
});
}
Expand Down
Loading
Loading