Skip to content

Commit b0351ae

Browse files
author
Kristel
committed
initial commit
0 parents  commit b0351ae

13 files changed

+574
-0
lines changed

.gitignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
target/
2+
!**/src/main/**/target/
3+
!**/src/test/**/target/
4+
5+
### IntelliJ IDEA ###
6+
/.idea/
7+
8+
*.iml
9+
10+
### files generated by java openapi generator
11+
/generated-tado-api-client/.github
12+
/generated-tado-api-client/.openapi-generator/
13+
/generated-tado-api-client/api/
14+
/generated-tado-api-client/generated-src/
15+
/generated-tado-api-client/gradle/
16+
/generated-tado-api-client/src/
17+
/generated-tado-api-client/*build*
18+
/generated-tado-api-client/*git*
19+
/generated-tado-api-client/*gradle*
20+
/generated-tado-api-client/*travis*
21+

README.md

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Tado api demo - java
2+
3+
tadoº is a german based company which offers a smart thermostat solution.
4+
They also have an API to control this solution.
5+
6+
This java application shows how you can use the tado API v2 which is available
7+
at https://my.tado.com/api/v2.
8+
9+
# Module set-up
10+
11+
## generated-tado-api-client
12+
Generated java client for the tado API.
13+
14+
It uses the `openapi-generator-maven-plugin` to generate the client code based on the
15+
tado OpenAPI spec maintained here https://github.com/kritsel/tado-openapispec-v2/
16+
17+
## tado demo
18+
19+
Spring boot application which executes some tado API calls upon application
20+
start-up.
21+
22+
It also implements the OAuth 2.0 authentication mechanism to authenticate
23+
to the API.
24+
25+
# How to run this application
26+
27+
## Prerequisites
28+
You need to have a tado account which is linked to a tado Home.
29+
30+
The username and password of this account need to be supplied as arguments
31+
to the program, as they are needed to authenticate to the API.
32+
33+
## maven command-line - on Windows
34+
35+
On Windows the `spring-boot.run.jvmArguments` part needs to be surrounded by quotes
36+
37+
Replace the placeholders with your account details.
38+
39+
`mvn -pl tado-demo -am spring-boot:run -D"spring-boot.run.jvmArguments"="-Dtado.username=<username> -Dtado.password=<password>"`
40+
41+
## maven command-line - non-Windows
42+
43+
Replace the placeholders with your account details.
44+
45+
`mvn -pl tado-demo -am spring-boot:run -Dspring-boot.run.jvmArguments="-Dtado.username=<username> -Dtado.password=<password>"`
46+
47+
## IntelliJ
48+
49+
Navigate to tado-demo > src > main > java > tadodemo > Application and run
50+
the `main` method.
51+
52+
The first run will be unsuccessful as you will be missing some necessary
53+
arguments. Edit the run configuration and add this part to the VM options
54+
(replace the placeholders with your account details):
55+
56+
`-Dtado.username=<username> -Dtado.password=<password>`
57+
58+
## `useWindowsKeystore` option
59+
60+
This application is developed on a company managed Windows machine,
61+
where the company manages the certificates in the Windows keystore.
62+
63+
This set-up requires that some specific system properties need to be set to instruct
64+
the program to use the Windows keystore instead of the Java one.
65+
66+
When you happen to be in a similar situation, you can add this extra JVM argument:
67+
68+
`-DuseWindowsKeystore=true`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# OpenAPI Generator Ignore
2+
3+
# Use this file to prevent files from being overwritten by the generator.
4+
# The patterns follow closely to .gitignore or .dockerignore.
5+
6+
pom.xml
7+
README.md

generated-tado-api-client/pom.xml

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>nl.kritsel</groupId>
9+
<artifactId>tado-api-demo-java</artifactId>
10+
<version>1.0-SNAPSHOT</version>
11+
</parent>
12+
13+
<artifactId>generated-tado-api-client</artifactId>
14+
<packaging>jar</packaging>
15+
16+
<properties>
17+
<generated.src.folder>generated-src</generated.src.folder>
18+
</properties>
19+
20+
<build>
21+
<sourceDirectory>${generated.src.folder}/main/java</sourceDirectory>
22+
<plugins>
23+
<plugin>
24+
<groupId>org.openapitools</groupId>
25+
<artifactId>openapi-generator-maven-plugin</artifactId>
26+
<version>7.7.0</version>
27+
<executions>
28+
<execution>
29+
<goals>
30+
<goal>generate</goal>
31+
</goals>
32+
<!-- supported configuration properties documentation:
33+
https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator-maven-plugin -->
34+
<configuration>
35+
<!-- the essentials -->
36+
<inputSpec>https://raw.githubusercontent.com/kritsel/tado-openapispec-v2/v2.2024.08.01.3/tado-openapispec-v2.yaml</inputSpec>
37+
<generatorName>java</generatorName>
38+
<library>restclient</library>
39+
40+
<!-- when to generate -->
41+
<skipIfSpecIsUnchanged>true</skipIfSpecIsUnchanged>
42+
43+
<!-- where to generate to -->
44+
<output>${project.basedir}/</output>
45+
46+
<!-- naming preferences -->
47+
<apiNameSuffix>tado</apiNameSuffix>
48+
49+
<!-- java generator does not use 'packageName'
50+
need to define the other package options instead -->
51+
<apiPackage>tadoclient</apiPackage>
52+
<modelPackage>tadoclient</modelPackage>
53+
<invokerPackage>tadoclient</invokerPackage>
54+
55+
<!-- prevent generation of files we don't use -->
56+
<generateModelTests>false</generateModelTests>
57+
<generateApiTests>false</generateApiTests>
58+
<generateModelDocumentation>false</generateModelDocumentation>
59+
<generateApiDocumentation>false</generateApiDocumentation>
60+
61+
<!-- java generator specific configOptions documentation:
62+
https://openapi-generator.tech/docs/generators/java -->
63+
<configOptions>
64+
<sourceFolder>${generated.src.folder}/main/java</sourceFolder>
65+
</configOptions>
66+
67+
<!-- use java.time.LocalDateTime instead of java.time.OffsetDateTime -->
68+
<typeMappings>
69+
<typeMapping>DateTime=java.time.LocalDateTime</typeMapping>
70+
</typeMappings>
71+
</configuration>
72+
</execution>
73+
</executions>
74+
</plugin>
75+
76+
<!-- ensure all generated files get removed when executing mvn clean -->
77+
<plugin>
78+
<artifactId>maven-clean-plugin</artifactId>
79+
<version>3.0.0</version>
80+
<configuration>
81+
<filesets>
82+
<fileset>
83+
<!-- make sure to keep the files we maintain ourselves -->
84+
<directory>./</directory>
85+
<excludes>
86+
<exclude>pom.xml</exclude>
87+
<exclude>README.md</exclude>
88+
<exclude>.openapi-generator-ignore</exclude>
89+
</excludes>
90+
</fileset>
91+
</filesets>
92+
</configuration>
93+
</plugin>
94+
</plugins>
95+
</build>
96+
97+
<dependencies>
98+
<dependency>
99+
<groupId>org.openapitools</groupId>
100+
<artifactId>jackson-databind-nullable</artifactId>
101+
<version>0.2.6</version>
102+
</dependency>
103+
</dependencies>
104+
105+
</project>

pom.xml

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>org.springframework.boot</groupId>
9+
<artifactId>spring-boot-starter-parent</artifactId>
10+
<version>3.3.2</version>
11+
<relativePath/>
12+
</parent>
13+
14+
<groupId>nl.kritsel</groupId>
15+
<artifactId>tado-api-demo-java</artifactId>
16+
<version>1.0-SNAPSHOT</version>
17+
<packaging>pom</packaging>
18+
19+
<modules>
20+
<module>tado-demo</module>
21+
<module>generated-tado-api-client</module>
22+
<module>generated-tado-api-client</module>
23+
<module>tado-demo</module>
24+
</modules>
25+
26+
<properties>
27+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
28+
<java.version>21</java.version>
29+
<spring.boot.version>3.3.2</spring.boot.version>
30+
</properties>
31+
32+
<repositories>
33+
<repository>
34+
<id>mavenCentral</id>
35+
<url>https://repo1.maven.org/maven2/</url>
36+
</repository>
37+
</repositories>
38+
39+
<build>
40+
<sourceDirectory>src/main/java</sourceDirectory>
41+
<plugins>
42+
<plugin>
43+
<artifactId>maven-compiler-plugin</artifactId>
44+
<version>3.8.1</version>
45+
<configuration>
46+
<source>21</source>
47+
<target>21</target>
48+
</configuration>
49+
</plugin>
50+
<plugin>
51+
<groupId>org.springframework.boot</groupId>
52+
<artifactId>spring-boot-maven-plugin</artifactId>
53+
<configuration>
54+
<skip>true</skip>
55+
</configuration>
56+
<executions>
57+
<execution>
58+
<goals>
59+
<goal>repackage</goal>
60+
</goals>
61+
</execution>
62+
</executions>
63+
</plugin>
64+
</plugins>
65+
</build>
66+
67+
<dependencies>
68+
<!-- JUnit -->
69+
<dependency>
70+
<groupId>org.junit.jupiter</groupId>
71+
<artifactId>junit-jupiter-engine</artifactId>
72+
<version>5.10.0</version>
73+
<scope>test</scope>
74+
</dependency>
75+
76+
<!-- Spring boot -->
77+
<dependency>
78+
<groupId>org.springframework.boot</groupId>
79+
<artifactId>spring-boot-starter-web</artifactId>
80+
<version>${spring.boot.version}</version>
81+
</dependency>
82+
83+
</dependencies>
84+
85+
</project>

tado-demo/pom.xml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<parent>
7+
<groupId>nl.kritsel</groupId>
8+
<artifactId>tado-api-demo-java</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>tado-demo</artifactId>
13+
<packaging>jar</packaging>
14+
15+
<dependencies>
16+
<dependency>
17+
<groupId>nl.kritsel</groupId>
18+
<artifactId>generated-tado-api-client</artifactId>
19+
<version>${project.version}</version>
20+
</dependency>
21+
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter-oauth2-client</artifactId>
25+
<version>3.3.2</version>
26+
</dependency>
27+
</dependencies>
28+
29+
<build>
30+
<plugins>
31+
<plugin>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-maven-plugin</artifactId>
34+
<configuration>
35+
<skip>false</skip>
36+
<addResources>true</addResources>
37+
<mainClass>tadodemo.Application</mainClass>
38+
</configuration>
39+
<executions>
40+
<execution>
41+
<goals>
42+
<goal>repackage</goal>
43+
</goals>
44+
</execution>
45+
</executions>
46+
</plugin>
47+
48+
</plugins>
49+
</build>
50+
51+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package tadodemo;
2+
3+
import org.springframework.boot.ApplicationArguments;
4+
import org.springframework.boot.ApplicationRunner;
5+
import org.springframework.stereotype.Component;
6+
7+
@Component
8+
public class AppStartupRunner implements ApplicationRunner {
9+
10+
private TadoApiDemo tadoApiDemo;
11+
12+
AppStartupRunner(final TadoApiDemo tadoApiDemo) {
13+
this.tadoApiDemo = tadoApiDemo;
14+
15+
}
16+
@Override
17+
public void run(ApplicationArguments args) throws Exception {
18+
tadoApiDemo.doIt();
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package tadodemo;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication
11+
.run(Application.class, args)
12+
.close();
13+
}
14+
}

0 commit comments

Comments
 (0)