Skip to content

Commit 59b11ce

Browse files
authored
Merge pull request #58 from LutzHelling/master
datatime attribute added
2 parents 8c51230 + b5b7b20 commit 59b11ce

File tree

7 files changed

+105
-45
lines changed

7 files changed

+105
-45
lines changed

CHANGELOG.md

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,99 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

45
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
56
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
67

7-
## [1.7.0] - unreleased
8+
## [1.8.0] - unreleased
9+
10+
## [1.7.0] - 2023-10-07
811

912
### Added
1013

11-
* [#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))
14+
- [#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))
15+
- [#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))
1216

1317
### Fixed
1418

15-
* [#37](https://github.com/kaklakariada/fritzbox-java-api/issues/37) Support empty device lists
19+
- [#37](https://github.com/kaklakariada/fritzbox-java-api/issues/37) Support empty device lists
1620

1721
### Refactoring
1822

19-
* [#50](https://github.com/kaklakariada/fritzbox-java-api/pull/50) Migrate to Junit 5
23+
- [#50](https://github.com/kaklakariada/fritzbox-java-api/pull/50) Migrate to Junit 5
2024

2125
## [1.6.0] - 2021-12-04
2226

2327
### Added
2428

25-
* [#39](https://github.com/kaklakariada/fritzbox-java-api/pull/39) Add new command "getdeviceinfo" (thanks to [@odin568](https://github.com/odin568))
26-
* [#46](https://github.com/kaklakariada/fritzbox-java-api/pull/46) Add additional attributes to group (thanks to [@TDesjardins](https://github.com/TDesjardins))
27-
* [#47](https://github.com/kaklakariada/fritzbox-java-api/pull/47) Add hkr attribute supported by FritzOS 7.29 (thanks to [@philippn](https://github.com/philippn))
28-
* [#38](https://github.com/kaklakariada/fritzbox-java-api/pull/38) Add commands to set status for hkr (tsoll) and for blind (open, close etc.) (thanks to [@JunkerMartin](https://github.com/JunkerMartin))
29+
- [#39](https://github.com/kaklakariada/fritzbox-java-api/pull/39) Add new command "getdeviceinfo" (thanks to [@odin568](https://github.com/odin568))
30+
- [#46](https://github.com/kaklakariada/fritzbox-java-api/pull/46) Add additional attributes to group (thanks to [@TDesjardins](https://github.com/TDesjardins))
31+
- [#47](https://github.com/kaklakariada/fritzbox-java-api/pull/47) Add hkr attribute supported by FritzOS 7.29 (thanks to [@philippn](https://github.com/philippn))
32+
- [#38](https://github.com/kaklakariada/fritzbox-java-api/pull/38) Add commands to set status for hkr (tsoll) and for blind (open, close etc.) (thanks to [@JunkerMartin](https://github.com/JunkerMartin))
2933

3034
### Updated
3135

32-
* [#45](https://github.com/kaklakariada/fritzbox-java-api/pull/45) Upgrade dependencies
36+
- [#45](https://github.com/kaklakariada/fritzbox-java-api/pull/45) Upgrade dependencies
3337

3438
## [1.5.0] - 2021-12-04
3539

3640
### Added
3741

38-
* [#34](https://github.com/kaklakariada/fritzbox-java-api/pull/34) Support new device "Blind" and supply device statistics (thanks to [@JunkerMartin](https://github.com/JunkerMartin) for his contribution!)
42+
- [#34](https://github.com/kaklakariada/fritzbox-java-api/pull/34) Support new device "Blind" and supply device statistics (thanks to [@JunkerMartin](https://github.com/JunkerMartin) for his contribution!)
3943

4044
### Updated
4145

42-
* [#35](https://github.com/kaklakariada/fritzbox-java-api/pull/35) Upgraded dependencies
46+
- [#35](https://github.com/kaklakariada/fritzbox-java-api/pull/35) Upgraded dependencies
4347

4448
## [1.4.0] - 2021-03-03
4549

4650
### Added
47-
* [#18](https://github.com/kaklakariada/fritzbox-java-api/pull/18) Added new fields to be compatible with Fritz!OS 7.25
48-
* Device (Fritz!Dect440) serves now relative humidity
49-
* ColorControl (Fritz!Dect500) got some more fields
50-
* Added some getter for fields that did miss them
51-
* [#19](https://github.com/kaklakariada/fritzbox-java-api/pull/19) Support for device groups
51+
52+
- [#18](https://github.com/kaklakariada/fritzbox-java-api/pull/18) Added new fields to be compatible with Fritz!OS 7.25
53+
- Device (Fritz!Dect440) serves now relative humidity
54+
- ColorControl (Fritz!Dect500) got some more fields
55+
- Added some getter for fields that did miss them
56+
- [#19](https://github.com/kaklakariada/fritzbox-java-api/pull/19) Support for device groups
5257

5358
## [1.3.1] - 2021-02-26
5459

55-
* No changes, update deployment to Maven Central
60+
- No changes, update deployment to Maven Central
5661

5762
## [1.3.0] - 2021-02-22
5863

5964
### Breaking Changes
6065

61-
* Requires Java 11 instead of Java 8
62-
* Moved from JCenter to Maven Central due to [deprecation of JCenter](https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/). In your build script use
66+
- Requires Java 11 instead of Java 8
67+
- Moved from JCenter to Maven Central due to [deprecation of JCenter](https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/). In your build script use
6368

64-
```gradle
65-
repositories {
66-
mavenCentral()
67-
}
68-
```
69+
```gradle
70+
repositories {
71+
mavenCentral()
72+
}
73+
```
6974

7075
## [1.2.2] - 2021-01-16
7176

7277
### Added
7378

74-
* [#17](https://github.com/kaklakariada/fritzbox-java-api/pull/17): Update for Fritz-Dect!4XX devices. Thanks to [SmokingDevices](https://github.com/SmokingDevices)!
79+
- [#17](https://github.com/kaklakariada/fritzbox-java-api/pull/17): Update for Fritz-Dect!4XX devices. Thanks to [SmokingDevices](https://github.com/SmokingDevices)!
7580

7681
## [1.2.1] - 2020-12-06
7782

7883
### Added
7984

80-
* [#16](https://github.com/kaklakariada/fritzbox-java-api/pull/16): Update for FRITZ-Dect 500 devices. Thanks to [SmokingDevices](https://github.com/SmokingDevices)!
85+
- [#16](https://github.com/kaklakariada/fritzbox-java-api/pull/16): Update for FRITZ-Dect 500 devices. Thanks to [SmokingDevices](https://github.com/SmokingDevices)!
8186

8287
## [1.2.0] - 2020-12-06 - invalid
8388

8489
## [1.1.0] - 2020-10-25
8590

8691
### Added
8792

88-
* [#15](https://github.com/kaklakariada/fritzbox-java-api/pull/15): Added new fields to be compatible with Fritz!OS 7.21. Thanks to [philippn](https://github.com/philippn)!
93+
- [#15](https://github.com/kaklakariada/fritzbox-java-api/pull/15): Added new fields to be compatible with Fritz!OS 7.21. Thanks to [philippn](https://github.com/philippn)!
8994

9095
## [1.0.0] - 2019-12-27
9196

9297
### Breaking change
9398

94-
* Make Device properties `battery` and `batterylow` optional to distinguish between missing values and zero, see [issue #11](https://github.com/kaklakariada/fritzbox-java-api/issues/11).
99+
- Make Device properties `battery` and `batterylow` optional to distinguish between missing values and zero, see [issue #11](https://github.com/kaklakariada/fritzbox-java-api/issues/11).

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ See [CHANGELOG.md](CHANGELOG.md).
3636
3737
```groovy
3838
dependencies {
39-
compile 'com.github.kaklakariada:fritzbox-java-api:1.6.0'
39+
compile 'com.github.kaklakariada:fritzbox-java-api:1.6.1'
4040
}
4141
```
4242
@@ -46,7 +46,7 @@ See [CHANGELOG.md](CHANGELOG.md).
4646
<dependency>
4747
<groupId>com.github.kaklakariada</groupId>
4848
<artifactId>fritzbox-java-api</artifactId>
49-
<version>1.6.0</version>
49+
<version>1.6.1</version>
5050
</dependency>
5151
```
5252

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ plugins {
1111
}
1212

1313
group 'com.github.kaklakariada'
14-
version = '1.6.0'
14+
version = '1.7.0'
1515

1616
java {
1717
toolchain {

src/main/java/com/github/kaklakariada/fritzbox/model/homeautomation/Statistics.java

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,13 @@
1717
*/
1818
package com.github.kaklakariada.fritzbox.model.homeautomation;
1919

20-
import java.util.ArrayList;
21-
import java.util.Arrays;
22-
import java.util.List;
23-
import java.util.Optional;
20+
import java.time.Instant;
21+
import java.util.*;
2422
import java.util.stream.Collectors;
2523

26-
import com.github.kaklakariada.fritzbox.helper.StringHelper;
24+
import org.simpleframework.xml.*;
2725

28-
import org.simpleframework.xml.Attribute;
29-
import org.simpleframework.xml.Root;
30-
import org.simpleframework.xml.Text;
26+
import com.github.kaklakariada.fritzbox.helper.StringHelper;
3127

3228
@Root(name = "stats")
3329
public class Statistics {
@@ -40,9 +36,25 @@ public class Statistics {
4036
@Attribute(name = "grid", required = false)
4137
private int grid;
4238

39+
@Attribute(name = "datatime", required = false)
40+
private Long datatime;
41+
4342
@Text()
4443
private String csvValues;
4544

45+
public Statistics() {
46+
// Default constructor for XML deserialization
47+
}
48+
49+
Statistics(final MeasurementUnit measurementUnit, final int count, final int grid, final Long datatime,
50+
final String csvValues) {
51+
this.measurementUnit = measurementUnit;
52+
this.count = count;
53+
this.grid = grid;
54+
this.datatime = datatime;
55+
this.csvValues = csvValues;
56+
}
57+
4658
public int getCount() {
4759
return count;
4860
}
@@ -51,6 +63,26 @@ public int getGrid() {
5163
return grid;
5264
}
5365

66+
/**
67+
* Get the raw timestamp in seconds since epoch.
68+
*
69+
* @return raw timestamp or {@code null} if not available
70+
*/
71+
public Long getDataTimeRaw() {
72+
return datatime;
73+
}
74+
75+
/**
76+
* Get the timestamp.
77+
*
78+
* @return timestamp or {@code null} if not available
79+
*/
80+
public Instant getDataTime() {
81+
return Optional.ofNullable(getDataTimeRaw()) //
82+
.map(Instant::ofEpochSecond) //
83+
.orElse(null);
84+
}
85+
5486
/**
5587
* Provide the gathered data as provided by Fritz!Box
5688
*

src/test/java/com/github/kaklakariada/fritzbox/mapping/DeserializerTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ DeviceList parseDeviceList(final Path file) throws IOException {
116116

117117
@Test
118118
void parseDeviceStatsFritzDect200() throws IOException {
119-
final InputStream fileContent = Files.newInputStream(Paths.get("src/test/resources/FritzOS29/devicestatsFritzDect200.xml"));
119+
final InputStream fileContent = Files
120+
.newInputStream(Paths.get("src/test/resources/FritzOS29/devicestatsFritzDect200.xml"));
120121
final DeviceStats stats = new Deserializer().parse(fileContent, DeviceStats.class);
121122
assertEquals(1, stats.getTemperature().get().getStats().size(), "Temperature has just one statistics Element");
122123
assertEquals(Double.valueOf(0.1),
@@ -126,6 +127,12 @@ void parseDeviceStatsFritzDect200() throws IOException {
126127
assertEquals(2, stats.getEnergy().get().getStats().size(), "Energy has two statistics Element");
127128

128129
assertEquals(false, stats.getHumidity().isPresent(), "Humidity is missing");
130+
131+
assertEquals(true, stats.getEnergy().get().getStats().get(0).getDataTimeRaw() == 1665897036,
132+
"DataTime (raw) is missing");
133+
assertEquals(false,
134+
stats.getEnergy().get().getStats().get(0).getDataTime().toEpochMilli() == 1665897,
135+
"DataTime is missing");
129136
}
130137

131138
@Test

src/test/java/com/github/kaklakariada/fritzbox/model/homeautomation/StatisticsTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,20 @@
1919

2020
import static org.junit.jupiter.api.Assertions.assertEquals;
2121

22+
import java.lang.System.Logger;
23+
import java.time.Instant;
2224
import java.util.List;
2325
import java.util.Optional;
2426

2527
import org.junit.jupiter.api.BeforeAll;
2628
import org.junit.jupiter.api.Test;
29+
import org.junit.jupiter.params.ParameterizedTest;
30+
import org.junit.jupiter.params.provider.CsvSource;
2731

2832
class StatisticsTest {
2933

3034
private static Statistics statistics;
35+
private static final Logger LOGGER = System.getLogger("StatisticsTest");
3136

3237
@BeforeAll
3338
static void setupStatistics() {
@@ -74,4 +79,15 @@ void getCsvValuesTest() {
7479
assertEquals(Double.valueOf(11.11), result.get(1).get(), "(5) Second number");
7580
assertEquals(true, result.get(2).isEmpty(), "(5) Third number is empty");
7681
}
82+
83+
@ParameterizedTest
84+
@CsvSource(nullValues = "null", value = { "null, null",
85+
"0, 1970-01-01T00:00:00Z",
86+
"1665897036, 2022-10-16T05:10:36Z",
87+
})
88+
void dateTime(final Long rawDateTime, final Instant expectedInstant) {
89+
final Statistics stat = new Statistics(null, 0, 0, rawDateTime, null);
90+
assertEquals(expectedInstant, stat.getDataTime());
91+
assertEquals(rawDateTime, stat.getDataTimeRaw());
92+
}
7793
}

0 commit comments

Comments
 (0)