Skip to content

Commit

Permalink
Adapt to new auth flow
Browse files Browse the repository at this point in the history
  • Loading branch information
seime committed Jul 4, 2024
1 parent 0dcd06b commit 8d108a2
Show file tree
Hide file tree
Showing 12 changed files with 536 additions and 127 deletions.
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@
</repository>
</repositories>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.17.2</version>
</dependency>
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
<version>0.3.0</version>
</dependency>

<dependency>
<groupId>org.openhab.osgiify</groupId>
<artifactId>io.socket.engine.io-client</artifactId>
Expand Down
3 changes: 1 addition & 2 deletions src/main/feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<feature>openhab-runtime-base</feature>
<bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.okhttp/3.8.1_1</bundle>
<bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.okio/1.13.0_1</bundle>
<!-- <bundle dependency="true">mvn:org.openhab.osgiify/io.socket.socket.io-client/1.0.1</bundle>
<bundle dependency="true">mvn:org.openhab.osgiify/io.socket.engine.io-client/1.0.1</bundle> -->
<!--<bundle dependency="false">mvn:org.jspecify/jspecify/0.3.0</bundle> -->
<bundle dependency="true">mvn:org.json/json/20180813</bundle>
<bundle start-level="80">mvn:org.openhab.addons.bundles/no.seime.openhab.binding.panasoniccomfortcloud/${project.version}</bundle>
</feature>
Expand Down
2 changes: 2 additions & 0 deletions src/main/history/dependencies.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
<bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.okio/1.13.0_1</bundle>
<bundle>mvn:org.json/json/20180813</bundle>
<bundle>mvn:org.json/json/20180813</bundle>
<bundle>mvn:org.jsoup/jsoup/1.17.2</bundle>
<bundle>mvn:org.openhab.addons.bundles/no.seime.openhab.binding.panasoniccomfortcloud/4.1.0-SNAPSHOT</bundle>
<bundle>mvn:org.openhab.osgiify/io.socket.engine.io-client/1.0.1</bundle>
<bundle>mvn:org.openhab.osgiify/io.socket.socket.io-client/1.0.1</bundle>
<bundle>wrap:mvn:com.squareup.okio/okio/1.13.0</bundle>
<bundle>wrap:mvn:org.jspecify/jspecify/0.3.0</bundle>
<bundle>wrap:mvn:org.lastnpe.eea/eea-all/2.2.1</bundle>
</feature>
</features>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public class AccountConfiguration extends Configuration {
@Nullable
public String password;

@Nullable
public String appVersion;
public String appVersion = "1.21.0";

public int refreshInterval = 120;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package no.seime.openhab.binding.panasoniccomfortcloud.internal.dto;

public class GetAccClientIdDTO {
public int language = 0;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package no.seime.openhab.binding.panasoniccomfortcloud.internal.dto;

public class LoginRequestDTO {

public String client_id;
public String redirect_uri;
public String tenant;
public String response_type;
public String scope;
public String audience;
public String _csrf;
public String state;
public String _intstate;
public String username;
public String password;
public String lang;
public String connection;
}

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/resources/OH-INF/config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ https://openhab.org/schemas/config-description-1.0.0.xsd">
</parameter>
<parameter name="appVersion" type="text" required="false">
<label>App version</label>
<description>Your Panasonic Comfort Cloud app version code, ie '1.20.0'. You can find this information in the apps
<description>Your Panasonic Comfort Cloud app version code, ie '1.21.0'. You can find this information in the apps
section of your mobile phone. If no value provided, it will use the current binding default.
</description>
<default>1.20.0</default>
<default>1.21.0</default>
</parameter>

<parameter name="refreshInterval" type="integer" min="30" unit="s">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package no.seime.openhab.binding.panasoniccomfortcloud.internal;

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

import java.security.NoSuchAlgorithmException;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.openhab.core.storage.Storage;
import org.openhab.core.test.storage.VolatileStorage;

import com.google.gson.reflect.TypeToken;

import no.seime.openhab.binding.panasoniccomfortcloud.internal.dto.GetGroupsRequest;
import no.seime.openhab.binding.panasoniccomfortcloud.internal.dto.GetGroupsResponse;

@ExtendWith(MockitoExtension.class)
public class APIClientTest {

private Storage storage = new VolatileStorage();

// Disabled - must have credentials to run
// @Test
public void test() throws PanasonicComfortCloudException {
ApiBridge apiBridge = new ApiBridge(storage);

String username = "FILL IN USERNAME TO TEST";
String password = "FILL IN PASSWORD TO TEST";

apiBridge.init(username, password, "1.20.0");
apiBridge.sendRequest(new GetGroupsRequest(), new TypeToken<GetGroupsResponse>() {
}.getType());
}

@Test
public void testSha256() throws NoSuchAlgorithmException {
String hash = ApiBridge.generateHash("XZlJsY7dnp32w4KCC39xehdfsENsR265TjzHGQoePVP");
assertEquals("TeFR13C1atlTUPWD1G9NdFCwvNC0Z0yOb7oVI8yjzvk", hash);
}

@Test
public void testGenerateRandom() {
String random = ApiBridge.generateRandomString(20);
assertEquals(20, random.length());
}

@Test
public void testGenerateRandomHexString() {
int length = "B7d80fb2bc3faE769b89Bf4EC9C4729eCfe690C1CbBa7c42a40A062dc2f4f3671daAaFF1Cf6777cdC23dfcfFfa6DabdDec825c8b0BfB2EFDe04FCE17Bb5e086e"
.length();
String random = ApiBridge.generateRandomStringHex(length);
assertEquals(length, random.length());
}
}
18 changes: 18 additions & 0 deletions src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<logger name="no.seime.openhab.binding" level="TRACE" additivity="false">
<appender-ref ref="STDOUT"/>
</logger>

<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>
</configuration>

0 comments on commit 8d108a2

Please sign in to comment.