Skip to content

Commit

Permalink
Merge pull request #19 from PeterJelitsch/feature/IDEA-114-homeautoma…
Browse files Browse the repository at this point in the history
…tion-group-support

IDEA-114 added homeautomation group support
  • Loading branch information
kaklakariada authored Feb 28, 2021
2 parents 766eae9 + bce7e0e commit 6bdd3cb
Show file tree
Hide file tree
Showing 15 changed files with 635 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [1.4.0] - unreleased

### Added

* [#19](https://github.com/kaklakariada/fritzbox-java-api/pull/19) Support for device groups

## [1.3.1] - 2021-02-26

* No changes, update deployment to Maven Central
Expand Down
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ dependencies {

testImplementation 'junit:junit:4.13.1'
testImplementation 'org.mockito:mockito-core:3.5.15'
testImplementation 'org.assertj:assertj-core:3.19.0'
}

license {
header = file('gradle/license-header.txt')
exclude('**/deviceList*Payload.xml')
exclude('devicelist6840.xml')
}

jacocoTestReport {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class Device {

@Element(name = "present")
private String present;
@Element(name = "txbusy")
@Element(name = "txbusy", required = false)
private String txbusy;
@Element(name = "name")
private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ public class DeviceList {
@ElementList(name = "device", type = Device.class, inline = true)
private List<Device> devices;

@Attribute(name = "fwversion")
@ElementList(name = "group", type = Group.class, inline = true, required = false)
private List<Group> groups;


@Attribute(name = "fwversion", required = false, empty = "n/a")
private String firmwareVersion;

public String getApiVersion() {
Expand All @@ -45,6 +49,10 @@ public List<Device> getDevices() {
return devices;
}

public List<Group> getGroups() {
return groups;
}

public Device getDeviceByIdentifier(String identifier) {
return devices.stream() //
.filter(d -> identifierMatches(d, identifier)) //
Expand All @@ -69,6 +77,13 @@ private static String normalizeIdentifier(String identifier) {
return identifier.replace(" ", "");
}

public Group getGroupById(String id) {
return groups.stream()
.filter(group -> group.getId().equals(id))
.findFirst()
.orElse(null);
}

@Override
public String toString() {
return "DeviceList [apiVersion=" + apiVersion + ", devices=" + devices + "]";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/**
* A Java API for managing FritzBox HomeAutomation
* Copyright (C) 2017 Christoph Pirkl <christoph at users.sourceforge.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.kaklakariada.fritzbox.model.homeautomation;

import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;

@Root(name = "group")
public class Group {

@Attribute(name = "identifier")
private String identifier;
@Attribute(name = "id")
private String id;
@Attribute(name = "functionbitmask")
private int functionBitmask;
@Attribute(name = "fwversion")
private String firmwareVersion;
@Attribute(name = "manufacturer")
private String manufacturer;
@Attribute(name = "productname")
private String productName;
@Element(name = "present")
private String present;
@Element(name = "name")
private String name;
@Element(name = "switch", required = false)
private SwitchState switchState;
@Element(name = "powermeter", required = false)
private PowerMeter powerMeter;
@Element(name = "groupinfo", required = false)
private GroupInfo groupInfo;

public String getId() {
return id;
}

public int getFunctionBitmask() {
return functionBitmask;
}

public String getFirmwareVersion() {
return firmwareVersion;
}

public String getManufacturer() {
return manufacturer;
}

public String getProductName() {
return productName;
}

public String getPresent() {
return present;
}

public String getName() {
return name;
}

public SwitchState getSwitchState() {
return switchState;
}

public PowerMeter getPowerMeter() {
return powerMeter;
}

public String getIdentifier() {
return identifier;
}

public GroupInfo getGroupInfo() {
return groupInfo;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* A Java API for managing FritzBox HomeAutomation
* Copyright (C) 2017 Christoph Pirkl <christoph at users.sourceforge.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.kaklakariada.fritzbox.model.homeautomation;

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

import org.simpleframework.xml.Element;
import org.simpleframework.xml.Root;

@Root(name="groupinfo")
public class GroupInfo {

@Element(name="masterdeviceid")
private String masterDeviceId;

/**
* Comma seperated list of devices identfied by their id.
*/
@Element(name="members")
private String members;

public String getMasterDeviceId() {
return masterDeviceId;
}

public String getMembers() {
return members;
}

public List<String> getMemberList() {
return Arrays.asList(this.members.split(","));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public int getEnergyWattHours() {
return energyWattHours;
}

public int getPowerMilliWatt() {
return powerMilliWatt;
}

@Override
public String toString() {
return "PowerMeter [voltage=" + getVoltageVolt() + ", energyWattHours=" + energyWattHours + ", powerWatt="
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* A Java API for managing FritzBox HomeAutomation
* Copyright (C) 2017 Christoph Pirkl <christoph at users.sourceforge.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.kaklakariada.fritzbox.assertions;

import org.assertj.core.api.AbstractObjectAssert;
import org.assertj.core.api.Assertions;

import com.github.kaklakariada.fritzbox.model.homeautomation.DeviceList;

public class DeviceListAssert extends AbstractObjectAssert<DeviceListAssert, DeviceList> {

private static final String ERROR_MESSAGE = "Expected %s to be <%s> but was <%s> (%s)";

DeviceListAssert(DeviceList actual) {
super(actual, DeviceListAssert.class);
}

public DeviceListAssert hasGroupsSize(int expected) {
int actualGroupsSize = actual.getGroups().size();
Assertions.assertThat(actualGroupsSize)
.overridingErrorMessage(ERROR_MESSAGE, "groupSize", expected, actualGroupsSize, descriptionText())
.isEqualTo(expected);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* A Java API for managing FritzBox HomeAutomation
* Copyright (C) 2017 Christoph Pirkl <christoph at users.sourceforge.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.kaklakariada.fritzbox.assertions;

import org.assertj.core.api.AbstractObjectAssert;
import org.assertj.core.api.Assertions;

import com.github.kaklakariada.fritzbox.model.homeautomation.Group;


public class GroupAssert extends AbstractObjectAssert<GroupAssert, Group> {

private static final String ERROR_MESSAGE = "Expected %s to be <%s> but was <%s> (%s)";

GroupAssert(Group actual) {
super(actual, GroupAssert.class);
}

public GroupAssert hasName(String expected) {
String actual = this.actual.getName();
Assertions.assertThat(actual)
.overridingErrorMessage(ERROR_MESSAGE, "name", expected, actual, descriptionText())
.isEqualTo(expected);
return this;
}

public GroupAssert hasPresent(String expected) {
String actual = this.actual.getPresent();
Assertions.assertThat(actual)
.overridingErrorMessage(ERROR_MESSAGE, "present", expected, actual, descriptionText())
.isEqualTo(expected);
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* A Java API for managing FritzBox HomeAutomation
* Copyright (C) 2017 Christoph Pirkl <christoph at users.sourceforge.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.github.kaklakariada.fritzbox.assertions;

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

import org.assertj.core.api.AbstractObjectAssert;
import org.assertj.core.api.Assertions;

import com.github.kaklakariada.fritzbox.model.homeautomation.GroupInfo;


public class GroupInfoAssert extends AbstractObjectAssert<GroupInfoAssert, GroupInfo> {

private static final String ERROR_MESSAGE = "Expected %s to be <%s> but was <%s> (%s)";

GroupInfoAssert(GroupInfo actual) {
super(actual, GroupInfoAssert.class);
}

public GroupInfoAssert hasMasterDeviceId(String expected) {
String actual = this.actual.getMasterDeviceId();
Assertions.assertThat(actual)
.overridingErrorMessage(ERROR_MESSAGE, "masterDeviceId", expected, actual, descriptionText())
.isEqualTo(expected);
return this;
}

public GroupInfoAssert containsAllMembers(String ... expected) {
List<String> actual = this.actual.getMemberList();
Assertions.assertThat(actual)
.overridingErrorMessage(ERROR_MESSAGE, "memberList", expected, actual, descriptionText())
.containsExactlyInAnyOrderElementsOf(Arrays.asList(expected));
return this;
}
}
Loading

0 comments on commit 6bdd3cb

Please sign in to comment.