diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 4b1e82997..000000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,35 +0,0 @@ -# This workflow will build a Java project with Maven -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven - -name: Java CI with Maven and Deploy - -on: - push: - branches: [ master ] - -permissions: - packages: write - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: '11' - architecture: x64 - - name: Setup git profile - run: | - git config --global user.name "github-actions[bot]" - git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" - - name: Publish Snapshot to GitHub Packages - run: mvn deploy -B - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Publish site - run: mvn -B site-deploy -Dusername=github-actions -Dpassword=${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml deleted file mode 100644 index 6f597043c..000000000 --- a/.github/workflows/maven.yml +++ /dev/null @@ -1,24 +0,0 @@ -# This workflow will build a Java project with Maven -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven - -name: Java CI with Maven - -on: - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: '11' - architecture: x64 - - name: Build with Maven - run: mvn -B package --file pom.xml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 380426925..000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,38 +0,0 @@ -# This workflow will build a Java project with Maven -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven - -name: Stage Release on Master Branch - -on: - workflow_dispatch: - inputs: - releaseVersion: - description: Version to release - required: true - -permissions: - contents: write - packages: write - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - uses: git-actions/set-user@v1 - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - distribution: 'zulu' - java-version: '11' - architecture: x64 - - name: Setup git profile - run: | - git config --global user.name "github-actions[bot]" - git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" - - name: Maven release - run: mvn release:prepare release:perform -B -DreleaseVersion=${{ github.event.inputs.releaseVersion }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 985e13a79..000000000 --- a/.gitignore +++ /dev/null @@ -1,30 +0,0 @@ -*.class - -# Mobile Tools for Java (J2ME) -.mtj.tmp/ - -# Package Files # -*.jar -*.war -*.ear - -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml -hs_err_pid* - -# Eclipse files -.classpath -.project -.settings/ - -# Maven target folder -target/ - -# Mac Files -.DS_Store - -# IntelliJ -**/.idea/ -**/*.iml - -# Log files -*.log diff --git a/CHANGES.md b/CHANGES.md deleted file mode 100644 index 8da353402..000000000 --- a/CHANGES.md +++ /dev/null @@ -1,96 +0,0 @@ -# HAP-Java 2.0.8 -* Updated bouncy castle to 1.83 -* Updated netty to 4.1.126.Final - -# HAP-Java 2.0.7 -* Add overloads to characteristics so that the username can be passed through. - -# HAP-Java 2.0.6 -* Several methods allowing library users to manipulate characteristics themselves -* Allow library users to provider their own implementation of AccessoryInformationService -* Fix ProgrammableSwitchEventEnum that has an incorrect value - -# HAP-Java 2.0.5 -* Implement List-Pairings method. Compatibility with new Home infrastructure from iOS 16.2? - -# HAP-Java 2.0.3 -* Avoid unnecessary forced disconnects. Library users should be updating the configuration index anyway. - -# HAP-Java 2.0.2 - * Various minor stability issues for after an accessory has been removed. - -# HAP-Java 2.0.1 -## Fixes -* Log accessory names instead of futures. [#150](https://github.com/hap-java/HAP-Java/issues/150) -* Fix rotation speed data type (BREAKING API CHANGE). According to HAP specification it must be float -* Close JsonWriters [#149](https://github.com/hap-java/HAP-Java/issues/149) -* Fix UUID of HAP Version characteristic -* Add Mute characteristic to Doorbell service - -## New -* New characteristics: - * Identifier - * Input Device Type - * Input Source Type - * Configured Name - * Current Visibility State - * Target Visibility State - * Sleep Discovery Mode - * Active Identifier - * Closed Captions - * Current Media State - * Target Media State - * Picture Mode - * Power Mode - * Remote Key - * Volume Control Type - * Volume Selector - * AirPlay Enable - -* New services - * Input Source - * Television - * Television Speaker - * Smart Speaker - -# HAP-Java 2.0.0 -* major refactoring to support optional characteristics -* structure and names adapted to HAP spec structure and naming. -* structure is following - * `accessory` package include basis accessory as the listed in HAP spec, plus interfaces for optional characteristics. clients should extend the accessory classes. e.g. `WindowCoveringAccessory` or `AccessoryWithBrightness` - * `characteristics` package consists of all characteristics, optional and mandatory. e.g. `TargetHorizontalTiltAngleCharacteristic`. The naming is done in accordance to HAP spec. - * `services` package consists of services, which grouping characteristics. e.g. `WindowCoveringService` defines mandatory and optional characteristics for a window covering service as it is defined in HAP spec. - * `server` package consists classes to run HomeKit server and handle communication -* the process is following: client, e.g. openHAB bindings, extends accessory classes, e.g. `WindowCoveringAccessory` and implements all required methods. WindowCoveringAccessory is linked already to WindowCoveringService, that in turn is link to single characteristics. -* linked service support - -## New and improved - -* Valid values are supported for enum characteristics instead of min and max values -* Supported valid states for Thermostat, SecuritySystem, HeaterCooler and HumidifierDehumidifier [#108] [#120](https://github.com/hap-java/HAP-Java/pull/120) -* Support for FilterMaintenance. Can be used as a linked service for an Air Purifier [#124](https://github.com/hap-java/HAP-Java/pull/124) - -## Fixes - -* Fix for re-advertising service when using alternative jMDNS implementations. - -# HAP-Java 1.1.5 - -## Fixes - -* `null` values are now allowed, since Homekit allows them. -* `SecuritySystemAlarmType` and `TargetSecuritySystemState` now match the Homekit documentation [#44](https://github.com/hap-java/HAP-Java/pull/44) [#45](https://github.com/hap-java/HAP-Java/pull/45) -* Null pointer exception no longer thrown if a characteristic is not implemented [#32](https://github.com/hap-java/HAP-Java/issues/32) -* Fixed incorrect support for BatteryLevel in battery-powered accessories. Appropriate characteristic is battery status. [#50](https://github.com/hap-java/HAP-Java/pull/50) -* Clear all connections in SessionManager during HomekitRoot.stop() [#54](https://github.com/hap-java/HAP-Java/issues/54) -* Fix issue in which communications would drop when encrypted frames didn't line up with network frames [#64](https://github.com/hap-java/HAP-Java/pull/64) -* Fix various spec violations and optimize communications to improve performance [#65](https://github.com/hap-java/HAP-Java/pull/65) -* Fix a pairing issue in which HAP-Java could listen on a different interface than that which it advertises [#67](https://github.com/hap-java/HAP-Java/pull/67) -* Allow window covering to be used without optional characteristics. The inclusion of `HoldPositionCharacteristic` did terrible things, and we're still not sure why. Addressed [#56](https://github.com/hap-java/HAP-Java/pull/56) -* Air Purifier didn't support rotation speed characteristics. [#124](https://github.com/hap-java/HAP-Java/pull/124) - -## New and improved - -* Occupancy sensor support [#59](https://github.com/hap-java/HAP-Java/pull/59) -* Leak sensors and valve support added [#52](https://github.com/hap-java/HAP-Java/pull/52) -* Notifications are batched now, when possible [#66](https://github.com/hap-java/HAP-Java/pull/66) diff --git a/LICENSE b/LICENSE index a56ce6c55..5e566f239 100644 --- a/LICENSE +++ b/LICENSE @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - diff --git a/PULL_REQUEST_TEMPLATE.md b/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index d20a2d17c..000000000 --- a/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,8 +0,0 @@ -# Pull Request Checklist - -Please confirm that you've done the following when opening a new pull request: - - - [ ] For fixes and other improvements, please reference the GitHub issue that your change addresses. - - [ ] For fixes, optimizations and new features, please add an entry to the CHANGES.md file. - - [ ] Run mvn compile before committing, so that the auto-code formatter will format your changes consistently with the rest of the project. - diff --git a/README.md b/README.md index 6d1f88458..5ebd1ed0f 100644 --- a/README.md +++ b/README.md @@ -1,83 +1,7 @@ -HAP-Java +HAP-Java-Sample ========= -[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.hap-java/hap/badge.svg)](https://search.maven.org/search?q=g:io.github.hap-java%20a:hap) -[![MIT License](https://img.shields.io/github/license/hap-java/HAP-Java)](https://github.com/hap-java/HAP-Java/blob/master/LICENSE) -![Maven Build Status](https://github.com/andylintner/HAP-Java/actions/workflows/maven.yml/badge.svg) +A sample implementation of a simple accessory using [HAP-Java](https://github.com/beowulfe/HAP-Java). -HAP-Java is a Java implementation of the HomeKit Accessory Protocol. - -Using this library, you can create your own HomeKit Accessory or HomeKit Accessory Bridge. - -This library would not have been possible without [Tian Zhang](https://github.com/KhaosT) who did a lot of the hard work of figuring out how the protocol works in his NodeJS implementation. - -Usage -========= -Include HAP-Java in your project using maven: - -``` - - io.github.hap-java - hap - 2.0.1-SNAPSHOT - -``` - -After that, check out the [Sample](https://github.com/hap-java/HAP-Java/tree/sample) and -read the [Javadoc](https://hap-java.github.io/HAP-Java/apidocs/index.html) - -Supported HomeKit Accessories -========= - -Current implementation fully supports 42 HomeKit accessory/services. - -| HomeKit Accessory & Service type | Supported by Java-HAP | -|--------------------|--------------------| -| Accessory Information | :white_check_mark: | -| Air Purifier | :white_check_mark: | -| Air Quality Sensor | :white_check_mark: | -| Audio Stream Management | :x: | -| Battery Service | :white_check_mark: | -| Camera RTP Stream Management | :x: | -| Carbon Dioxide Sensor | :white_check_mark: | -| Carbon Monoxide Sensor | :white_check_mark: | -| Contact Sensor | :white_check_mark: | -| Data Stream Transport Management | :x: | -| Door | :white_check_mark: | -| Doorbell | :white_check_mark: | -| Fan | :white_check_mark: | -| Faucet | :white_check_mark: | -| Filter Maintenance | :white_check_mark: | -| Garage Door Opener | :white_check_mark: | -| HAP Protocol Information | :white_check_mark: | -| Heater Cooler | :white_check_mark: | -| Humidifier Dehumidifier | :white_check_mark: | -| Humidity Sensor | :white_check_mark: | -| Input Source | :white_check_mark: | -| Irrigation System | :white_check_mark: | -| Leak Sensor | :white_check_mark: | -| Light Bulb | :white_check_mark: | -| Light Sensor | :white_check_mark: | -| Lock Management | :x: | -| Lock Mechanism | :white_check_mark: | -| Microphone | :white_check_mark: | -| Motion Sensor | :white_check_mark: | -| Occupancy Sensor | :white_check_mark: | -| Outlet | :white_check_mark: | -| Security System | :white_check_mark: | -| Service Label | :white_check_mark: | -| Siri | :x: | -| Slat | :white_check_mark: | -| Smart Speaker | :white_check_mark: | -| Smoke Sensor | :white_check_mark: | -| Speaker | :white_check_mark: | -| Stateless Programmable Switch | :white_check_mark: | -| Switch | :white_check_mark: | -| Target Control | :x: | -| Target Control Management | :x: | -| Television | :white_check_mark: | -| Television Speaker | :white_check_mark: | -| Temperature Sensor | :white_check_mark: | -| Thermostat | :white_check_mark: | -| Valve | :white_check_mark: | -| Window | :white_check_mark: | -| Window Covering | :white_check_mark: | \ No newline at end of file +This is for demonstration purposes only. The persistence implementation is very primitive and should not be used except +for convenience in testing purposes, so information between app launches will maintain pairing information with the iOS +devices. Persisted data is written to a file `auth-state.bin` in the current working directory. diff --git a/RELEASING.md b/RELEASING.md deleted file mode 100644 index 6dd790693..000000000 --- a/RELEASING.md +++ /dev/null @@ -1,7 +0,0 @@ -# How to release HAP-Java - -These actions can only be performed by someone with maintainer level access to the repository. - -1. Run the [Stage Release on Master Branch](https://github.com/hap-java/HAP-Java/actions/workflows/release.yml) Action with a version such as `2.0.2` -2. After this completes, find the release on the [Releases page](https://github.com/hap-java/HAP-Java/releases) -3. Edit the release to include the changelog details diff --git a/pom.xml b/pom.xml index c292424af..13ae12f91 100644 --- a/pom.xml +++ b/pom.xml @@ -1,364 +1,67 @@ - - 4.0.0 - io.github.hap-java - hap - hap-java - Homekit Accessory Protocol for Java - 2.0.9-SNAPSHOT - jar - https://github.com/hap-java/HAP-Java - - - UTF-8 - 4.1.126.Final - - - - - MIT License - http://www.opensource.org/licenses/mit-license.php - repo - - - - - scm:git:https://github.com/hap-java/HAP-Java.git - scm:git:https://github.com/hap-java/HAP-Java.git - https://github.com/hap-java/HAP-Java.git - HEAD - - - - - Andy Lintner - dev@beowulfe.com - https://github.com/beowulfe - - - Cody Cutrer - cody@cutrer.us - https://github.com/ccutrer - - - Tim Harper - timcharper@gmail.com - https://github.com/timcharper - - - - - - - org.slf4j - slf4j-api - 1.7.10 - - - - io.netty - netty-common - ${netty.version} - - - - io.netty - netty-buffer - ${netty.version} - - - - io.netty - netty-transport - ${netty.version} - - - - io.netty - netty-handler - ${netty.version} - - - - io.netty - netty-codec - ${netty.version} - - - - io.netty - netty-codec-http - ${netty.version} - - - - io.netty - netty-resolver - ${netty.version} - - - - com.nimbusds - srp6a - 1.5.2 - - - - org.bouncycastle - bcpkix-jdk18on - 1.83 - - - - org.bouncycastle - bctls-jdk18on - 1.82 - - - - net.vrallev.ecc - ecc-25519-java - 1.0.1 - - - - org.zeromq - curve25519-java - 0.1.0 - - - - javax.json - javax.json-api - 1.0 - - - - org.glassfish - javax.json - 1.0.4 - - - - org.jmdns - jmdns - 3.5.6 - - - - junit - junit - 4.13.1 - test - - - - org.mockito - mockito-core - 3.8.0 - test - - - - org.assertj - assertj-core - 3.27.7 - test - - - - - + 4.0.0 + com.beowulfe.hap + hap-sample + 0.0.2-SNAPSHOT + hap-java-sample + + + io.github.hap-java + hap + 2.0.1-snapshot + + + ch.qos.logback + logback-classic + 1.0.13 + + + com.google.zxing + core + 3.4.1 + + + + - - com.coveo - fmt-maven-plugin - 2.9 - - - - format - - - - org.apache.maven.plugins maven-compiler-plugin - 3.8.0 + 2.1 1.8 1.8 + org.apache.maven.plugins - maven-source-plugin - 3.0.1 - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.2.0 + maven-jar-plugin + 3.1.0 - io.github.hapjava.server.impl - 8 + + + true + lib/ + com.beowulfe.hap.sample.Main + + - - - attach-javadocs - - jar - - - - org.apache.maven.plugins - maven-scm-publish-plugin - 3.1.0 + maven-dependency-plugin - scm-publish - site-deploy + install - publish-scm + copy-dependencies - scm:git:https://github.com/hap-java/HAP-Java.git - gh-pages - - - - - - org.apache.maven.plugins - maven-site-plugin - 3.7.1 - - - stage-for-scm-publish - post-site - - stage - - - false + ${project.build.directory}/lib - - - - - org.apache.maven.plugins - maven-site-plugin - - true - - - - - - - - - website - https://hap-java.github.io/ - - - github - https://maven.pkg.github.com/hap-java/HAP-Java - - - github - https://maven.pkg.github.com/hap-java/HAP-Java - - - - - - - org.apache.maven.plugins - maven-pmd-plugin - 3.6 - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.0.1 - - io.github.hapjava.server.impl - 8 - false - - - - - javadoc - - - - - - org.codehaus.mojo - findbugs-maven-plugin - 3.0.3 - - - - - - - ossrh - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.5 - - - sign-artifacts - verify - - sign - - - - - HAP-Java - - --pinentry-mode - loopback - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.3 - true - - ossrh - https://s01.oss.sonatype.org/ - true - - - - - - - diff --git a/src/main/java/com/beowulfe/hap/sample/AuthState.java b/src/main/java/com/beowulfe/hap/sample/AuthState.java new file mode 100644 index 000000000..1cca02778 --- /dev/null +++ b/src/main/java/com/beowulfe/hap/sample/AuthState.java @@ -0,0 +1,24 @@ +package com.beowulfe.hap.sample; + +import java.io.Serializable; +import java.math.BigInteger; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +class AuthState implements Serializable { + private static final long serialVersionUID = 1L; + String PIN; + final String mac; + final BigInteger salt; + final byte[] privateKey; + final String setupId; + final ConcurrentMap userKeyMap = new ConcurrentHashMap<>(); + + public AuthState(String _PIN, String _mac, BigInteger _salt, byte[] _privateKey, String _setupId) { + PIN = _PIN; + salt = _salt; + privateKey = _privateKey; + mac = _mac; + setupId = _setupId; + } +} \ No newline at end of file diff --git a/src/main/java/com/beowulfe/hap/sample/Main.java b/src/main/java/com/beowulfe/hap/sample/Main.java new file mode 100644 index 000000000..02438e2c5 --- /dev/null +++ b/src/main/java/com/beowulfe/hap/sample/Main.java @@ -0,0 +1,68 @@ +package com.beowulfe.hap.sample; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import io.github.hapjava.server.impl.HomekitRoot; +import io.github.hapjava.server.impl.HomekitServer; +import io.github.hapjava.server.impl.crypto.HAPSetupCodeUtils; + +public class Main { + + private static final int PORT = 9123; + + public static void main(String[] args) { + try { + File authFile = new File("auth-state.bin"); + MockAuthInfo mockAuth; + if (authFile.exists()) { + FileInputStream fileInputStream = new FileInputStream(authFile); + ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream); + try { + System.out.println("Using persisted auth"); + AuthState authState = (AuthState) objectInputStream.readObject(); + mockAuth = new MockAuthInfo(authState); + } finally { + objectInputStream.close(); + } + } else { + mockAuth = new MockAuthInfo(); + } + + HomekitServer homekit = new HomekitServer(PORT); + HomekitRoot bridge = homekit.createBridge(mockAuth, "Test Bridge", "TestBridge, Inc.", "G6", "111abe234", "1.1", "1.2"); + + String setupURI = HAPSetupCodeUtils.getSetupURI(mockAuth.getPin().replace("-",""), mockAuth.getSetupId(), 2); + QRtoConsole.printQR(setupURI); + + + mockAuth.onChange(state -> { + try { + System.out.println("State has changed! Writing"); + FileOutputStream fileOutputStream = new FileOutputStream(authFile); + ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream); + objectOutputStream.writeObject(state); + objectOutputStream.flush(); + objectOutputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + }); + bridge.addAccessory(new MockSwitch()); + bridge.start(); + + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + System.out.println("Stopping homekit server."); + homekit.stop(); + })); + + } catch (Exception e) { + e.printStackTrace(); + } + + } + +} diff --git a/src/main/java/com/beowulfe/hap/sample/MockAuthInfo.java b/src/main/java/com/beowulfe/hap/sample/MockAuthInfo.java new file mode 100644 index 000000000..f0b667f16 --- /dev/null +++ b/src/main/java/com/beowulfe/hap/sample/MockAuthInfo.java @@ -0,0 +1,98 @@ +package com.beowulfe.hap.sample; + +import java.math.BigInteger; +import java.security.InvalidAlgorithmParameterException; +import java.util.function.Consumer; + +import io.github.hapjava.server.HomekitAuthInfo; +import io.github.hapjava.server.impl.HomekitServer; +import io.github.hapjava.server.impl.crypto.HAPSetupCodeUtils; + +/** + * This is a simple implementation that should never be used in actual production. The mac, salt, and privateKey + * are being regenerated every time the application is started. The user store is also not persisted. This means pairing + * needs to be re-done every time the app restarts. + * + * @author Andy Lintner + */ +public class MockAuthInfo implements HomekitAuthInfo { + + private final AuthState authState; + + Consumer callback; + + public MockAuthInfo() throws InvalidAlgorithmParameterException { + this(new AuthState("031-45-154", HomekitServer.generateMac(), HomekitServer.generateSalt(), + HomekitServer.generateKey(), HAPSetupCodeUtils.generateSetupId())); + } + + public MockAuthInfo(AuthState _authState) { + authState = _authState; + System.out.println("The PIN for pairing is " + authState.PIN); + } + + @Override + public String getPin() { + return authState.PIN; + } + + @Override + public String getMac() { + return authState.mac; + } + + @Override + public BigInteger getSalt() { + return authState.salt; + } + + @Override + public byte[] getPrivateKey() { + return authState.privateKey; + } + + @Override + public String getSetupId() { + return authState.setupId; + } + + @Override + public void createUser(String username, byte[] publicKey) { + if (!authState.userKeyMap.containsKey(username)) { + authState.userKeyMap.putIfAbsent(username, publicKey); + System.out.println("Added pairing for " + username); + notifyChange(); + } else { + System.out.println("Already have a user for " + username); + } + } + + @Override + public void removeUser(String username) { + authState.userKeyMap.remove(username); + System.out.println("Removed pairing for " + username); + notifyChange(); + } + + @Override + public byte[] getUserPublicKey(String username) { + return authState.userKeyMap.get(username); + } + + public void onChange(Consumer _callback) { + callback = _callback; + notifyChange(); + } + + private void notifyChange() { + if (callback != null) { + callback.accept(authState); + } + } + @Override + public boolean hasUser() { + return !authState.userKeyMap.isEmpty(); + } + + +} diff --git a/src/main/java/com/beowulfe/hap/sample/MockSwitch.java b/src/main/java/com/beowulfe/hap/sample/MockSwitch.java new file mode 100644 index 000000000..5808976f7 --- /dev/null +++ b/src/main/java/com/beowulfe/hap/sample/MockSwitch.java @@ -0,0 +1,80 @@ +package com.beowulfe.hap.sample; + +import java.util.concurrent.CompletableFuture; + +import io.github.hapjava.accessories.LightbulbAccessory; +import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithHardwareRevision; +import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; + +public class MockSwitch implements LightbulbAccessory, AccessoryWithHardwareRevision { + + private boolean powerState = false; + private HomekitCharacteristicChangeCallback subscribeCallback = null; + + @Override + public int getId() { + return 2; + } + + @Override + public CompletableFuture getName() { + return CompletableFuture.completedFuture("Test Switch Name"); + } + + @Override + public void identify() { + System.out.println("Identifying light"); + } + + @Override + public CompletableFuture getSerialNumber() { + return CompletableFuture.completedFuture("Test SwitchSN"); + } + + @Override + public CompletableFuture getModel() { + return CompletableFuture.completedFuture("TestSwitch Model"); + } + + @Override + public CompletableFuture getManufacturer() { + return CompletableFuture.completedFuture("Test SwitchManufacturer"); + } + + @Override + public CompletableFuture getFirmwareRevision() { + return CompletableFuture.completedFuture("Test Switch Firmware"); + } + + @Override + public CompletableFuture getLightbulbPowerState() { + return CompletableFuture.completedFuture(powerState); + } + + @Override + public CompletableFuture setLightbulbPowerState(boolean powerState) + throws Exception { + this.powerState = powerState; + if (subscribeCallback != null) { + subscribeCallback.changed(); + } + System.out.println("The lightbulb is now "+(powerState ? "on" : "off")); + return CompletableFuture.completedFuture(null); + } + + @Override + public void subscribeLightbulbPowerState( + HomekitCharacteristicChangeCallback callback) { + this.subscribeCallback = callback; + } + + @Override + public void unsubscribeLightbulbPowerState() { + this.subscribeCallback = null; + } + + @Override + public CompletableFuture getHardwareRevision() { + return CompletableFuture.completedFuture("Test Switch Hardware"); + } +} diff --git a/src/main/java/com/beowulfe/hap/sample/QRtoConsole.java b/src/main/java/com/beowulfe/hap/sample/QRtoConsole.java new file mode 100644 index 000000000..a09c96144 --- /dev/null +++ b/src/main/java/com/beowulfe/hap/sample/QRtoConsole.java @@ -0,0 +1,47 @@ +package com.beowulfe.hap.sample; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.WriterException; +import com.google.zxing.common.BitMatrix; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ported code from https://github.com/gtanner/qrcode-terminal + */ +public class QRtoConsole { + private static final Logger logger = LoggerFactory.getLogger(QRtoConsole.class); + + private static final char WHITE_ALL = '\u2588'; + private static final char WHITE_BLACK = '\u2580'; + private static final char BLACK_WHITE = '\u2584'; + private static final char BLACK_ALL = ' '; + + + public static void printQR(String setupURI) { + try { + BitMatrix matrix = new MultiFormatWriter().encode( + setupURI, BarcodeFormat.QR_CODE, 10, + 30); + for(int y = 0; y < matrix.getHeight();y+=2) { + for(int x = 0; x < matrix.getWidth(); x++) { + boolean firstRow = matrix.get(x,y); + boolean secondRow = matrix.get(x,y+1); + if(firstRow && secondRow) { + System.out.print(BLACK_ALL); + } else if(firstRow) { + System.out.print(BLACK_WHITE); + } else if(secondRow) { + System.out.print(WHITE_BLACK); + } else { + System.out.print(WHITE_ALL); + } + } + System.out.println(); + } + } catch(WriterException e) { + logger.error("error creating qr code", e); + } + } +} diff --git a/src/main/java/io/github/hapjava/accessories/AirPurifierAccessory.java b/src/main/java/io/github/hapjava/accessories/AirPurifierAccessory.java deleted file mode 100644 index 3766f75a1..000000000 --- a/src/main/java/io/github/hapjava/accessories/AirPurifierAccessory.java +++ /dev/null @@ -1,86 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.airpurifier.CurrentAirPurifierStateEnum; -import io.github.hapjava.characteristics.impl.airpurifier.TargetAirPurifierStateEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.AirPurifierService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** An air purifier. */ -public interface AirPurifierAccessory extends HomekitAccessory { - /** - * Mandatory: Retrieves the current active state of the fan'. - * - * @return a future that will contain the binary state - */ - CompletableFuture isActive(); - - /** - * Sets the active state of the fan - * - * @param state the binary state to set - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setActive(boolean state) throws Exception; - - /** - * Subscribes to changes in the active state of the fan. - * - * @param callback the function to call when the direction changes. - */ - void subscribeActive(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the active state of the fan. */ - void unsubscribeActive(); - - /** - * Retrieves the current state of the air purifier - * - * @return a future that will contain the state - */ - CompletableFuture getCurrentState(); - - /** - * Subscribes to changes in the state of the air purifier. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the state of the air purifier. */ - void unsubscribeCurrentState(); - - /** - * Retrieves the air purifier target state. - * - * @return a future that will contain the air purifier target state . - */ - CompletableFuture getTargetState(); - - /** - * set target state the air purifier target state. - * - * @param state air purifier target state - * @return a future that completes when the change is made - */ - CompletableFuture setTargetState(TargetAirPurifierStateEnum state); - - /** - * Subscribes to changes in the target state of the air purifier. - * - * @param callback the function to call when the target state changes. - */ - void subscribeTargetState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the target state of the air purifier. */ - void unsubscribeTargetState(); - - @Override - default Collection getServices() { - return Collections.singleton(new AirPurifierService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/AirQualityAccessory.java b/src/main/java/io/github/hapjava/accessories/AirQualityAccessory.java deleted file mode 100644 index 309fb486e..000000000 --- a/src/main/java/io/github/hapjava/accessories/AirQualityAccessory.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.airquality.AirQualityEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.AirQualityService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** An air quality accessory which can include several sensors. */ -public interface AirQualityAccessory extends HomekitAccessory { - - /** - * Retrieves the state of the air quality - * - * @return a future that will contain the state - */ - CompletableFuture getAirQuality(); - - /** - * Subscribes to changes in the air quality - * - * @param callback the function to call when the air quality changes. - */ - void subscribeAirQuality(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the air quality. */ - void unsubscribeAirQuality(); - - @Override - default Collection getServices() { - return Collections.singleton(new AirQualityService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/BasicFanAccessory.java b/src/main/java/io/github/hapjava/accessories/BasicFanAccessory.java deleted file mode 100644 index 98c4bf497..000000000 --- a/src/main/java/io/github/hapjava/accessories/BasicFanAccessory.java +++ /dev/null @@ -1,46 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.BasicFanService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A fan with mandatory characteristics. - * - * @author Andy Lintner - */ -public interface BasicFanAccessory extends HomekitAccessory { - /** - * Mandatory: Retrieves the current power state of the fan. - * - * @return a future that will contain the binary state - */ - CompletableFuture isOn(); - - /** - * Sets the active state of the fan - * - * @param state the binary state to set - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setOn(boolean state) throws Exception; - - /** - * Subscribes to changes in the active state of the fan. - * - * @param callback the function to call when the active state changes. - */ - void subscribeOn(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the active state of the fan. */ - void unsubscribeOn(); - - @Override - default Collection getServices() { - return Collections.singleton(new BasicFanService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/BatteryAccessory.java b/src/main/java/io/github/hapjava/accessories/BatteryAccessory.java deleted file mode 100644 index d3724bc50..000000000 --- a/src/main/java/io/github/hapjava/accessories/BatteryAccessory.java +++ /dev/null @@ -1,74 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.battery.ChargingStateEnum; -import io.github.hapjava.characteristics.impl.battery.StatusLowBatteryEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.BatteryService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * Devices with battery . - * - * @author Gaston Dombiak - */ -public interface BatteryAccessory extends HomekitAccessory { - - /** - * Retrieves the battery level of the accessory. - * - * @return a future that will contain the accessory's battery state - */ - CompletableFuture getBatteryLevel(); - - /** - * Queries if the device battery level is low; returning a value of true will cause a low-battery - * status to appear in Home for the device. - * - * @return a future that will contain the accessory's low battery state - */ - CompletableFuture getLowBatteryState(); - - /** - * Retriece the battery charging state. - * - * @return a future that will contain the battery charging state - */ - CompletableFuture getChargingState(); - - /** - * Subscribes to changes in the battery level. - * - * @param callback the function to call when battery level changes. - */ - void subscribeBatteryLevel(HomekitCharacteristicChangeCallback callback); - /** - * Subscribes to changes in the battery level. - * - * @param callback the function to call when low battery state changes. - */ - void subscribeLowBatteryState(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the battery level. - * - * @param callback the function to call when low battery state changes. - */ - void subscribeBatteryChargingState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the battery level. */ - void unsubscribeBatteryLevel(); - - /** Unsubscribes from changes in the low battery state. */ - void unsubscribeLowBatteryState(); - - /** Unsubscribes from changes in the low battery state. */ - void unsubscribeBatteryChargingState(); - - @Override - default Collection getServices() { - return Collections.singleton(new BatteryService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/Bridge.java b/src/main/java/io/github/hapjava/accessories/Bridge.java deleted file mode 100644 index e53c427f2..000000000 --- a/src/main/java/io/github/hapjava/accessories/Bridge.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.github.hapjava.accessories; - -/** HomeKit bridge service. */ -public interface Bridge extends HomekitAccessory { - - @Override - default void identify() {} -} diff --git a/src/main/java/io/github/hapjava/accessories/CarbonDioxideSensorAccessory.java b/src/main/java/io/github/hapjava/accessories/CarbonDioxideSensorAccessory.java deleted file mode 100644 index 185aedd13..000000000 --- a/src/main/java/io/github/hapjava/accessories/CarbonDioxideSensorAccessory.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.carbondioxidesensor.CarbonDioxideDetectedEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.CarbonDioxideSensorService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** A carbon dioxide sensor reports carbon dioxide level. */ -public interface CarbonDioxideSensorAccessory extends HomekitAccessory { - - /** - * Retrieves the state of the sensor that indicates if carbon dioxide has been detected. - * - * @return a future that will contain the carbon dioxide sensor's state - */ - CompletableFuture getCarbonDioxideDetectedState(); - - /** - * Subscribes to changes in the carbon dioxide's state. - * - * @param callback the function to call when the state changes. - */ - void subscribeCarbonDioxideDetectedState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the carbon dioxide's state. */ - void unsubscribeCarbonDioxideDetectedState(); - - @Override - default Collection getServices() { - return Collections.singleton(new CarbonDioxideSensorService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/CarbonMonoxideSensorAccessory.java b/src/main/java/io/github/hapjava/accessories/CarbonMonoxideSensorAccessory.java deleted file mode 100644 index 93cfebbd6..000000000 --- a/src/main/java/io/github/hapjava/accessories/CarbonMonoxideSensorAccessory.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.carbonmonoxidesensor.CarbonMonoxideDetectedEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.CarbonMonoxideSensorService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A carbon monoxide sensor reports whether carbon monoxide has been detected or not. - * - * @author Gaston Dombiak - */ -public interface CarbonMonoxideSensorAccessory extends HomekitAccessory { - - /** - * Retrieves the state of the sensor that indicates if carbon monoxide has been detected. - * - * @return a future that will contain the carbon monoxide sensor's state - */ - CompletableFuture getCarbonMonoxideDetectedState(); - - /** - * Subscribes to changes in the carbon monoxide's state. - * - * @param callback the function to call when the state changes. - */ - void subscribeCarbonMonoxideDetectedState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the carbon monoxide's state. */ - void unsubscribeCarbonMonoxideDetectedState(); - - @Override - default Collection getServices() { - return Collections.singleton(new CarbonMonoxideSensorService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/ContactSensorAccessory.java b/src/main/java/io/github/hapjava/accessories/ContactSensorAccessory.java deleted file mode 100644 index 754f6981b..000000000 --- a/src/main/java/io/github/hapjava/accessories/ContactSensorAccessory.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.contactsensor.ContactStateEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.ContactSensorService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A contact sensor that reports whether contact is detected or not. Typical contact sensors are - * window/door sensors. When contact is detected it means that the door/window is closed. - * - * @author Gaston Dombiak - */ -public interface ContactSensorAccessory extends HomekitAccessory { - - /** - * Retrieves the state of the contact. This is whether the contact is detected or not. Detected - * contact means door/window is closed. - * - * @return a future that will contain the contact's state - */ - CompletableFuture getCurrentState(); - - /** - * Subscribes to changes in the contact state. - * - * @param callback the function to call when the state changes. - */ - void subscribeContactState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the contact state. */ - void unsubscribeContactState(); - - @Override - default Collection getServices() { - return Collections.singleton(new ContactSensorService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/DoorAccessory.java b/src/main/java/io/github/hapjava/accessories/DoorAccessory.java deleted file mode 100644 index 1049c7686..000000000 --- a/src/main/java/io/github/hapjava/accessories/DoorAccessory.java +++ /dev/null @@ -1,78 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.windowcovering.PositionStateEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.DoorService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** A motorized door with current and target position. */ -public interface DoorAccessory extends HomekitAccessory { - - /** - * Retrieves the position state of the door - * - * @return a future which will contain the door's position state - */ - CompletableFuture getPositionState(); - - /** - * Retrieves the current position of the door - * - * @return a future which will contain the door's current position - */ - CompletableFuture getCurrentPosition(); - - /** - * Retrieves the target position of the door - * - * @return a future which will contain the door's target position - */ - CompletableFuture getTargetPosition(); - - /** - * Sets the targeted state of the door. - * - * @param position the targeted position - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setTargetPosition(Integer position) throws Exception; - - /** - * Subscribes to changes in the door's position state - * - * @param callback the function to call when the state changes - */ - void subscribePositionState(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the door's current position - * - * @param callback the function to call when the current position changes - */ - void subscribeCurrentPosition(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the door's target position - * - * @param callback the function to call when the target position changes - */ - void subscribeTargetPosition(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the door's state */ - void unsubscribePositionState(); - - /** Unsubscribes from changes in the door's current position */ - void unsubscribeCurrentPosition(); - - /** Unsubscribes from changes in the door's target position */ - void unsubscribeTargetPosition(); - - @Override - default Collection getServices() { - return Collections.singleton(new DoorService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/DoorbellAccessory.java b/src/main/java/io/github/hapjava/accessories/DoorbellAccessory.java deleted file mode 100644 index d46d4a00e..000000000 --- a/src/main/java/io/github/hapjava/accessories/DoorbellAccessory.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.common.ProgrammableSwitchEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.DoorbellService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** doorbell accessory with a switch (button push) event. */ -public interface DoorbellAccessory extends HomekitAccessory { - - /** - * Retrieves the last states of the doorbell. Bluetooth device should return the last event, the - * IP device should always return null - * - * @return state of the door bell event - */ - CompletableFuture getSwitchEvent(); - - /** - * Subscribes to changes in doorbell switch event, i.e. pressing on the door bell button. - * - * @param callback the function to call when the state changes. - */ - void subscribeSwitchEvent(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in doorbell switch event. */ - void unsubscribeSwitchEvent(); - - @Override - default Collection getServices() { - return Collections.singleton(new DoorbellService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/FanAccessory.java b/src/main/java/io/github/hapjava/accessories/FanAccessory.java deleted file mode 100644 index 641214e76..000000000 --- a/src/main/java/io/github/hapjava/accessories/FanAccessory.java +++ /dev/null @@ -1,46 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.FanService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A fan with mandatory characteristics. - * - * @author Andy Lintner - */ -public interface FanAccessory extends HomekitAccessory { - /** - * Mandatory: Retrieves the current active state of the fan'. - * - * @return a future that will contain the binary state - */ - CompletableFuture isActive(); - - /** - * Sets the active state of the fan - * - * @param state the binary state to set - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setActive(boolean state) throws Exception; - - /** - * Subscribes to changes in the active state of the fan. - * - * @param callback the function to call when the active state changes. - */ - void subscribeActive(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the active state of the fan. */ - void unsubscribeActive(); - - @Override - default Collection getServices() { - return Collections.singleton(new FanService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/FaucetAccessory.java b/src/main/java/io/github/hapjava/accessories/FaucetAccessory.java deleted file mode 100644 index 7a000fcec..000000000 --- a/src/main/java/io/github/hapjava/accessories/FaucetAccessory.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.FaucetService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** Faucets or shower heads accessory. */ -public interface FaucetAccessory extends HomekitAccessory { - /** - * Mandatory: Retrieves the current active state of the faucet. - * - * @return a future that will contain the binary state - */ - CompletableFuture isActive(); - - /** - * Sets the active state of the faucet - * - * @param state the binary state to set - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setActive(boolean state) throws Exception; - - /** - * Subscribes to changes in the active state of the faucet. - * - * @param callback the function to call when the active state changes. - */ - void subscribeActive(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the active state of the faucet. */ - void unsubscribeActive(); - - @Override - default Collection getServices() { - return Collections.singleton(new FaucetService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/FilterMaintenanceAccessory.java b/src/main/java/io/github/hapjava/accessories/FilterMaintenanceAccessory.java deleted file mode 100644 index 2ebee5495..000000000 --- a/src/main/java/io/github/hapjava/accessories/FilterMaintenanceAccessory.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.filtermaintenance.FilterChangeIndicationEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.FilterMaintenanceService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A Filter maintenance with mandatory characteristics. - * - *

The HomeKit app doesn't support a separate FilterMaintenance, but as a linked service to - * AirPurifier. - */ -public interface FilterMaintenanceAccessory extends HomekitAccessory { - - /** - * The filter change indictaion. It's either yes or no. - * - * @return FilterChangeIndicationEnum - */ - CompletableFuture getFilterChangeIndication(); - - /** - * Subscribes to changes in the filter change indication. - * - * @param callback the function to call when the state changes. - */ - void subscribeFilterChangeIndication(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the filter change indication. */ - void unsubscribeFilterChangeIndication(); - - @Override - default Collection getServices() { - return Collections.singleton(new FilterMaintenanceService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/GarageDoorOpenerAccessory.java b/src/main/java/io/github/hapjava/accessories/GarageDoorOpenerAccessory.java deleted file mode 100644 index 37bd8a063..000000000 --- a/src/main/java/io/github/hapjava/accessories/GarageDoorOpenerAccessory.java +++ /dev/null @@ -1,83 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.garagedoor.CurrentDoorStateEnum; -import io.github.hapjava.characteristics.impl.garagedoor.TargetDoorStateEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.GarageDoorOpenerService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * garage door opener accessory with control and status of a garage door - * - * @author Andy Lintner - */ -public interface GarageDoorOpenerAccessory extends HomekitAccessory { - - /** - * Retrieves the current state of the door - * - * @return a future which will contain the door's state - */ - CompletableFuture getCurrentDoorState(); - - /** - * Retrieves the targeted state of the door - * - * @return a future which will contain the door's targeted state - */ - CompletableFuture getTargetDoorState(); - - /** - * Retrieves an indicator of an obstruction detected by the door - * - * @return a future which will contain the indicator - */ - CompletableFuture getObstructionDetected(); - - /** - * Sets the targeted state of the door. - * - * @param state the targeted state - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setTargetDoorState(TargetDoorStateEnum state) throws Exception; - - /** - * Subscribes to changes in the door's state - * - * @param callback the function to call when the state changes - */ - void subscribeCurrentDoorState(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the door's targeted state - * - * @param callback the function to call when the targeted state changes - */ - void subscribeTargetDoorState(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the obstruction detected indicator - * - * @param callback the function to call when the indicator chnages - */ - void subscribeObstructionDetected(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the door's state */ - void unsubscribeCurrentDoorState(); - - /** Unsubscribes from changes in the door's targeted state */ - void unsubscribeTargetDoorState(); - - /** Unsubscribes from changes in the door's obstruction detected indicator */ - void unsubscribeObstructionDetected(); - - @Override - default Collection getServices() { - return Collections.singleton(new GarageDoorOpenerService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/HeaterCoolerAccessory.java b/src/main/java/io/github/hapjava/accessories/HeaterCoolerAccessory.java deleted file mode 100644 index d72af203a..000000000 --- a/src/main/java/io/github/hapjava/accessories/HeaterCoolerAccessory.java +++ /dev/null @@ -1,121 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.heatercooler.CurrentHeaterCoolerStateEnum; -import io.github.hapjava.characteristics.impl.heatercooler.TargetHeaterCoolerStateEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.HeaterCoolerService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** Heater Cooler accessory */ -public interface HeaterCoolerAccessory extends HomekitAccessory { - /** - * Retrieves the current temperature, in celsius degrees. - * - * @return a future that will contain the temperature. - */ - CompletableFuture getCurrentTemperature(); - - /** - * Mandatory: Retrieves the current active state of the Heater Cooler. - * - * @return a future that will contain the binary state - */ - CompletableFuture isActive(); - - /** - * Sets the active state of the Heater Cooler - * - * @param state the binary state to set - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setActive(boolean state) throws Exception; - - /** - * Retrieves the heater /cooler current state. - * - * @return a future that will contain the heater cooler current state . - */ - CompletableFuture getCurrentHeaterCoolerState(); - - /** - * Retrieves the heater cooler target state. - * - * @return a future that will contain the heater cooler target state . - */ - CompletableFuture getTargetHeaterCoolerState(); - - /** - * set heater cooler target state the lock target state. - * - * @param state heater cooler target state - * @return a future that completes when the change is made - */ - CompletableFuture setTargetHeaterCoolerState(TargetHeaterCoolerStateEnum state); - - /** - * Subscribes to changes in the heater cooler current state. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentHeaterCoolerState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in heater cooler current state. */ - void unsubscribeCurrentHeaterCoolerState(); - - /** - * Subscribes to changes in the heater cooler target state. - * - * @param callback the function to call when the state changes. - */ - void subscribeTargetHeaterCoolerState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in heater cooler target state. */ - void unsubscribeTargetHeaterCoolerState(); - - /** - * Subscribes to changes in the active state of the heater cooler . - * - * @param callback the function to call when the active state changes. - */ - void subscribeActive(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the active state of the heater cooler . */ - void unsubscribeActive(); - - /** - * Subscribes to changes in the current temperature. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentTemperature(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current temperature. */ - void unsubscribeCurrentTemperature(); - - /** - * Valid values for current state. - * - * @return array of valid current states - */ - default CurrentHeaterCoolerStateEnum[] getCurrentHeaterCoolerStateValidValues() { - return CurrentHeaterCoolerStateEnum.values(); - } - - /** - * Valid values for target state. - * - * @return array of valid target states - */ - default TargetHeaterCoolerStateEnum[] getTargetHeaterCoolerStateValidValues() { - return TargetHeaterCoolerStateEnum.values(); - } - - @Override - default Collection getServices() { - return Collections.singleton(new HeaterCoolerService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/HomekitAccessory.java b/src/main/java/io/github/hapjava/accessories/HomekitAccessory.java deleted file mode 100644 index 64c406492..000000000 --- a/src/main/java/io/github/hapjava/accessories/HomekitAccessory.java +++ /dev/null @@ -1,99 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.AccessoryInformationService; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.concurrent.CompletableFuture; - -/** - * Base interface for all HomeKit Accessories. You can implement this interface directly, but most - * users will prefer to use the more full featured interfaces in {@link - * io.github.hapjava.accessories} which include a default implementation of {@link #getServices()}. - * - * @author Andy Lintner - */ -public interface HomekitAccessory { - - /** - * A unique identifier that must remain static across invocations to prevent errors with paired - * iOS devices. When used as a child of a Bridge, this value must be greater than 1, as that ID is - * reserved for the Bridge itself. - * - * @return the unique identifier. - */ - int getId(); - - /** - * Returns a name to display in iOS. - * - * @return the label. - */ - CompletableFuture getName(); - - /** - * Performs an operation that can be used to identify the accessory. This action can be performed - * without pairing. - */ - void identify(); - - /** - * Returns a serial number to display in iOS. - * - * @return the serial number, or null. - */ - CompletableFuture getSerialNumber(); - - /** - * Returns a model name to display in iOS. - * - * @return the model name, or null. - */ - CompletableFuture getModel(); - - /** - * Returns a manufacturer to display in iOS. - * - * @return the manufacturer, or null. - */ - CompletableFuture getManufacturer(); - - /** - * Returns a firmware revision to display in iOS. - * - * @return the firmware revision, or null. - */ - CompletableFuture getFirmwareRevision(); - - /** - * The collection of Services this accessory supports. Services are the primary way to interact - * with the accessory via HomeKit. Besides the Services offered here, the accessory will - * automatically include the required information service. - * - *

This method will only be useful if you're implementing your own accessory type. For the - * standard accessories, use the default implementation provided by the interfaces in {@link - * io.github.hapjava.accessories}. - * - * @return the collection of services. - */ - default Collection getServices() { - return Collections.singleton(new AccessoryInformationService(this)); - }; - - /** - * default implementation which is sufficient if accessory has only one service - * - * @return primary service - */ - default Service getPrimaryService() { - Iterator iterator = getServices().iterator(); - while (iterator.hasNext()) { - Service service = iterator.next(); - if (!(service instanceof AccessoryInformationService)) { - return service; - } - } - return null; - }; -} diff --git a/src/main/java/io/github/hapjava/accessories/HumidifierDehumidifierAccessory.java b/src/main/java/io/github/hapjava/accessories/HumidifierDehumidifierAccessory.java deleted file mode 100644 index 63a460526..000000000 --- a/src/main/java/io/github/hapjava/accessories/HumidifierDehumidifierAccessory.java +++ /dev/null @@ -1,114 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.humidifier.CurrentHumidifierDehumidifierStateEnum; -import io.github.hapjava.characteristics.impl.humidifier.TargetHumidifierDehumidifierStateEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.HumidifierDehumidifierService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** Humidifier/Dehumidifier accessory */ -public interface HumidifierDehumidifierAccessory extends HomekitAccessory { - /** - * Retrieves the current relative humidity. - * - * @return a future that will contain the humidity as a value between 0 and 100. - */ - CompletableFuture getCurrentHumidity(); - - /** - * Mandatory: Retrieves the current active state of the humidifier/dehumidifier. - * - * @return a future that will contain the binary state - */ - CompletableFuture isActive(); - - /** - * Sets the active state of the humidifier/dehumidifier - * - * @param state the binary state to set - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setActive(boolean state) throws Exception; - - /** - * Retrieves the humidifier/dehumidifier current state. - * - * @return a future that will contain the humidifier/dehumidifier current state . - */ - CompletableFuture getCurrentHumidifierDehumidifierState(); - - /** - * Retrieves the humidifier/dehumidifier target state. - * - * @return a future that will contain the humidifier/dehumidifier target state . - */ - CompletableFuture getTargetHumidifierDehumidifierState(); - - /** - * set humidifier/dehumidifier target state the lock target state. - * - * @param state humidifier/dehumidifier target state - * @return a future that completes when the change is made - */ - CompletableFuture setTargetHumidifierDehumidifierState( - TargetHumidifierDehumidifierStateEnum state); - - /** - * Valid values for target state. - * - * @return array of valid target states. - */ - default TargetHumidifierDehumidifierStateEnum[] - getTargetHumidifierDehumidifierStateValidValues() { - return TargetHumidifierDehumidifierStateEnum.values(); - } - - /** - * Subscribes to changes in the humidifier/dehumidifier current state. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentHumidifierDehumidifierState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in humidifier/dehumidifier current state. */ - void unsubscribeCurrentHumidifierDehumidifierState(); - - /** - * Subscribes to changes in the humidifier/dehumidifier target state. - * - * @param callback the function to call when the state changes. - */ - void subscribeTargetHumidifierDehumidifierState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in humidifier/dehumidifier target state. */ - void unsubscribeTargetHumidifierDehumidifierState(); - - /** - * Subscribes to changes in the active state of the humidifier/dehumidifier . - * - * @param callback the function to call when the active state changes. - */ - void subscribeActive(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the active state of the humidifier/dehumidifier . */ - void unsubscribeActive(); - - /** - * Subscribes to changes in the current humidity. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentHumidity(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current humidity. */ - void unsubscribeCurrentHumidity(); - - @Override - default Collection getServices() { - return Collections.singleton(new HumidifierDehumidifierService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/HumiditySensorAccessory.java b/src/main/java/io/github/hapjava/accessories/HumiditySensorAccessory.java deleted file mode 100644 index 07c24be58..000000000 --- a/src/main/java/io/github/hapjava/accessories/HumiditySensorAccessory.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.HumiditySensorService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A humidity sensor that reports the current relative humidity. - * - * @author Andy Lintner - */ -public interface HumiditySensorAccessory extends HomekitAccessory { - - /** - * Retrieves the current relative humidity. - * - * @return a future that will contain the humidity as a value between 0 and 100 - */ - CompletableFuture getCurrentRelativeHumidity(); - - /** - * Subscribes to changes in the current relative humidity. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentRelativeHumidity(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current relative humidity. */ - void unsubscribeCurrentRelativeHumidity(); - - @Override - default Collection getServices() { - return Collections.singleton(new HumiditySensorService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/InputSourceAccessory.java b/src/main/java/io/github/hapjava/accessories/InputSourceAccessory.java deleted file mode 100644 index cfa5ae3d6..000000000 --- a/src/main/java/io/github/hapjava/accessories/InputSourceAccessory.java +++ /dev/null @@ -1,104 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.common.IsConfiguredEnum; -import io.github.hapjava.characteristics.impl.inputsource.CurrentVisibilityStateEnum; -import io.github.hapjava.characteristics.impl.inputsource.InputSourceTypeEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.InputSourceService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** Input Source accessory. */ -public interface InputSourceAccessory extends HomekitAccessory { - - /** - * Retrieves configured name of input source. - * - * @return configured name of input source - */ - CompletableFuture getConfiguredName(); - - /** - * Sets the configured name. - * - * @param name configured name - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setConfiguredName(String name) throws Exception; - - /** - * Subscribes to changes in configured name. - * - * @param callback the function to call when the configured name changes. - */ - void subscribeConfiguredName(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the configured name. */ - void unsubscribeConfiguredName(); - - /** - * Retrieves the flag whether input source is configured. - * - * @return a future that will contain the flag . - */ - CompletableFuture isConfigured(); - /** - * set the flag whether input source is configured. - * - * @param state is configured state - * @return a future that completes when the change is made - */ - CompletableFuture setIsConfigured(IsConfiguredEnum state); - - /** - * Subscribes to changes in isConfigured. - * - * @param callback the function to call when the state changes. - */ - void subscribeIsConfigured(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in isConfigured. */ - void unsubscribeIsConfigured(); - - /** - * Retrieves the input source type. - * - * @return a future that will contain the input source type. - */ - CompletableFuture getInputSourceType(); - - /** - * Subscribes to changes in input source type. - * - * @param callback the function to call when the type changes. - */ - void subscribeInputSourceType(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the input source type. */ - void unsubscribeInputSourceType(); - - /** - * Retrieves the current visibility state. - * - * @return a future that will contain the current visibility state. - */ - CompletableFuture getCurrentVisibilityState(); - - /** - * Subscribes to changes in current visibility state. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentVisibilityState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current visibility state. */ - void unsubscribeCurrentVisibilityState(); - - @Override - default Collection getServices() { - return Collections.singleton(new InputSourceService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/IrrigationSystemAccessory.java b/src/main/java/io/github/hapjava/accessories/IrrigationSystemAccessory.java deleted file mode 100644 index dffa2e00b..000000000 --- a/src/main/java/io/github/hapjava/accessories/IrrigationSystemAccessory.java +++ /dev/null @@ -1,82 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.common.ActiveEnum; -import io.github.hapjava.characteristics.impl.common.InUseEnum; -import io.github.hapjava.characteristics.impl.common.ProgramModeEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.IrrigationSystemService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** irrigation system accessory that controls several valves. */ -public interface IrrigationSystemAccessory extends HomekitAccessory { - - /** - * An irrigation system is set to Active when the system is enabled. When one of the valves is set - * to In Use, the irrigation system must be set to in use. - * - * @return a future that will contain the binary state - */ - CompletableFuture getActive(); - - /** - * Sets the irrigation active state - * - * @param active the binary state to set - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setActive(ActiveEnum active) throws Exception; - - /** - * Retrieves the program mode status - * - * @return a future that will contain the valve type. - */ - CompletableFuture getProgramMode(); - - /** - * Retrieves the current inUse state of the irrigation; InUse means one of the valves is set to In - * Use. - * - * @return a future that will contain the binary state - */ - CompletableFuture getInUse(); - - /** - * Subscribes to changes in the inUse state. - * - * @param callback the function to call when the state changes. - */ - void subscribeInUse(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the inUse state. */ - void unsubscribeInUse(); - - /** - * Subscribes to changes in the active state of the irrigation. - * - * @param callback the function to call when the state changes. - */ - void subscribeActive(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the irrigation active state. */ - void unsubscribeActive(); - - /** - * Subscribes to changes in the program mode of the irrigation system. - * - * @param callback the function to call when the state changes. - */ - void subscribeProgramMode(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the program mode. */ - void unsubscribeProgramMode(); - - @Override - default Collection getServices() { - return Collections.singleton(new IrrigationSystemService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/LeakSensorAccessory.java b/src/main/java/io/github/hapjava/accessories/LeakSensorAccessory.java deleted file mode 100644 index c36ce278c..000000000 --- a/src/main/java/io/github/hapjava/accessories/LeakSensorAccessory.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.leaksensor.LeakDetectedStateEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.LeakSensorService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A leak sensor that reports whether a leak has been detected. - * - * @author Tim Harper - */ -public interface LeakSensorAccessory extends HomekitAccessory { - - /** - * Retrieves the state of the leak sensor. If true then leak has been detected. - * - * @return a future that will contain the leak sensor's state - */ - CompletableFuture getLeakDetected(); - - /** - * Subscribes to changes in the leak sensor. - * - * @param callback the function to call when the state changes. - */ - void subscribeLeakDetected(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the leak sensor. */ - void unsubscribeLeakDetected(); - - @Override - default Collection getServices() { - return Collections.singleton(new LeakSensorService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/LightSensorAccessory.java b/src/main/java/io/github/hapjava/accessories/LightSensorAccessory.java deleted file mode 100644 index 2087b1e99..000000000 --- a/src/main/java/io/github/hapjava/accessories/LightSensorAccessory.java +++ /dev/null @@ -1,69 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.lightsensor.CurrentAmbientLightLevelCharacteristic; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.LightSensorService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A light sensor that reports current ambient light level. - * - * @author Gaston Dombiak - */ -public interface LightSensorAccessory extends HomekitAccessory { - - /** - * Retrieves the current ambient light level. - * - * @return a future that will contain the luminance level expressed in LUX. - */ - CompletableFuture getCurrentAmbientLightLevel(); - - /** - * Subscribes to changes in the current ambient light level. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentAmbientLightLevel(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current ambient light level. */ - void unsubscribeCurrentAmbientLightLevel(); - - /** - * return the min value for current ambient light level. overwrite if you want to change the - * default value. - * - * @return min current ambient light level - */ - default double getMinCurrentAmbientLightLevel() { - return CurrentAmbientLightLevelCharacteristic.DEFAULT_MIN_VALUE; - } - - /** - * return the max value for current ambient light level. overwrite if you want to change the - * default value. - * - * @return max current ambient light level - */ - default double getMaxCurrentAmbientLightLevel() { - return CurrentAmbientLightLevelCharacteristic.DEFAULT_MAX_VALUE; - } - - /** - * return the min step value for current ambient light level. overwrite if you want to change the - * default value. - * - * @return min step current ambient light level - */ - default double getMinStepCurrentAmbientLightLevel() { - return CurrentAmbientLightLevelCharacteristic.DEFAULT_STEP; - } - - @Override - default Collection getServices() { - return Collections.singleton(new LightSensorService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/LightbulbAccessory.java b/src/main/java/io/github/hapjava/accessories/LightbulbAccessory.java deleted file mode 100644 index 8a6caaed8..000000000 --- a/src/main/java/io/github/hapjava/accessories/LightbulbAccessory.java +++ /dev/null @@ -1,47 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.LightbulbService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A simple light with a binary state. - * - * @author Andy Lintner - */ -public interface LightbulbAccessory extends HomekitAccessory { - - /** - * Retrieves the current binary state of the light. - * - * @return a future that will contain the binary state - */ - CompletableFuture getLightbulbPowerState(); - - /** - * Sets the binary state of the light - * - * @param powerState the binary state to set - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setLightbulbPowerState(boolean powerState) throws Exception; - - /** - * Subscribes to changes in the binary state of the light. - * - * @param callback the function to call when the state changes. - */ - void subscribeLightbulbPowerState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the binary state of the light. */ - void unsubscribeLightbulbPowerState(); - - @Override - default Collection getServices() { - return Collections.singleton(new LightbulbService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/LockMechanismAccessory.java b/src/main/java/io/github/hapjava/accessories/LockMechanismAccessory.java deleted file mode 100644 index f12f3e286..000000000 --- a/src/main/java/io/github/hapjava/accessories/LockMechanismAccessory.java +++ /dev/null @@ -1,61 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.lock.LockCurrentStateEnum; -import io.github.hapjava.characteristics.impl.lock.LockTargetStateEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.LockMechanismService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** Lock mechanism with current and target state. */ -public interface LockMechanismAccessory extends HomekitAccessory { - - /** - * Retrieves the lock current state. - * - * @return a future that will contain the lock current state . - */ - CompletableFuture getLockCurrentState(); - - /** - * Retrieves the lock target state. - * - * @return a future that will contain the lock target state . - */ - CompletableFuture getLockTargetState(); - - /** - * set lock target state the lock target state. - * - * @param state lock target state - * @return a future that completes when the change is made - */ - CompletableFuture setLockTargetState(LockTargetStateEnum state); - - /** - * Subscribes to changes in the lock current state. - * - * @param callback the function to call when the state changes. - */ - void subscribeLockCurrentState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in lock current state. */ - void unsubscribeLockCurrentState(); - - /** - * Subscribes to changes in the lock target state. - * - * @param callback the function to call when the state changes. - */ - void subscribeLockTargetState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in lock target state. */ - void unsubscribeLockTargetState(); - - @Override - default Collection getServices() { - return Collections.singleton(new LockMechanismService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/MicrophoneAccessory.java b/src/main/java/io/github/hapjava/accessories/MicrophoneAccessory.java deleted file mode 100644 index f63f8b70c..000000000 --- a/src/main/java/io/github/hapjava/accessories/MicrophoneAccessory.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.MicrophoneService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** Microphone accessory with mute state. */ -public interface MicrophoneAccessory extends HomekitAccessory { - - /** - * Retrieves mute status. - * - * @return true if accessory is muted - */ - CompletableFuture isMuted(); - - /** - * Sets the mute status - * - * @param mute true if accessory should be muted - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setMute(boolean mute) throws Exception; - - /** - * Subscribes to changes in mute state. - * - * @param callback the function to call when the state changes. - */ - void subscribeMuteState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the mute state. */ - void unsubscribeMuteState(); - - @Override - default Collection getServices() { - return Collections.singleton(new MicrophoneService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/MotionSensorAccessory.java b/src/main/java/io/github/hapjava/accessories/MotionSensorAccessory.java deleted file mode 100644 index e843068b1..000000000 --- a/src/main/java/io/github/hapjava/accessories/MotionSensorAccessory.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.MotionSensorService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A motion sensor that reports whether motion has been detected. - * - * @author Gaston Dombiak - */ -public interface MotionSensorAccessory extends HomekitAccessory { - - /** - * Retrieves the state of the motion sensor. If true then motion has been detected. - * - * @return a future that will contain the motion sensor's state - */ - CompletableFuture getMotionDetected(); - - /** - * Subscribes to changes in the motion sensor. - * - * @param callback the function to call when the state changes. - */ - void subscribeMotionDetected(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the motion sensor. */ - void unsubscribeMotionDetected(); - - @Override - default Collection getServices() { - return Collections.singleton(new MotionSensorService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/OccupancySensorAccessory.java b/src/main/java/io/github/hapjava/accessories/OccupancySensorAccessory.java deleted file mode 100644 index 5fc3cff1e..000000000 --- a/src/main/java/io/github/hapjava/accessories/OccupancySensorAccessory.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.occupancysensor.OccupancyDetectedEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.OccupancySensorService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * An occupancy sensor that reports whether occupancy has been detected. - * - * @author Tim Harper - */ -public interface OccupancySensorAccessory extends HomekitAccessory { - /** - * Retrieves the state of the occupancy sensor. If true then occupancy has been detected. - * - * @return a future that will contain the occupancy sensor's state - */ - CompletableFuture getOccupancyDetected(); - - /** - * Subscribes to changes in the occupancy sensor. - * - * @param callback the function to call when the state changes. - */ - void subscribeOccupancyDetected(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the occupancy sensor. */ - void unsubscribeOccupancyDetected(); - - @Override - default Collection getServices() { - return Collections.singleton(new OccupancySensorService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/OutletAccessory.java b/src/main/java/io/github/hapjava/accessories/OutletAccessory.java deleted file mode 100644 index 213f673b7..000000000 --- a/src/main/java/io/github/hapjava/accessories/OutletAccessory.java +++ /dev/null @@ -1,64 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.OutletService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A power outlet with boolean power and usage states. - * - * @author Andy Lintner - */ -public interface OutletAccessory extends HomekitAccessory { - - /** - * Retrieves the current binary state of the outlet's power. - * - * @return a future that will contain the binary state - */ - CompletableFuture getPowerState(); - - /** - * Retrieves the current binary state indicating whether the outlet is in use. - * - * @return a future that will contain the binary state - */ - CompletableFuture getOutletInUse(); - - /** - * Sets the binary state of the outlet's power. - * - * @param state the binary state to set - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setPowerState(boolean state) throws Exception; - - /** - * Subscribes to changes in the binary state of the outlet's power. - * - * @param callback the function to call when the state changes. - */ - void subscribePowerState(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the binary state indicating whether the outlet is in use. - * - * @param callback the function to call when the state changes. - */ - void subscribeOutletInUse(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the binary state of the outlet's power. */ - void unsubscribePowerState(); - - /** Unsubscribes from changes in the binary state indicating whether hte outlet is in use. */ - void unsubscribeOutletInUse(); - - @Override - default Collection getServices() { - return Collections.singleton(new OutletService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/SecuritySystemAccessory.java b/src/main/java/io/github/hapjava/accessories/SecuritySystemAccessory.java deleted file mode 100644 index 43c12acd2..000000000 --- a/src/main/java/io/github/hapjava/accessories/SecuritySystemAccessory.java +++ /dev/null @@ -1,89 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.securitysystem.CurrentSecuritySystemStateEnum; -import io.github.hapjava.characteristics.impl.securitysystem.TargetSecuritySystemStateEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.SecuritySystemService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A security system that can be armed so that when a contact sensor is opened or a motion sensor - * detects movement, then a siren could be fired off. There are different modes for arming the - * system. See {@link TargetSecuritySystemStateEnum} for more information. - * - * @author Gaston Dombiak - */ -public interface SecuritySystemAccessory extends HomekitAccessory { - - /** - * Retrieves the current state of the security system. The state describes if the system is armed - * in any of its variations; or if the alarm has been triggered; or if the system is disarmed. - * - * @return current state of the security system. - */ - CompletableFuture getCurrentSecuritySystemState(); - - /** - * Subscribes to changes to the state of the security system. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentSecuritySystemState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the state of the security system. */ - void unsubscribeCurrentSecuritySystemState(); - - /** - * Sets the state of the security system. The security system could be armed in any of its - * variations or disarmed. - * - * @param state target state of the security system. - * @throws Exception when the change cannot be made. - */ - void setTargetSecuritySystemState(TargetSecuritySystemStateEnum state) throws Exception; - - /** - * Retrieves the pending, but not yet completed, state of the security system. - * - * @return target state of the security system. - */ - CompletableFuture getTargetSecuritySystemState(); - - /** - * Subscribes to changes in the pending, but not yet completed, state of the security system. - * - * @param callback the function to call when the state changes. - */ - void subscribeTargetSecuritySystemState(HomekitCharacteristicChangeCallback callback); - - /** - * Unsubscribes from changes in the pending, but not yet completed, state of the security system. - */ - void unsubscribeTargetSecuritySystemState(); - - /** - * Valid values for current state. - * - * @return array of valid current states. - */ - default CurrentSecuritySystemStateEnum[] getCurrentSecuritySystemStateValidValues() { - return CurrentSecuritySystemStateEnum.values(); - } - - /** - * Valid values for target state. - * - * @return array of valid targe states. - */ - default TargetSecuritySystemStateEnum[] getTargetSecuritySystemStateValidValues() { - return TargetSecuritySystemStateEnum.values(); - } - - @Override - default Collection getServices() { - return Collections.singleton(new SecuritySystemService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/SlatAccessory.java b/src/main/java/io/github/hapjava/accessories/SlatAccessory.java deleted file mode 100644 index 62888ab60..000000000 --- a/src/main/java/io/github/hapjava/accessories/SlatAccessory.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.slat.CurrentSlatStateEnum; -import io.github.hapjava.characteristics.impl.slat.SlatTypeEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.SlatService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** A slat accessory which tilts on a vertical or a horizontal axis. */ -public interface SlatAccessory extends HomekitAccessory { - - /** - * Retrieves the current state of the slat - * - * @return a future that will contain the state - */ - CompletableFuture getSlatState(); - - /** - * Subscribes to changes in the state of the slat. - * - * @param callback the function to call when the state changes. - */ - void subscribeSlatState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the state of the slat. */ - void unsubscribeSlatState(); - - /** - * Retrieves the slat type. - * - * @return a future that will slat type. - */ - CompletableFuture getSlatType(); - - @Override - default Collection getServices() { - return Collections.singleton(new SlatService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/SmartSpeakerAccessory.java b/src/main/java/io/github/hapjava/accessories/SmartSpeakerAccessory.java deleted file mode 100644 index 9f70af2be..000000000 --- a/src/main/java/io/github/hapjava/accessories/SmartSpeakerAccessory.java +++ /dev/null @@ -1,62 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.television.CurrentMediaStateEnum; -import io.github.hapjava.characteristics.impl.television.TargetMediaStateEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.SmartSpeakerService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** Smart Speaker accessory. */ -public interface SmartSpeakerAccessory extends HomekitAccessory { - - /** - * Retrieves the current media state (see {@link - * io.github.hapjava.characteristics.impl.television.CurrentMediaStateEnum} for supported values). - * - * @return a future that will contain the current media state - */ - CompletableFuture getCurrentMediaState(); - - /** - * Subscribes to changes in the current media state. - * - * @param callback the function to call when the current media state changes. - */ - void subscribeCurrentMediaState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current media state. */ - void unsubscribeCurrentMediaState(); - - /** - * Retrieves the target media state (see {@link TargetMediaStateEnum} for supported values). - * - * @return a future that will contain the target media state - */ - CompletableFuture getTargetMediaState(); - - /** - * Set the target media state (see {@link TargetMediaStateEnum} for supported values). - * - * @param targetMediaState target media state - * @return a future that completes when the change is made - */ - CompletableFuture setTargetMediaState(TargetMediaStateEnum targetMediaState); - - /** - * Subscribes to changes in the target media state. - * - * @param callback the function to call when the target media state changes. - */ - void subscribeTargetMediaState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the target media state. */ - void unsubscribeTargetMediaState(); - - @Override - default Collection getServices() { - return Collections.singleton(new SmartSpeakerService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/SmokeSensorAccessory.java b/src/main/java/io/github/hapjava/accessories/SmokeSensorAccessory.java deleted file mode 100644 index b6a8b1054..000000000 --- a/src/main/java/io/github/hapjava/accessories/SmokeSensorAccessory.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.smokesensor.SmokeDetectedStateEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.SmokeSensorService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A smoke sensor reports whether smoke has been detected or not. - * - * @author Gaston Dombiak - */ -public interface SmokeSensorAccessory extends HomekitAccessory { - - /** - * Retrieves the state of the smoke sensor. This is whether smoke has been detected or not. - * - * @return a future that will contain the smoke sensor's state - */ - CompletableFuture getSmokeDetectedState(); - - /** - * Subscribes to changes in the smoke sensor's state. - * - * @param callback the function to call when the state changes. - */ - void subscribeSmokeDetectedState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the smoke sensor's state. */ - void unsubscribeSmokeDetectedState(); - - @Override - default Collection getServices() { - return Collections.singleton(new SmokeSensorService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/SpeakerAccessory.java b/src/main/java/io/github/hapjava/accessories/SpeakerAccessory.java deleted file mode 100644 index 661607a30..000000000 --- a/src/main/java/io/github/hapjava/accessories/SpeakerAccessory.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.SpeakerService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** Speaker accessory. */ -public interface SpeakerAccessory extends HomekitAccessory { - - /** - * Retrieves mute status. - * - * @return true if accessory is muted - */ - CompletableFuture isMuted(); - - /** - * Sets the mute status - * - * @param mute true if accessory should be muted - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setMute(boolean mute) throws Exception; - - /** - * Subscribes to changes in mute state. - * - * @param callback the function to call when the state changes. - */ - void subscribeMuteState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the mute state. */ - void unsubscribeMuteState(); - - @Override - default Collection getServices() { - return Collections.singleton(new SpeakerService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/StatelessProgrammableSwitchAccessory.java b/src/main/java/io/github/hapjava/accessories/StatelessProgrammableSwitchAccessory.java deleted file mode 100644 index 354c36587..000000000 --- a/src/main/java/io/github/hapjava/accessories/StatelessProgrammableSwitchAccessory.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.common.ProgrammableSwitchEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.StatelessProgrammableSwitchService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** The Stateless Programmable Switch accessory */ -public interface StatelessProgrammableSwitchAccessory extends HomekitAccessory { - - /** - * Retrieves the last states of the switch. Bluetooth device should return the last event, the IP - * device should always return null - * - * @return state of the switch event - */ - CompletableFuture getSwitchEvent(); - - /** - * Subscribes to changes in switch event, i.e. pressing on the button. - * - * @param callback the function to call when the state changes. - */ - void subscribeSwitchEvent(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in switch event. */ - void unsubscribeSwitchEvent(); - - @Override - default Collection getServices() { - return Collections.singleton(new StatelessProgrammableSwitchService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/SwitchAccessory.java b/src/main/java/io/github/hapjava/accessories/SwitchAccessory.java deleted file mode 100644 index aae442f90..000000000 --- a/src/main/java/io/github/hapjava/accessories/SwitchAccessory.java +++ /dev/null @@ -1,47 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.SwitchService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A simple switch with a binary state. - * - * @author Andy Lintner - */ -public interface SwitchAccessory extends HomekitAccessory { - - /** - * Retrieves the current binary state of the switch. - * - * @return a future that will contain the binary state - */ - CompletableFuture getSwitchState(); - - /** - * Sets the binary state of the switch - * - * @param state the binary state to set - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setSwitchState(boolean state) throws Exception; - - /** - * Subscribes to changes in the binary state of the switch. - * - * @param callback the function to call when the state changes. - */ - void subscribeSwitchState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the binary state of the switch. */ - void unsubscribeSwitchState(); - - @Override - default Collection getServices() { - return Collections.singleton(new SwitchService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/TelevisionAccessory.java b/src/main/java/io/github/hapjava/accessories/TelevisionAccessory.java deleted file mode 100644 index b51efe319..000000000 --- a/src/main/java/io/github/hapjava/accessories/TelevisionAccessory.java +++ /dev/null @@ -1,123 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.television.RemoteKeyEnum; -import io.github.hapjava.characteristics.impl.television.SleepDiscoveryModeEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.TelevisionService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** Television accessory. */ -public interface TelevisionAccessory extends HomekitAccessory { - - /** - * Retrieves the current active state of the TV. - * - * @return a future that will contain the state - */ - CompletableFuture isActive(); - - /** - * Sets the active state of the TV - * - * @param state the state to set - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setActive(boolean state) throws Exception; - - /** - * Subscribes to changes in the active state of the TV . - * - * @param callback the function to call when the active state changes. - */ - void subscribeActive(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the active state of the TV. */ - void unsubscribeActive(); - - /** - * Retrieves the active identifier - * - * @return a future that will contain the active identifier. - */ - CompletableFuture getActiveIdentifier(); - - /** - * Sets the active identifier - * - * @param identifier the active identifier - * @return a future that completes when the active identifier is changed - * @throws Exception when the active identifier cannot be set - */ - CompletableFuture setActiveIdentifier(Integer identifier) throws Exception; - - /** - * Subscribes to changes in the active identifier. - * - * @param callback the function to call when the active identifier changes. - */ - void subscribeActiveIdentifier(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the active identifier. */ - void unsubscribeActiveIdentifier(); - - /** - * Retrieves configured name. - * - * @return configured name - */ - CompletableFuture getConfiguredName(); - - /** - * Sets the configured name - * - * @param name configured name - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setConfiguredName(String name) throws Exception; - - /** - * Subscribes to changes in configured name. - * - * @param callback the function to call when the configureed name changes. - */ - void subscribeConfiguredName(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the configured name state. */ - void unsubscribeConfiguredName(); - - /** - * Sends the remote key. - * - * @param key remote key - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setRemoteKey(RemoteKeyEnum key) throws Exception; - - /** - * Retrieves the sleep discovery mode. - * - * @return a future that will contain the sleep discovery mode . - */ - CompletableFuture getSleepDiscoveryMode(); - - /** - * Subscribes to changes in sleep discovery mode. - * - * @param callback the function to call when the sleep discovery mode changes. - */ - void subscribeSleepDiscoveryMode(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the sleep discovery mode. */ - void unsubscribeSleepDiscoveryMode(); - - @Override - default Collection getServices() { - return Collections.singleton(new TelevisionService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/TelevisionSpeakerAccessory.java b/src/main/java/io/github/hapjava/accessories/TelevisionSpeakerAccessory.java deleted file mode 100644 index 28df1437d..000000000 --- a/src/main/java/io/github/hapjava/accessories/TelevisionSpeakerAccessory.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.TelevisionSpeakerService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** Television speaker accessory. */ -public interface TelevisionSpeakerAccessory extends HomekitAccessory { - - /** - * Retrieves mute status. - * - * @return true if accessory is muted - */ - CompletableFuture isMuted(); - - /** - * Sets the mute status - * - * @param mute true if accessory should be muted - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setMute(boolean mute) throws Exception; - - /** - * Subscribes to changes in mute state. - * - * @param callback the function to call when the state changes. - */ - void subscribeMuteState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the mute state. */ - void unsubscribeMuteState(); - - @Override - default Collection getServices() { - return Collections.singleton(new TelevisionSpeakerService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/TemperatureSensorAccessory.java b/src/main/java/io/github/hapjava/accessories/TemperatureSensorAccessory.java deleted file mode 100644 index 4f9184926..000000000 --- a/src/main/java/io/github/hapjava/accessories/TemperatureSensorAccessory.java +++ /dev/null @@ -1,68 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.TemperatureSensorService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A temperature sensor that reports the current temperature - * - * @author Andy Lintner - */ -public interface TemperatureSensorAccessory extends HomekitAccessory { - - /** - * Retrieves the current temperature, in celsius degrees. - * - * @return a future that will contain the temperature. - */ - CompletableFuture getCurrentTemperature(); - - /** - * return the min value for current temperature. overwrite if you want to change the default - * value. - * - * @return min current temperature - */ - default double getMinCurrentTemperature() { - return 0; - } - - /** - * return the max value for current temperature. overwrite if you want to change the default - * value. - * - * @return max current temperature - */ - default double getMaxCurrentTemperature() { - return 100; - } - - /** - * return the min step value for current temperature. overwrite if you want to change the default - * value. - * - * @return min step current temperature - */ - default double getMinStepCurrentTemperature() { - return 0.1; - } - - /** - * Subscribes to changes in the current temperature. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentTemperature(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current temperature. */ - void unsubscribeCurrentTemperature(); - - @Override - default Collection getServices() { - return Collections.singleton(new TemperatureSensorService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/ThermostatAccessory.java b/src/main/java/io/github/hapjava/accessories/ThermostatAccessory.java deleted file mode 100644 index 837993853..000000000 --- a/src/main/java/io/github/hapjava/accessories/ThermostatAccessory.java +++ /dev/null @@ -1,214 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.thermostat.CurrentHeatingCoolingStateEnum; -import io.github.hapjava.characteristics.impl.thermostat.TargetHeatingCoolingStateEnum; -import io.github.hapjava.characteristics.impl.thermostat.TemperatureDisplayUnitEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.ThermostatService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A thermostat with heating and cooling controls. - * - * @author Andy Lintner - */ -public interface ThermostatAccessory extends HomekitAccessory { - - /** - * Retrieves the current temperature, in celsius degrees. - * - * @return a future that will contain the temperature. - */ - CompletableFuture getCurrentTemperature(); - - /** - * return the min value for current temperature. overwrite if you want to change the default - * value. - * - * @return min current temperature - */ - default double getMinCurrentTemperature() { - return 0; - } - - /** - * return the max value for current temperature. overwrite if you want to change the default - * value. - * - * @return max current temperature - */ - default double getMaxCurrentTemperature() { - return 100; - } - - /** - * return the min step value for current temperature. overwrite if you want to change the default - * value. - * - * @return min step current temperature - */ - default double getMinStepCurrentTemperature() { - return 0.1; - } - - /** - * Retrieves the target temperature, in celsius degrees. - * - * @return a future that will contain the target temperature. - */ - CompletableFuture getTargetTemperature(); - - /** - * Sets the target temperature. - * - * @param value the target temperature, in celsius degrees. - * @throws Exception when the temperature cannot be changed. - */ - void setTargetTemperature(Double value) throws Exception; - - /** - * return the min value for target temperature. overwrite if you want to change the default value. - * - * @return min target temperature - */ - default double getMinTargetTemperature() { - return 10; - } - - /** - * return the max value for target temperature. overwrite if you want to change the default value. - * - * @return max target temperature - */ - default double getMaxTargetTemperature() { - return 38; - } - - /** - * return the min step value for target temperature. overwrite if you want to change the default - * value. - * - * @return min step target temperature - */ - default double getMinStepTargetTemperature() { - return 0.1; - } - - /** - * Retrieves the current {@link CurrentHeatingCoolingStateEnum} of the thermostat. - * - * @return a future that will contain the mode. - */ - CompletableFuture getCurrentState(); - - /** - * Sets the {@link TargetHeatingCoolingStateEnum} of the thermostat. - * - * @param mode The {@link TargetHeatingCoolingStateEnum} to set. - * @throws Exception when the change cannot be made. - */ - void setTargetState(TargetHeatingCoolingStateEnum mode) throws Exception; - - /** - * Retrieves the pending, but not yet complete, {@link TargetHeatingCoolingStateEnum} of the - * thermostat. - * - * @return a future that will contain the target mode. - */ - CompletableFuture getTargetState(); - - /** - * Retrieves the temperture display units, e.g. C or F. - * - * @return a future that will contain the temperature unit. - */ - CompletableFuture getTemperatureDisplayUnit(); - - /** - * Sets the temperature unit. - * - * @param value the temperature display unit. - * @throws Exception when the temperature cannot be changed. - */ - void setTemperatureDisplayUnit(TemperatureDisplayUnitEnum value) throws Exception; - - /** - * Subscribes to changes in the pending, but not yet complete, {@link - * TargetHeatingCoolingStateEnum} of the thermostat. - * - * @param callback the function to call when the state changes. - */ - void subscribeTargetState(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the target temperature. - * - * @param callback the function to call when the state changes. - */ - void subscribeTargetTemperature(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the temperature display unit. - * - * @param callback the function to call when the uni changes. - */ - void subscribeTemperatureDisplayUnit(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the current temperature. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentTemperature(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the {@link CurrentHeatingCoolingStateEnum} of the thermostat. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the mode of the thermostat. */ - void unsubscribeCurrentState(); - - /** - * Unsubscribes from changes in the pending, but not yet complete, {@link - * TargetHeatingCoolingStateEnum} of the thermostat. - */ - void unsubscribeTargetState(); - - /** Unsubscribes from changes in the current temperature. */ - void unsubscribeCurrentTemperature(); - - /** Unsubscribes from changes in temperature display unit */ - void unsubscribeTemperatureDisplayUnit(); - - /** Unsubscribes from changes in the target temperature. */ - void unsubscribeTargetTemperature(); - - /** - * Valid values for current state. - * - * @return array of valid current states. - */ - default CurrentHeatingCoolingStateEnum[] getCurrentHeatingCoolingStateValidValues() { - return CurrentHeatingCoolingStateEnum.values(); - } - - /** - * Valid values for target state. - * - * @return array of valid targe states. - */ - default TargetHeatingCoolingStateEnum[] getTargetHeatingCoolingStateValidValues() { - return TargetHeatingCoolingStateEnum.values(); - } - - @Override - default Collection getServices() { - return Collections.singleton(new ThermostatService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/ValveAccessory.java b/src/main/java/io/github/hapjava/accessories/ValveAccessory.java deleted file mode 100644 index 3db17e41f..000000000 --- a/src/main/java/io/github/hapjava/accessories/ValveAccessory.java +++ /dev/null @@ -1,91 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.common.ActiveEnum; -import io.github.hapjava.characteristics.impl.common.InUseEnum; -import io.github.hapjava.characteristics.impl.valve.ValveTypeEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.ValveService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** - * A Valve (sprinkler head, faucet, etc.) - * - * @author Tim Harper - */ -public interface ValveAccessory extends HomekitAccessory { - - /** - * Retrieves the current active state of the valve; Active could mean the valve is open (but not - * necessarily running), or that the valve is associated with an active watering program (like a - * watering program) but is not currently running. - * - *

To communicate water is flowing through a valve, inUse should be used. - * - * @return a future that will contain the binary state - */ - CompletableFuture getValveActive(); - - /** - * Sets the valve active state - * - * @param active the binary state to set - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setValveActive(ActiveEnum active) throws Exception; - - /** - * Subscribes to changes in the active state of the valve. - * - * @param callback the function to call when the state changes. - */ - void subscribeValveActive(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the valve active state. */ - void unsubscribeValveActive(); - - /** - * Retrieves the current inUse state of the valve; InUse usually means water is flowing through - * the valve. - * - *

To communicate water is flowing through a valve, inUse should be used. - * - * @return a future that will contain the binary state - */ - CompletableFuture getValveInUse(); - - /** - * Subscribes to changes in the inUse state of the valve. - * - * @param callback the function to call when the state changes. - */ - void subscribeValveInUse(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the valve inUse state. */ - void unsubscribeValveInUse(); - - /** - * Retrieves the valve type. - * - * @return a future that will contain the valve type. - */ - CompletableFuture getValveType(); - - /** - * Subscribes to changes in the valveType state of the valve. - * - * @param callback the function to call when the state changes. - */ - void subscribeValveType(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the valveType state. */ - void unsubscribeValveType(); - - @Override - default Collection getServices() { - return Collections.singleton(new ValveService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/WindowAccessory.java b/src/main/java/io/github/hapjava/accessories/WindowAccessory.java deleted file mode 100644 index 6cc52322b..000000000 --- a/src/main/java/io/github/hapjava/accessories/WindowAccessory.java +++ /dev/null @@ -1,78 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.windowcovering.PositionStateEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.WindowService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** motorized window accessory. */ -public interface WindowAccessory extends HomekitAccessory { - - /** - * Retrieves the position state of the door - * - * @return a future which will contain the door's position state - */ - CompletableFuture getPositionState(); - - /** - * Retrieves the current position of the door - * - * @return a future which will contain the door's current position - */ - CompletableFuture getCurrentPosition(); - - /** - * Retrieves the target position of the door - * - * @return a future which will contain the door's target position - */ - CompletableFuture getTargetPosition(); - - /** - * Sets the targeted state of the door. - * - * @param position the targeted position - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setTargetPosition(Integer position) throws Exception; - - /** - * Subscribes to changes in the door's position state - * - * @param callback the function to call when the state changes - */ - void subscribePositionState(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the door's current position - * - * @param callback the function to call when the current position changes - */ - void subscribeCurrentPosition(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the door's target position - * - * @param callback the function to call when the target position changes - */ - void subscribeTargetPosition(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the door's state */ - void unsubscribePositionState(); - - /** Unsubscribes from changes in the door's current position */ - void unsubscribeCurrentPosition(); - - /** Unsubscribes from changes in the door's target position */ - void unsubscribeTargetPosition(); - - @Override - default Collection getServices() { - return Collections.singleton(new WindowService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/WindowCoveringAccessory.java b/src/main/java/io/github/hapjava/accessories/WindowCoveringAccessory.java deleted file mode 100644 index 1b618d66f..000000000 --- a/src/main/java/io/github/hapjava/accessories/WindowCoveringAccessory.java +++ /dev/null @@ -1,77 +0,0 @@ -package io.github.hapjava.accessories; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.windowcovering.PositionStateEnum; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.WindowCoveringService; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -/** A window covering, like blinds, which can be remotely controlled. */ -public interface WindowCoveringAccessory extends HomekitAccessory { - /** - * Retrieves the current position - * - * @return a future that will contain the position as a value between 0 and 100 - */ - CompletableFuture getCurrentPosition(); - - /** - * Retrieves the target position - * - * @return a future that will contain the target position as a value between 0 and 100 - */ - CompletableFuture getTargetPosition(); - - /** - * Retrieves the state of the position: increasing, decreasing, or stopped - * - * @return a future that will contain the current state - */ - CompletableFuture getPositionState(); - - /** - * Sets the target position - * - * @param position the target position to set, as a value between 1 and 100 - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setTargetPosition(int position) throws Exception; - - /** - * Subscribes to changes in the current position. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentPosition(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the target position. - * - * @param callback the function to call when the state changes. - */ - void subscribeTargetPosition(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the position state: increasing, decreasing, or stopped - * - * @param callback the function to call when the state changes. - */ - void subscribePositionState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current position. */ - void unsubscribeCurrentPosition(); - - /** Unsubscribes from changes in the target position. */ - void unsubscribeTargetPosition(); - - /** Unsubscribes from changes in the position state */ - void unsubscribePositionState(); - - @Override - default Collection getServices() { - return Collections.singleton(new WindowCoveringService(this)); - } -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithAccessoryFlags.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithAccessoryFlags.java deleted file mode 100644 index 27d9c2e18..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithAccessoryFlags.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.accessoryinformation.AccessoryFlagsEnum; -import java.util.concurrent.CompletableFuture; - -/** Accessory with accessory flags, which indicates that additional setup is required */ -public interface AccessoryWithAccessoryFlags { - - /** - * When set indicates accessory requires additional setup. - * - * @return a future that will contain the accessory flags - */ - CompletableFuture getAccessoryFlags(); - - /** - * Subscribes to changes in accessory flags - * - * @param callback the function to call when the accessory flags changes. - */ - void subscribeAccessoryFlags(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the accessory flags . */ - void unsubscribeAccessoryFlags(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithActive.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithActive.java deleted file mode 100644 index 4ad11be63..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithActive.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.common.ActiveEnum; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with active characteristic {@link - * io.github.hapjava.characteristics.impl.common.ActiveCharacteristic}. - */ -public interface AccessoryWithActive { - - /** - * Retrieves the active state (see {@link - * io.github.hapjava.characteristics.impl.common.ActiveEnum} for supported values). - * - * @return a future that will contain the active state - */ - CompletableFuture getActive(); - - /** - * Set the active state (see {@link ActiveEnum} for supported values). - * - * @param active active state - * @return a future that completes when the change is made - */ - CompletableFuture setActive(ActiveEnum active); - - /** - * Subscribes to changes in the active state. - * - * @param callback the function to call when the active state changes. - */ - void subscribeActive(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the active state. */ - void unsubscribeActive(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithAirPlayEnable.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithAirPlayEnable.java deleted file mode 100644 index 76b90b43f..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithAirPlayEnable.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with AirPlay enable characteristic {@link - * io.github.hapjava.characteristics.impl.common.AirPlayEnableCharacteristic}. - */ -public interface AccessoryWithAirPlayEnable { - - /** - * Retrieves the AirPlay enable state - * - * @return a future that will contain the AirPlay enable state. - */ - CompletableFuture getAirPlayEnable(); - - /** - * Sets the AirPlay enable state - * - * @param state AirPlay enable state - * @return a future that completes when the AirPlay enable is changed - * @throws Exception when the AirPlay enable cannot be set - */ - CompletableFuture setAirPlayEnable(Integer state) throws Exception; - - /** - * Subscribes to changes in the AirPlay enable state. - * - * @param callback the function to call when the AirPlay enable state changes. - */ - void subscribeAirPlayEnable(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the AirPlay enable state. */ - void unsubscribeAirPlayEnable(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithBrightness.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithBrightness.java deleted file mode 100644 index 4fa4557c2..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithBrightness.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with brightness values. - * - * @author Andy Lintner - */ -public interface AccessoryWithBrightness { - - /** - * Retrieves the current brightness of the light - * - * @return a future that will contain the brightness, expressed as an integer between 0 and 100. - */ - CompletableFuture getBrightness(); - - /** - * Sets the current brightness of the light - * - * @param value the brightness, on a scale of 0 to 100, to set - * @return a future that completes when the brightness is changed - * @throws Exception when the brightness cannot be set - */ - CompletableFuture setBrightness(Integer value) throws Exception; - - /** - * Subscribes to changes in the brightness of the light. - * - * @param callback the function to call when the state changes. - */ - void subscribeBrightness(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the brightness of the light. */ - void unsubscribeBrightness(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCarbonDioxideLevel.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCarbonDioxideLevel.java deleted file mode 100644 index bd143b22f..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCarbonDioxideLevel.java +++ /dev/null @@ -1,104 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.carbondioxidesensor.CarbonDioxideLevelCharacteristic; -import io.github.hapjava.characteristics.impl.carbondioxidesensor.CarbonDioxidePeakLevelCharacteristic; -import java.util.concurrent.CompletableFuture; - -/** Accessory with carbon dioxide level and peak level characteristic. */ -public interface AccessoryWithCarbonDioxideLevel { - - /** - * Retrieves the carbon dioxide peak level - * - * @return a future that will contain the carbon dioxide level as a value between 0 and 100000 - */ - CompletableFuture getCarbonDioxidePeakLevel(); - - /** - * Retrieves the carbon dioxide level - * - * @return a future that will contain the carbon dioxide level as a value between 0 and 100000 - */ - CompletableFuture getCarbonDioxideLevel(); - - /** - * return the min value for carbon dioxide level. overwrite if you want to change the default - * value. - * - * @return min carbon dioxide level - */ - default double getMinCarbonDioxideLevel() { - return CarbonDioxideLevelCharacteristic.DEFAULT_MIN_VALUE; - } - - /** - * return the max value for carbon dioxide level. overwrite if you want to change the default - * value. - * - * @return max carbon dioxide level - */ - default double getMaxCarbonDioxideLevel() { - return CarbonDioxideLevelCharacteristic.DEFAULT_MAX_VALUE; - } - - /** - * return the min step value for carbon dioxide level. overwrite if you want to change the default - * value. - * - * @return min step carbon dioxide level - */ - default double getMinStepCarbonDioxideLevel() { - return CarbonDioxideLevelCharacteristic.DEFAULT_STEP; - } - - /** - * return the min value for carbon dioxide peak level. overwrite if you want to change the default - * value. - * - * @return min carbon dioxide peak level - */ - default double getMinCarbonDioxidePeakLevel() { - return CarbonDioxidePeakLevelCharacteristic.DEFAULT_MIN_VALUE; - } - - /** - * return the max value for carbon dioxide peak level. overwrite if you want to change the default - * value. - * - * @return max carbon dioxide peak level - */ - default double getMaxCarbonDioxidePeakLevel() { - return CarbonDioxidePeakLevelCharacteristic.DEFAULT_MAX_VALUE; - } - - /** - * return the min step value for carbon dioxide peak level. overwrite if you want to change the - * default value. - * - * @return min step carbon dioxide peak level - */ - default double getMinStepCarbonDioxidePeakLevel() { - return CarbonDioxidePeakLevelCharacteristic.DEFAULT_STEP; - } - - /** - * Subscribes to changes in the carbon dioxide level. - * - * @param callback the function to call when the state changes. - */ - void subscribeCarbonDioxideLevel(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the carbon dioxide level. */ - void unsubscribeCarbonDioxideLevel(); - - /** - * Subscribes to changes in the carbon dioxide level. - * - * @param callback the function to call when the state changes. - */ - void subscribeCarbonDioxidePeakLevel(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the carbon dioxide level. */ - void unsubscribeCarbonDioxidePeakLevel(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCarbonMonoxideLevel.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCarbonMonoxideLevel.java deleted file mode 100644 index cbccd9647..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCarbonMonoxideLevel.java +++ /dev/null @@ -1,104 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.carbonmonoxidesensor.CarbonMonoxideLevelCharacteristic; -import io.github.hapjava.characteristics.impl.carbonmonoxidesensor.CarbonMonoxidePeakLevelCharacteristic; -import java.util.concurrent.CompletableFuture; - -/** Accessory with carbon monoxide level and peak level characteristic. */ -public interface AccessoryWithCarbonMonoxideLevel { - - /** - * Retrieves the carbon monoxide peak level - * - * @return a future that will contain the carbon monoxide level as a value between 0 and 100000 - */ - CompletableFuture getCarbonMonoxidePeakLevel(); - - /** - * Retrieves the carbon monoxide level - * - * @return a future that will contain the carbon monoxide level as a value between 0 and 100000 - */ - CompletableFuture getCarbonMonoxideLevel(); - - /** - * return the min value for carbon monoxide level. overwrite if you want to change the default - * value. - * - * @return min carbon monoxide level - */ - default double getMinCarbonMonoxideLevel() { - return CarbonMonoxideLevelCharacteristic.DEFAULT_MIN_VALUE; - } - - /** - * return the max value for carbon monoxide level. overwrite if you want to change the default - * value. - * - * @return max carbon monoxide level - */ - default double getMaxCarbonMonoxideLevel() { - return CarbonMonoxideLevelCharacteristic.DEFAULT_MAX_VALUE; - } - - /** - * return the min step value for carbon monoxide level. overwrite if you want to change the - * default value. - * - * @return min step carbon monoxide level - */ - default double getMinStepCarbonMonoxideLevel() { - return CarbonMonoxideLevelCharacteristic.DEFAULT_STEP; - } - - /** - * return the min value for carbon monoxide peak level. overwrite if you want to change the - * default value. - * - * @return min carbon monoxide peak level - */ - default double getMinCarbonMonoxidePeakLevel() { - return CarbonMonoxidePeakLevelCharacteristic.DEFAULT_MIN_VALUE; - } - - /** - * return the max value for carbon monoxide peak level. overwrite if you want to change the - * default value. - * - * @return max carbon monoxide peak level - */ - default double getMaxCarbonMonoxidePeakLevel() { - return CarbonMonoxidePeakLevelCharacteristic.DEFAULT_MAX_VALUE; - } - - /** - * return the min step value for carbon monoxide peak level. overwrite if you want to change the - * default value. - * - * @return min step carbon monoxide peak level - */ - default double getMinStepCarbonMonoxidePeakLevel() { - return CarbonMonoxidePeakLevelCharacteristic.DEFAULT_STEP; - } - - /** - * Subscribes to changes in the carbon monoxide level. - * - * @param callback the function to call when the state changes. - */ - void subscribeCarbonMonoxideLevel(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the carbon monoxide level. */ - void unsubscribeCarbonMonoxideLevel(); - - /** - * Subscribes to changes in the carbon monoxide level. - * - * @param callback the function to call when the state changes. - */ - void subscribeCarbonMonoxidePeakLevel(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the carbon monoxide level. */ - void unsubscribeCarbonMonoxidePeakLevel(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithClosedCaptions.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithClosedCaptions.java deleted file mode 100644 index c13da3289..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithClosedCaptions.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.television.ClosedCaptionsEnum; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with closed captions characteristic {@link - * io.github.hapjava.characteristics.impl.television.ClosedCaptionsCharacteristic}. - */ -public interface AccessoryWithClosedCaptions { - - /** - * Retrieves the closed captions state (see {@link ClosedCaptionsEnum} for supported values). - * - * @return a future that will contain the closed captions - */ - CompletableFuture getClosedCaptions(); - - /** - * Set the closed captions state (see {@link ClosedCaptionsEnum} for supported values). - * - * @param closedCaptions closed captions - * @return a future that completes when the change is made - */ - CompletableFuture setClosedCaptions(ClosedCaptionsEnum closedCaptions); - - /** - * Subscribes to changes in the closed captions. - * - * @param callback the function to call when the closed captions changes. - */ - void subscribeClosedCaptions(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the closed captions. */ - void unsubscribeClosedCaptions(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithColor.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithColor.java deleted file mode 100644 index e8f2dd66a..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithColor.java +++ /dev/null @@ -1,64 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with Color - * - * @author Andy Lintner - */ -public interface AccessoryWithColor { - - /** - * Retrieves the current hue of the light. - * - * @return a future that will contain the hue, expressed in arc degrees from 0 to 360. - */ - CompletableFuture getHue(); - - /** - * Sets the current hue of the light - * - * @param value the hue to set, expressed in arc degrees from 0 to 360. - * @return a future that completes when the hue is changed - * @throws Exception when the hue cannot be changed. - */ - CompletableFuture setHue(Double value) throws Exception; - - /** - * Subscribes to changes in the hue of the light. - * - * @param callback the function to call when the state changes. - */ - void subscribeHue(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the hue of the light. */ - void unsubscribeHue(); - - /** - * Retrieves the saturation of the light. - * - * @return a future that will contain the saturation, expressed as a value between 0 and 100. - */ - CompletableFuture getSaturation(); - - /** - * Sets the saturation of the light. - * - * @param value the saturation to set, expressed as a value between 0 and 100. - * @return a future that completes when the saturation is changed. - * @throws Exception when the saturation cannot be set. - */ - CompletableFuture setSaturation(Double value) throws Exception; - - /** - * Subscribes to changes in the saturation of the light. - * - * @param callback the function to call when the state changes. - */ - void subscribeSaturation(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the saturation of the light. */ - void unsubscribeSaturation(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithColorTemperature.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithColorTemperature.java deleted file mode 100644 index ecf74ba63..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithColorTemperature.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.lightbulb.ColorTemperatureCharacteristic; -import java.util.concurrent.CompletableFuture; - -/** Accessory with color temperature. */ -public interface AccessoryWithColorTemperature { - - /** - * Retrieves the color temperature - * - * @return a future that will contain the brightness, expressed as an integer between 0 and 100. - */ - CompletableFuture getColorTemperature(); - - /** - * Sets the color temperature - * - * @param value the brightness, on a scale of 0 to 100, to set - * @return a future that completes when the brightness is changed - * @throws Exception when the brightness cannot be set - */ - CompletableFuture setColorTemperature(Integer value) throws Exception; - - /** - * return the min value for color temperature. overwrite if you want to change the default value. - * - * @return min color temperature - */ - default int getMinColorTemperature() { - return ColorTemperatureCharacteristic.DEFAULT_MIN_VALUE; - } - - /** - * return the max value for color temperature. overwrite if you want to change the default value. - * - * @return max color temperature - */ - default int getMaxColorTemperature() { - return ColorTemperatureCharacteristic.DEFAULT_MAX_VALUE; - } - - /** - * Subscribes to changes in color temperature. - * - * @param callback the function to call when the color temperature changes. - */ - void subscribeColorTemperature(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the color temperature. */ - void unsubscribeColorTemperature(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithConfiguredName.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithConfiguredName.java deleted file mode 100644 index 0c9528130..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithConfiguredName.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** Accessory with configured name. */ -public interface AccessoryWithConfiguredName { - - /** - * Retrieves configured name. - * - * @return configured name - */ - CompletableFuture getConfiguredName(); - - /** - * Sets the configured name - * - * @param name configured name - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setConfiguredName(String name) throws Exception; - - /** - * Subscribes to changes in configured name. - * - * @param callback the function to call when the configureed name changes. - */ - void subscribeConfiguredName(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the configured name state. */ - void unsubscribeConfiguredName(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCoolingThresholdTemperature.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCoolingThresholdTemperature.java deleted file mode 100644 index c42398a10..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCoolingThresholdTemperature.java +++ /dev/null @@ -1,63 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** Accessory with cooling threshold temperature. */ -public interface AccessoryWithCoolingThresholdTemperature { - - /** - * Retrieves the temperature above which the thermostat should begin cooling. - * - * @return a future that will contain the threshold temperature, in celsius degrees. - */ - CompletableFuture getCoolingThresholdTemperature(); - - /** - * Sets the temperature above which the thermostat should begin cooling. - * - * @param value the threshold temperature, in celsius degrees. - * @throws Exception when the threshold temperature cannot be changed. - */ - void setCoolingThresholdTemperature(Double value) throws Exception; - - /** - * return the min value for cooling threshold temperature. overwrite if you want to change the - * default value. - * - * @return min threshold temperature - */ - default double getMinCoolingThresholdTemperature() { - return 10; - } - - /** - * return the max value for cooling threshold temperature. overwrite if you want to change the - * default value. - * - * @return max threshold temperature - */ - default double getMaxCoolingThresholdTemperature() { - return 35; - } - - /** - * return the min step value for cooling threshold temperature. overwrite if you want to change - * the default value. - * - * @return step for threshold temperature - */ - default double getStepCoolingThresholdTemperature() { - return 0.1; - } - - /** - * Subscribes to changes in the cooling threshold. - * - * @param callback the function to call when the state changes. - */ - void subscribeCoolingThresholdTemperature(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the cooling threshold. */ - void unsubscribeCoolingThresholdTemperature(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCurrentHorizontalTilting.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCurrentHorizontalTilting.java deleted file mode 100644 index b5ce298bf..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCurrentHorizontalTilting.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with current horizontal tilting characteristic. - * - * @author Andy Lintner - */ -public interface AccessoryWithCurrentHorizontalTilting { - - /** - * Retrieves the current horizontal tilt angle - * - * @return a future that will contain the position as a value between -90 and 90 - */ - CompletableFuture getCurrentHorizontalTiltAngle(); - - /** - * Subscribes to changes in the current horizontal tilt angle. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentHorizontalTiltAngle(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current horizontal tilt angle */ - void unsubscribeCurrentHorizontalTiltAngle(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCurrentMediaState.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCurrentMediaState.java deleted file mode 100644 index 22350d9b4..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCurrentMediaState.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.television.CurrentMediaStateEnum; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with current media state characteristic {@link - * io.github.hapjava.characteristics.impl.television.CurrentMediaStateCharacteristic}. - */ -public interface AccessoryWithCurrentMediaState { - - /** - * Retrieves the current media state (see {@link - * io.github.hapjava.characteristics.impl.television.CurrentMediaStateEnum} for supported values). - * - * @return a future that will contain the current media state - */ - CompletableFuture getCurrentMediaState(); - - /** - * Subscribes to changes in the current media state. - * - * @param callback the function to call when the current media state changes. - */ - void subscribeCurrentMediaState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current media state. */ - void unsubscribeCurrentMediaState(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCurrentRelativeHumidity.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCurrentRelativeHumidity.java deleted file mode 100644 index 562e42649..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCurrentRelativeHumidity.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** accessory with current relative humidity. */ -public interface AccessoryWithCurrentRelativeHumidity { - - /** - * Retrieves the current relative humidity. - * - * @return a future that will contain the current relative humidity. - */ - CompletableFuture getCurrentRelativeHumidity(); - - /** - * Subscribes to changes in current relative humidity. - * - * @param callback the function to call when the current relative humidity changes. - */ - void subscribeCurrentRelativeHumidity(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current relative humidity. */ - void unsubscribeCurrentRelativeHumidity(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCurrentTilting.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCurrentTilting.java deleted file mode 100644 index 54a558491..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCurrentTilting.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** Accessory with current tilting characteristic. */ -public interface AccessoryWithCurrentTilting { - - /** - * Retrieves the current tilt angle - * - * @return a future that will contain the position as a value between -90 and 90 - */ - CompletableFuture getCurrentTiltAngle(); - - /** - * Subscribes to changes in the current tilt angle. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentTiltAngle(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current tilt angle */ - void unsubscribeCurrentTiltAngle(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCurrentVerticalTilting.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCurrentVerticalTilting.java deleted file mode 100644 index 3b996c925..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithCurrentVerticalTilting.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** Accessory with current vertical tilting characteristic. */ -public interface AccessoryWithCurrentVerticalTilting { - /** - * Retrieves the current vertical tilt angle - * - * @return a future that will contain the position as a value between -90 and 90 - */ - CompletableFuture getCurrentVerticalTiltAngle(); - - /** - * Subscribes to changes in the current vertical tilt angle. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentVerticalTiltAngle(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current vertical tilt angle */ - void unsubscribeCurrentVerticalTiltAngle(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithDuration.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithDuration.java deleted file mode 100644 index a5cebf97c..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithDuration.java +++ /dev/null @@ -1,52 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.valve.SetDurationCharacteristic; -import java.util.concurrent.CompletableFuture; - -/** Accessory with duration characteristic. */ -public interface AccessoryWithDuration { - - /** - * Retrieves the current set duration; - * - * @return a future with the value - */ - CompletableFuture getSetDuration(); - - /** - * return the min value for duration. overwrite if you want to change the default value. - * - * @return min remaining duration - */ - default int getMinDuration() { - return SetDurationCharacteristic.DEFAULT_MIN_VALUE; - } - - /** - * return the max value for duration. overwrite if you want to change the default value. - * - * @return max duration - */ - default int getMaxDuration() { - return SetDurationCharacteristic.DEFAULT_MAX_VALUE; - } - - /** - * Sets the duration for which the service should run. - * - * @param value duration in seconds - * @return a future that completes when the change is made - */ - CompletableFuture setSetDuration(int value); - - /** - * Subscribes to changes in the set duration - * - * @param callback the function when the duration has changed - */ - void subscribeSetDuration(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribeSetDuration(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithFanState.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithFanState.java deleted file mode 100644 index 75be61e8c..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithFanState.java +++ /dev/null @@ -1,56 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.fan.CurrentFanStateEnum; -import io.github.hapjava.characteristics.impl.fan.TargetFanStateEnum; -import java.util.concurrent.CompletableFuture; - -/** - * An accessory with current and target fan states. - * - * @author Andy Lintner - */ -public interface AccessoryWithFanState { - - /** - * Retrieves the current state of the fan (INACTIVE, IDLE, BLOWING AIR). - * - * @return a future that will contain the state - */ - CompletableFuture getCurrentFanState(); - - /** - * Retrieves the target state of the fan (MANUAL, AUTO). - * - * @return a future that will contain the state - */ - CompletableFuture getTargetFanState(); - - /** - * Set the target state of the fan (MANUAL, AUTO). - * - * @param targetState target state - * @return a future that completes when the change is made - */ - CompletableFuture setTargetFanState(TargetFanStateEnum targetState); - - /** - * Subscribes to changes in the current fan state. - * - * @param callback the function to call when the direction changes. - */ - void subscribeCurrentFanState(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the target fan state. - * - * @param callback the function to call when the direction changes. - */ - void subscribeTargetFanState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current state of the fan. */ - void unsubscribeCurrentFanState(); - - /** Unsubscribes from changes in the target state of the fan. */ - void unsubscribeTargetFanState(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithFilterLifeLevel.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithFilterLifeLevel.java deleted file mode 100644 index 2b94d4ec9..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithFilterLifeLevel.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** Accessory with filter level characteristics */ -public interface AccessoryWithFilterLifeLevel { - - /** - * what's the filter life level, percentage wise - * - * @return filter life level - */ - CompletableFuture getFilterLifeLevel(); - - /** - * Subscribes to changes in the filter life level. - * - * @param callback the function to call when the level changes. - */ - void subscribeFilterLifeLevel(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current filter life level. */ - void unsubscribeFilterLifeLevel(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithHardwareRevision.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithHardwareRevision.java deleted file mode 100644 index 866921817..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithHardwareRevision.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import java.util.concurrent.CompletableFuture; - -/** Accessory with hardware revision. */ -public interface AccessoryWithHardwareRevision { - - /** - * Returns a hardware revision to display in iOS. - * - * @return the hardware revision, or null. - */ - CompletableFuture getHardwareRevision(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithHeatingThresholdTemperature.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithHeatingThresholdTemperature.java deleted file mode 100644 index 02cb3f819..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithHeatingThresholdTemperature.java +++ /dev/null @@ -1,62 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -public interface AccessoryWithHeatingThresholdTemperature { - - /** - * Retrieves the temperature below which the thermostat should begin heating. - * - * @return a future that will contain the threshold temperature, in celsius degrees. - */ - CompletableFuture getHeatingThresholdTemperature(); - - /** - * Sets the temperature below which the thermostat should begin heating. - * - * @param value the threshold temperature, in celsius degrees. - * @throws Exception when the threshold temperature cannot be changed. - */ - void setHeatingThresholdTemperature(Double value) throws Exception; - - /** - * return the min value for heating threshold temperature. overwrite if you want to change the - * default value. - * - * @return min threshold temperature - */ - default double getMinHeatingThresholdTemperature() { - return 0; - } - - /** - * return the max value for heating threshold temperature. overwrite if you want to change the - * default value. - * - * @return max threshold temperature - */ - default double getMaxHeatingThresholdTemperature() { - return 25; - } - - /** - * return the min step value for heating threshold temperature. overwrite if you want to change - * the default value. - * - * @return step for threshold temperature - */ - default double getStepHeatingThresholdTemperature() { - return 0.1; - } - - /** - * Subscribes to changes in the heating threshold. - * - * @param callback the function to call when the state changes. - */ - void subscribeHeatingThresholdTemperature(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the heating threshold. */ - void unsubscribeHeatingThresholdTemperature(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithHoldPosition.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithHoldPosition.java deleted file mode 100644 index b1d0d65fa..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithHoldPosition.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import java.util.concurrent.CompletableFuture; - -/** Accessory with hold position */ -public interface AccessoryWithHoldPosition { - - /** - * Sets the hold position state - * - * @param hold whether or not to hold the current position state - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setHoldPosition(boolean hold) throws Exception; -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithHumidityDehumidifierThreshold.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithHumidityDehumidifierThreshold.java deleted file mode 100644 index 4dff49352..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithHumidityDehumidifierThreshold.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** Dehumidifier with humidity threshold. */ -public interface AccessoryWithHumidityDehumidifierThreshold { - - /** - * Retrieves the humidity threshold. - * - * @return a future that will contain the humidity threshold. - */ - CompletableFuture getHumidityThreshold(); - - /** - * Sets the humidity threshold above which the dehumidifier should be turned on. - * - * @param value the humidity threshold, in celsius degrees. - * @throws Exception when the threshold cannot be changed. - */ - void setHumidityThreshold(Double value) throws Exception; - - /** - * Subscribes to changes in the humidity threshold. - * - * @param callback the function to call when the state changes. - */ - void subscribeHumidityThreshold(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the humidity threshold. */ - void unsubscribeHumidityThreshold(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithHumidityHumidifierThreshold.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithHumidityHumidifierThreshold.java deleted file mode 100644 index f783a3039..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithHumidityHumidifierThreshold.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** Humidifier with humidity threshold. */ -public interface AccessoryWithHumidityHumidifierThreshold { - - /** - * Retrieves the humidity threshold. - * - * @return a future that will contain the humidity threshold. - */ - CompletableFuture getHumidityThreshold(); - - /** - * Sets the humidity threshold above which the humidifier should be turned on. - * - * @param value the humidity threshold, in celsius degrees. - * @throws Exception when the threshold cannot be changed. - */ - void setHumidityThreshold(Double value) throws Exception; - - /** - * Subscribes to changes in the humidity threshold. - * - * @param callback the function to call when the state changes. - */ - void subscribeHumidityThreshold(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the humidity threshold. */ - void unsubscribeHumidityThreshold(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithIdentifier.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithIdentifier.java deleted file mode 100644 index b181d4d99..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithIdentifier.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with identifier characteristic {@link - * io.github.hapjava.characteristics.impl.common.IdentifierCharacteristic}. - */ -public interface AccessoryWithIdentifier { - - /** - * Retrieves the identifier of service. - * - * @return a future with the identifier - */ - CompletableFuture getIdentifier(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithInputDeviceType.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithInputDeviceType.java deleted file mode 100644 index fca5f5df1..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithInputDeviceType.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.inputsource.InputDeviceTypeEnum; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with input devices, e.g. television. {@link - * io.github.hapjava.characteristics.impl.inputsource.InputDeviceTypeCharacteristic} - */ -public interface AccessoryWithInputDeviceType { - - /** - * Retrieves the input device type. See {@link InputDeviceTypeEnum} for supported values. - * - * @return a future with the value - */ - CompletableFuture getInputDeviceType(); - - /** - * Subscribes to changes in input device type. - * - * @param callback the function when the input device type changes - */ - void subscribeInputDeviceType(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribeInputDeviceType(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithIsConfigured.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithIsConfigured.java deleted file mode 100644 index 017fdce5f..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithIsConfigured.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.common.IsConfiguredEnum; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with isConfigured characteristics. This characteristic describes if the service is - * configured for use. For example, all of the valves in an irrigation system may not be configured - * depending on physical wire connection. - */ -public interface AccessoryWithIsConfigured { - - /** - * isConfigured state - * - * @return a future that will contain the isConfigured state - */ - CompletableFuture getIsConfigured(); - - /** - * Set the isConfigured (NOT_CONFIGURED, CONFIGURED). - * - * @param isConfigured isConfigured state - * @return a future that completes when the change is made - */ - CompletableFuture setIsConfigured(IsConfiguredEnum isConfigured); - - /** - * Subscribes to changes in isConfigured state - * - * @param callback the function to call when the isConfigured state changes. - */ - void subscribeIsConfigured(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the isConfigured state. */ - void unsubscribeIsConfigured(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithLockCurrentState.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithLockCurrentState.java deleted file mode 100644 index f3f9782ca..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithLockCurrentState.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.lock.LockCurrentStateEnum; -import java.util.concurrent.CompletableFuture; - -/** Accessory with current lock state. */ -public interface AccessoryWithLockCurrentState { - - /** - * Retrieves the lock states. The current state of the physical security mechanism (e.g. deadbolt) - * - * @return a future with the value - */ - CompletableFuture getLockCurrentState(); - - /** - * Subscribes to changes in lock current state. - * - * @param callback the function when the lock current state changes - */ - void subscribeLockCurrentState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribeLockCurrentState(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithLockTargetState.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithLockTargetState.java deleted file mode 100644 index 41ef0d3ed..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithLockTargetState.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.lock.LockTargetStateEnum; -import java.util.concurrent.CompletableFuture; - -/** Accessory with lock target state. */ -public interface AccessoryWithLockTargetState { - - /** - * Retrieves the lock states. The target state of the physical security mechanism (e.g. deadbolt) - * - * @return a future with the value - */ - CompletableFuture getLockTargetState(); - - /** - * Sets the lock target state - * - * @param state the target state to set - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setLockTargetState(LockTargetStateEnum state) throws Exception; - - /** - * Subscribes to changes in lock target state. - * - * @param callback the function when the lock target state changes - */ - void subscribeLockTargetState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribeLockTargetState(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithMute.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithMute.java deleted file mode 100644 index a0bb08579..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithMute.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with mute characteristic {@link - * io.github.hapjava.characteristics.impl.audio.MuteCharacteristic}. - */ -public interface AccessoryWithMute { - - /** - * Retrieves mute status. - * - * @return true if accessory is muted - */ - CompletableFuture isMuted(); - - /** - * Sets the mute status - * - * @param mute true if accessory should be muted - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setMute(boolean mute) throws Exception; - - /** - * Subscribes to changes in mute state. - * - * @param callback the function to call when the state changes. - */ - void subscribeMuteState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the mute state. */ - void unsubscribeMuteState(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithName.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithName.java deleted file mode 100644 index 626429124..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithName.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import java.util.concurrent.CompletableFuture; - -/** Accessory with name. */ -public interface AccessoryWithName { - - /** - * Retrieves the name of service. - * - * @return a future with the name - */ - CompletableFuture getName(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithNitrogenDioxideDensity.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithNitrogenDioxideDensity.java deleted file mode 100644 index 6aead4f98..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithNitrogenDioxideDensity.java +++ /dev/null @@ -1,56 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.airquality.NitrogenDioxideDensityCharacteristic; -import java.util.concurrent.CompletableFuture; - -/** Accessory with nitrogen dioxide density characteristic. */ -public interface AccessoryWithNitrogenDioxideDensity { - - /** - * Retrieves the nitrogen dioxide density. - * - * @return a future with the nitrogen dioxide density - */ - CompletableFuture getNitrogenDioxideDensity(); - - /** - * return the min value for nitrogen dioxide density. overwrite if you want to change the default - * value. - * - * @return min nitrogen dioxide density - */ - default double getMinNitrogenDioxideDensity() { - return NitrogenDioxideDensityCharacteristic.DEFAULT_MIN_VALUE; - } - - /** - * return the max value for nitrogen dioxide density. overwrite if you want to change the default - * value. - * - * @return max nitrogen dioxide density - */ - default double getMaxNitrogenDioxideDensity() { - return NitrogenDioxideDensityCharacteristic.DEFAULT_MAX_VALUE; - } - - /** - * return the min step value for nitrogen dioxide density. overwrite if you want to change the - * default value. - * - * @return min step nitrogen dioxide density - */ - default double getMinStepNitrogenDioxideDensity() { - return NitrogenDioxideDensityCharacteristic.DEFAULT_STEP; - } - - /** - * Subscribes to changes in nitrogen dioxide density. - * - * @param callback the function when nitrogen dioxide density changes - */ - void subscribeNitrogenDioxideDensity(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribeNitrogenDioxideDensity(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithObstructionDetection.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithObstructionDetection.java deleted file mode 100644 index 859379cd0..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithObstructionDetection.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** Accessory with hold position */ -public interface AccessoryWithObstructionDetection { - - /** - * Retrieves an indication obstructed is detected - * - * @return a future that will contain a boolean indicating whether an obstruction is present - */ - CompletableFuture getObstructionDetected(); - - /** - * Subscribes to changes in the obstruction detected state - * - * @param callback the function to call when the state changes. - */ - void subscribeObstructionDetected(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the obstruction detected state */ - void unsubscribeObstructionDetected(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithOzoneDensity.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithOzoneDensity.java deleted file mode 100644 index efba2a49f..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithOzoneDensity.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.airquality.OzoneDensityCharacteristic; -import java.util.concurrent.CompletableFuture; - -/** Accessory with Ozone Density characteristic. */ -public interface AccessoryWithOzoneDensity { - - /** - * Retrieves the ozone density. - * - * @return a future with the ozone density - */ - CompletableFuture getOzoneDensity(); - - /** - * return the min value for ozone density. overwrite if you want to change the default value. - * - * @return min ozone density - */ - default double getMinOzoneDensity() { - return OzoneDensityCharacteristic.DEFAULT_MIN_VALUE; - } - - /** - * return the max value for ozone density. overwrite if you want to change the default value. - * - * @return max ozone density - */ - default double getMaxOzoneDensity() { - return OzoneDensityCharacteristic.DEFAULT_MAX_VALUE; - } - - /** - * return the min step value for ozone density. overwrite if you want to change the default value. - * - * @return min step ozone density - */ - default double getMinStepOzoneDensity() { - return OzoneDensityCharacteristic.DEFAULT_STEP; - } - - /** - * Subscribes to changes in ozone density. - * - * @param callback the function when ozone density changes - */ - void subscribeOzoneDensity(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribeOzoneDensity(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithPM10Density.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithPM10Density.java deleted file mode 100644 index 2ae3cded0..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithPM10Density.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.airquality.PM10DensityCharacteristic; -import java.util.concurrent.CompletableFuture; - -/** Accessory with PM10 Density characteristic. */ -public interface AccessoryWithPM10Density { - - /** - * Retrieves the PM10 density. - * - * @return a future with the PM10 density - */ - CompletableFuture getPM10Density(); - - /** - * return the min value for PM10 density. overwrite if you want to change the default value. - * - * @return min PM10 density - */ - default double getMinPM10Density() { - return PM10DensityCharacteristic.DEFAULT_MIN_VALUE; - } - - /** - * return the max value for PM10 density. overwrite if you want to change the default value. - * - * @return max PM10 density - */ - default double getMaxPM10Density() { - return PM10DensityCharacteristic.DEFAULT_MAX_VALUE; - } - - /** - * return the min step value for PM10 density. overwrite if you want to change the default value. - * - * @return min step PM10 density - */ - default double getMinStepPM10Density() { - return PM10DensityCharacteristic.DEFAULT_STEP; - } - - /** - * Subscribes to changes in PM10 density. - * - * @param callback the function when PM10 density changes - */ - void subscribePM10Density(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribePM10Density(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithPM25Density.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithPM25Density.java deleted file mode 100644 index 02488f52d..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithPM25Density.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.airquality.PM25DensityCharacteristic; -import java.util.concurrent.CompletableFuture; - -/** Accessory with PM25 Density characteristic. */ -public interface AccessoryWithPM25Density { - - /** - * Retrieves the PM25 density. - * - * @return a future with the PM25 density - */ - CompletableFuture getPM25Density(); - - /** - * return the min value for PM25 density. overwrite if you want to change the default value. - * - * @return min PM25 density - */ - default double getMinPM25Density() { - return PM25DensityCharacteristic.DEFAULT_MIN_VALUE; - } - - /** - * return the max value for PM25 density. overwrite if you want to change the default value. - * - * @return max PM25 density - */ - default double getMaxPM25Density() { - return PM25DensityCharacteristic.DEFAULT_MAX_VALUE; - } - - /** - * return the min step value for PM25 density. overwrite if you want to change the default value. - * - * @return min step PM25 density - */ - default double getMinStepPM25Density() { - return PM25DensityCharacteristic.DEFAULT_STEP; - } - - /** - * Subscribes to changes in PM25 density. - * - * @param callback the function when PM25 density changes - */ - void subscribePM25Density(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribePM25Density(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithPhysicalControlsLock.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithPhysicalControlsLock.java deleted file mode 100644 index 2e1e3cd87..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithPhysicalControlsLock.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.fan.LockPhysicalControlsEnum; -import java.util.concurrent.CompletableFuture; - -/** Accessory with physical controls which can be locked, e.g. child lock */ -public interface AccessoryWithPhysicalControlsLock { - - /** - * OPTIONAL: Retrieves the lock controls. - * - * @return a future that will contain the lock controls - */ - CompletableFuture getLockControls(); - - /** - * Set the lock controls (DISABLED, ENABLED). - * - * @param lockControls lock controls mode - * @return a future that completes when the change is made - */ - CompletableFuture setLockControls(LockPhysicalControlsEnum lockControls); - - /** - * Subscribes to changes in the lock controls. - * - * @param callback the function to call when the lock controls changes. - */ - void subscribeLockControls(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the lock controls. */ - void unsubscribeLockControls(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithPictureMode.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithPictureMode.java deleted file mode 100644 index b369b98bf..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithPictureMode.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.television.PictureModeEnum; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with picture mode characteristic {@link - * io.github.hapjava.characteristics.impl.television.PictureModeCharacteristic}. - */ -public interface AccessoryWithPictureMode { - - /** - * Retrieves the picture mode (see {@link - * io.github.hapjava.characteristics.impl.television.PictureModeEnum} for supported values). - * - * @return a future that will contain the picture mode - */ - CompletableFuture getPictureMode(); - - /** - * Set the picture mode (see {@link - * io.github.hapjava.characteristics.impl.television.PictureModeEnum} for supported values). - * - * @param pictureMode picture mode - * @return a future that completes when the change is made - */ - CompletableFuture setPictureMode(PictureModeEnum pictureMode); - - /** - * Subscribes to changes in the picture mode. - * - * @param callback the function to call when the picture mode changes. - */ - void subscribePictureMode(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the picture mode. */ - void unsubscribePictureMode(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithPowerMode.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithPowerMode.java deleted file mode 100644 index 5abb7e6f1..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithPowerMode.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.impl.television.PowerModeEnum; -import java.util.concurrent.CompletableFuture; - -/** An accessory with power mode. */ -public interface AccessoryWithPowerMode { - - /** - * Set the power mode. See {@link PowerModeEnum} for supported values - * - * @param mode target power mode - * @return a future that completes when the change is made - */ - CompletableFuture setPowerMode(PowerModeEnum mode); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithRemainingDuration.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithRemainingDuration.java deleted file mode 100644 index 7859fb396..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithRemainingDuration.java +++ /dev/null @@ -1,49 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.valve.RemainingDurationCharacteristic; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with remaining duration characteristic. - * - * @author Tim Harper - */ -public interface AccessoryWithRemainingDuration { - - /** - * Retrieves the remaining duration - * - * @return a future with the duration in seconds - */ - CompletableFuture getRemainingDuration(); - - /** - * return the min value for remaining duration. overwrite if you want to change the default value. - * - * @return min remaining duration - */ - default int getMinRemainingDuration() { - return RemainingDurationCharacteristic.DEFAULT_MIN_VALUE; - } - - /** - * return the max value for remaining duration. overwrite if you want to change the default value. - * - * @return max remaining duration - */ - default int getMaxRemainingDuration() { - return RemainingDurationCharacteristic.DEFAULT_MAX_VALUE; - } - - /** - * Subscribes to changes in the duration; note it is not necessary to emit a change every second, - * homekit infers the countdown progress client side. - * - * @param callback the function when the existing duration has been replaced with a new one. - */ - void subscribeRemainingDuration(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribeRemainingDuration(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithResetFilterIndication.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithResetFilterIndication.java deleted file mode 100644 index 737ca03ec..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithResetFilterIndication.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import java.util.concurrent.CompletableFuture; - -/** Accessory with filter reset characteristics */ -public interface AccessoryWithResetFilterIndication { - - /** - * Request to reset the filter level - * - * @param indication always 1, by HomeKit protocol. (to be ignored) - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture resetFilterIndication(Integer indication) throws Exception; -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithRotationDirection.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithRotationDirection.java deleted file mode 100644 index 91acf9afa..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithRotationDirection.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.fan.RotationDirectionEnum; -import java.util.concurrent.CompletableFuture; - -/** accessory with rotation direction characteristics. */ -public interface AccessoryWithRotationDirection { - - /** - * Retrieves the current rotation direction. - * - * @return a future that will contain the direction - */ - CompletableFuture getRotationDirection(); - - /** - * Sets the rotation direction - * - * @param direction the direction to set - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setRotationDirection(RotationDirectionEnum direction) throws Exception; - - /** - * Subscribes to changes in the rotation direction. - * - * @param callback the function to call when the direction changes. - */ - void subscribeRotationDirection(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the rotation direction. */ - void unsubscribeRotationDirection(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithRotationSpeed.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithRotationSpeed.java deleted file mode 100644 index ef39947ce..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithRotationSpeed.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** accessory with rotation speed characteristics. */ -public interface AccessoryWithRotationSpeed { - - /** - * Retrieves the current speed of the rotation - * - * @return a future that will contain the speed, expressed as an integer between 0 and 100. - */ - CompletableFuture getRotationSpeed(); - - /** - * Sets the speed of the rotation - * - * @param speed the speed to set, expressed as an integer between 0 and 100. - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setRotationSpeed(Double speed) throws Exception; - - /** - * Subscribes to changes in the rotation speed. - * - * @param callback the function to call when the speed changes. - */ - void subscribeRotationSpeed(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the rotation speed. */ - void unsubscribeRotationSpeed(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithSecurityAlarmType.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithSecurityAlarmType.java deleted file mode 100644 index 036fd35b3..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithSecurityAlarmType.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.securitysystem.SecuritySystemAlarmTypeEnum; -import java.util.concurrent.CompletableFuture; - -/** This characteristic describes the type of alarm triggered by a security system. */ -public interface AccessoryWithSecurityAlarmType { - - /** - * return alarm type See {@link SecuritySystemAlarmTypeEnum} for possible values - * - * @return a future with the value - */ - CompletableFuture getSecurityAlarmType(); - - /** - * Subscribes to changes in status alarm type - * - * @param callback the function when the alarm type changes - */ - void subscribeSecurityAlarmType(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribeSecurityAlarmType(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithServiceLabelIndex.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithServiceLabelIndex.java deleted file mode 100644 index 07cb17fc7..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithServiceLabelIndex.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import java.util.concurrent.CompletableFuture; - -/** Accessory with service label index. T */ -public interface AccessoryWithServiceLabelIndex { - - /** - * Retrieves the service label index. - * - * @return a future with the service label index - */ - CompletableFuture getServiceLabelIndex(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithStatusActive.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithStatusActive.java deleted file mode 100644 index 6bd7a18b5..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithStatusActive.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** Accessory with status active. */ -public interface AccessoryWithStatusActive { - - /** - * Retrieves the status active. A value of true indicates that the accessory is active and is - * functioning without any errors. - * - * @return a future with the value - */ - CompletableFuture getStatusActive(); - - /** - * Subscribes to changes in status active. - * - * @param callback the function when the status active changes - */ - void subscribeStatusActive(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribeStatusActive(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithStatusFault.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithStatusFault.java deleted file mode 100644 index b6b0aebdf..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithStatusFault.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.common.StatusFaultEnum; -import java.util.concurrent.CompletableFuture; - -/** Accessory with characteristic that describes an accessory which has a fault. */ -public interface AccessoryWithStatusFault { - - /** - * Retrieves the status fault. A non-zero value indicates that the accessory has experienced a - * fault that may be interfering with its intended functionality. A value of 0 indicates that - * there is no fault. - * - * @return a future with the value - */ - CompletableFuture getStatusFault(); - - /** - * Subscribes to changes in status fault. - * - * @param callback the function when the status fault changes - */ - void subscribeStatusFault(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribeStatusFault(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithStatusLowBattery.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithStatusLowBattery.java deleted file mode 100644 index def16df5d..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithStatusLowBattery.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.battery.StatusLowBatteryEnum; -import java.util.concurrent.CompletableFuture; - -/** This characteristic describes an accessoryʼs battery status. */ -public interface AccessoryWithStatusLowBattery { - - /** - * A status of 1 indicates that the battery level of the accessory is low. Value should return to - * 0 when the battery charges to a level thats above the low threshold. - * - * @return a future with the value - */ - CompletableFuture getStatusLowBattery(); - - /** - * Subscribes to changes in status low battery. - * - * @param callback the function when the status low batter changes - */ - void subscribeStatusLowBattery(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribeStatusLowBattery(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithStatusTampered.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithStatusTampered.java deleted file mode 100644 index fe25d2f44..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithStatusTampered.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.common.StatusTamperedEnum; -import java.util.concurrent.CompletableFuture; - -/** This characteristic describes an accessory which has been tampered with. */ -public interface AccessoryWithStatusTampered { - - /** - * Retrieves the status tampered. - * - * @return a future with the value - */ - CompletableFuture getStatusTampered(); - - /** - * Subscribes to changes in status tampered. - * - * @param callback the function when the status tampered changes - */ - void subscribeStatusTampered(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribeStatusTampered(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithSulphurDioxideDensity.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithSulphurDioxideDensity.java deleted file mode 100644 index dbe0cc947..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithSulphurDioxideDensity.java +++ /dev/null @@ -1,56 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.airquality.SulphurDioxideDensityCharacteristic; -import java.util.concurrent.CompletableFuture; - -/** Accessory with sulphur dioxide density characteristic. */ -public interface AccessoryWithSulphurDioxideDensity { - - /** - * Retrieves the sulphur dioxide density. - * - * @return a future with the sulphur dioxide density - */ - CompletableFuture getSulphurDioxideDensity(); - - /** - * return the min value for sulphur dioxide density. overwrite if you want to change the default - * value. - * - * @return min sulphur dioxide density - */ - default double getMinSulphurDioxideDensity() { - return SulphurDioxideDensityCharacteristic.DEFAULT_MIN_VALUE; - } - - /** - * return the max value for sulphur dioxide density. overwrite if you want to change the default - * value. - * - * @return max sulphur dioxide density - */ - default double getMaxSulphurDioxideDensity() { - return SulphurDioxideDensityCharacteristic.DEFAULT_MAX_VALUE; - } - - /** - * return the min step value for sulphur dioxide density. overwrite if you want to change the - * default value. - * - * @return min step sulphur dioxide density - */ - default double getMinStepSulphurDioxideDensity() { - return SulphurDioxideDensityCharacteristic.DEFAULT_STEP; - } - - /** - * Subscribes to changes in sulphur dioxide density. - * - * @param callback the function when sulphur dioxide density changes - */ - void subscribeSulphurDioxideDensity(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribeSulphurDioxideDensity(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithSwingMode.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithSwingMode.java deleted file mode 100644 index ae49ffee6..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithSwingMode.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.fan.SwingModeEnum; -import java.util.concurrent.CompletableFuture; - -/** Accessory with Swing Mode characteristics. */ -public interface AccessoryWithSwingMode { - - /** - * Retrieves the swing mode. - * - * @return a future that will contain the swing mode - */ - CompletableFuture getSwingMode(); - - /** - * Set the swing mode (DISABLED, ENABLED). - * - * @param swingMode swing mode - * @return a future that completes when the change is made - */ - CompletableFuture setSwingMode(SwingModeEnum swingMode); - - /** - * Subscribes to changes in the swing mode. - * - * @param callback the function to call when the swing mode changes. - */ - void subscribeSwingMode(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the swing mode. */ - void unsubscribeSwingMode(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetHorizontalTilting.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetHorizontalTilting.java deleted file mode 100644 index cc154520d..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetHorizontalTilting.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with target horizontal tilting characteristic. - * - * @author Andy Lintner - */ -public interface AccessoryWithTargetHorizontalTilting { - - /** - * Retrieves the target horizontal tilt angle - * - * @return a future that will contain the target position as a value between -90 and 90 - */ - CompletableFuture getTargetHorizontalTiltAngle(); - - /** - * Sets the target position - * - * @param angle the target angle to set, as a value between -90 and 90 - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setTargetHorizontalTiltAngle(int angle) throws Exception; - - /** - * Subscribes to changes in the target horizontal tilt angle. - * - * @param callback the function to call when the state changes. - */ - void subscribeTargetHorizontalTiltAngle(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the target horizontal tilt angle */ - void unsubscribeTargetHorizontalTiltAngle(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetMediaState.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetMediaState.java deleted file mode 100644 index e1f1a34bd..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetMediaState.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.television.TargetMediaStateEnum; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with target media state characteristic {@link - * io.github.hapjava.characteristics.impl.television.TargetMediaStateCharacteristic}. - */ -public interface AccessoryWithTargetMediaState { - - /** - * Retrieves the target media state (see {@link TargetMediaStateEnum} for supported values). - * - * @return a future that will contain the target media state - */ - CompletableFuture getTargetMediaState(); - - /** - * Set the target media state (see {@link TargetMediaStateEnum} for supported values). - * - * @param targetMediaState target media state - * @return a future that completes when the change is made - */ - CompletableFuture setTargetMediaState(TargetMediaStateEnum targetMediaState); - - /** - * Subscribes to changes in the target media state. - * - * @param callback the function to call when the target media state changes. - */ - void subscribeTargetMediaState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the target media state. */ - void unsubscribeTargetMediaState(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetRelativeHumidity.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetRelativeHumidity.java deleted file mode 100644 index 23ac5fd97..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetRelativeHumidity.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** accessory with target relative humidity. */ -public interface AccessoryWithTargetRelativeHumidity { - - /** - * Retrieves the target relative humidity. - * - * @return a future that will contain the target relative humidity. - */ - CompletableFuture getTargetRelativeHumidity(); - - /** - * Sets the target relative humidity. - * - * @param value the target relative humidity. - * @throws Exception when the target relative humidity cannot be changed. - */ - void setTargetRelativeHumidity(Double value) throws Exception; - - /** - * Subscribes to changes in the target relative humidity. - * - * @param callback the function to call when the target relative humidity changes. - */ - void subscribeTargetRelativeHumidity(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the target relative humidity. */ - void unsubscribeTargetRelativeHumidity(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetTilting.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetTilting.java deleted file mode 100644 index 9c2bc8009..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetTilting.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** Accessory with target tilting characteristic. */ -public interface AccessoryWithTargetTilting { - - /** - * Retrieves the target tilt angle - * - * @return a future that will contain the target position as a value between -90 and 90 - */ - CompletableFuture getTargetTiltAngle(); - - /** - * Sets the target tilt angle - * - * @param angle the target angle to set, as a value between -90 and 90 - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setTargetTiltAngle(int angle) throws Exception; - - /** - * Subscribes to changes in the target tilt angle. - * - * @param callback the function to call when the state changes. - */ - void subscribeTargetTiltAngle(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the target tilt angle */ - void unsubscribeTargetTiltAngle(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetVerticalTilting.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetVerticalTilting.java deleted file mode 100644 index e87607204..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetVerticalTilting.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** Accessory with target vertical tilting characteristic. */ -public interface AccessoryWithTargetVerticalTilting { - - /** - * Retrieves the target vertical tilt angle - * - * @return a future that will contain the target position as a value between -90 and 90 - */ - CompletableFuture getTargetVerticalTiltAngle(); - - /** - * Sets the target position - * - * @param angle the target angle to set, as a value between -90 and 90 - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setTargetVerticalTiltAngle(int angle) throws Exception; - - /** - * Subscribes to changes in the target vertical tilt angle. - * - * @param callback the function to call when the state changes. - */ - void subscribeTargetVerticalTiltAngle(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the target vertical tilt angle */ - void unsubscribeTargetVerticalTiltAngle(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetVisibilityState.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetVisibilityState.java deleted file mode 100644 index dcadd1cc5..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTargetVisibilityState.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.inputsource.TargetVisibilityStateEnum; -import java.util.concurrent.CompletableFuture; - -/** accessory with target visibility state characteristics. */ -public interface AccessoryWithTargetVisibilityState { - - /** - * Retrieves the target visibility state. - * - * @return a future that will contain the target visibility state - */ - CompletableFuture getTargetVisibilityState(); - - /** - * Sets the target visibility state - * - * @param state the target visibility state to set - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setTargetVisibilityState(TargetVisibilityStateEnum state) - throws Exception; - - /** - * Subscribes to changes in t target visibility state. - * - * @param callback the function to call when the target visibility state changes. - */ - void subscribeTargetVisibilityState(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the target visibility state. */ - void unsubscribeTargetVisibilityState(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTemperatureDisplayUnits.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTemperatureDisplayUnits.java deleted file mode 100644 index b9407b34b..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithTemperatureDisplayUnits.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.thermostat.TemperatureDisplayUnitEnum; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with characteristic that describes units of temperature used for presentation purposes - * (e.g. the units of temperature displayed on the screen). - */ -public interface AccessoryWithTemperatureDisplayUnits { - - /** - * Retrieves temperature display units - * - * @return a future that will contain temperature display units - */ - CompletableFuture getTemperatureDisplayUnits(); - - /** - * Sets the temperature display units - * - * @param units the target temperature display units - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setTemperatureDisplayUnits(TemperatureDisplayUnitEnum units) - throws Exception; - - /** - * Subscribes to changes in the temperature display units - * - * @param callback the function to call when temperature display units changes. - */ - void subscribeTemperatureDisplayUnits(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the temperature display units */ - void unsubscribeTemperatureDisplayUnits(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithVOCDensity.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithVOCDensity.java deleted file mode 100644 index f8a7bc46b..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithVOCDensity.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.airquality.VOCDensityCharacteristic; -import java.util.concurrent.CompletableFuture; - -/** Accessory with VOC Density characteristic. */ -public interface AccessoryWithVOCDensity { - - /** - * Retrieves the VOC density. - * - * @return a future with the VOC density - */ - CompletableFuture getVOCDensity(); - - /** - * return the min value for VOC density. overwrite if you want to change the default value. - * - * @return min VOC density - */ - default double getMinVOCDensity() { - return VOCDensityCharacteristic.DEFAULT_MIN_VALUE; - } - - /** - * return the max value for VOC density. overwrite if you want to change the default value. - * - * @return max VOC density - */ - default double getMaxVOCDensity() { - return VOCDensityCharacteristic.DEFAULT_MAX_VALUE; - } - - /** - * return the min step value for VOC density. overwrite if you want to change the default value. - * - * @return min step VOC density - */ - default double getMinStepVOCDensity() { - return VOCDensityCharacteristic.DEFAULT_STEP; - } - - /** - * Subscribes to changes in VOC density. - * - * @param callback the function when VOC density changes - */ - void subscribeVOCDensity(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes */ - void unsubscribeVOCDensity(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithVerticalTilting.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithVerticalTilting.java deleted file mode 100644 index 3e849e5bb..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithVerticalTilting.java +++ /dev/null @@ -1,50 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** Accessory with vertical tilting characteristic. */ -public interface AccessoryWithVerticalTilting { - /** - * Retrieves the current vertical tilt angle - * - * @return a future that will contain the position as a value between -90 and 90 - */ - CompletableFuture getCurrentVerticalTiltAngle(); - - /** - * Retrieves the target vertical tilt angle - * - * @return a future that will contain the target position as a value between -90 and 90 - */ - CompletableFuture getTargetVerticalTiltAngle(); - - /** - * Sets the target position - * - * @param angle the target angle to set, as a value between -90 and 90 - * @return a future that completes when the change is made - * @throws Exception when the change cannot be made - */ - CompletableFuture setTargetVerticalTiltAngle(int angle) throws Exception; - - /** - * Subscribes to changes in the current vertical tilt angle. - * - * @param callback the function to call when the state changes. - */ - void subscribeCurrentVerticalTiltAngle(HomekitCharacteristicChangeCallback callback); - - /** - * Subscribes to changes in the target vertical tilt angle. - * - * @param callback the function to call when the state changes. - */ - void subscribeTargetVerticalTiltAngle(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the current vertical tilt angle */ - void unsubscribeCurrentVerticalTiltAngle(); - - /** Unsubscribes from changes in the target vertical tilt angle */ - void unsubscribeTargetVerticalTiltAngle(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithVolume.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithVolume.java deleted file mode 100644 index b6dda376f..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithVolume.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** Accessory with volume values. */ -public interface AccessoryWithVolume { - - /** - * Retrieves the current volume - * - * @return a future that will contain the volume, expressed as an integer between 0 and 100. - */ - CompletableFuture getVolume(); - - /** - * Sets the current volume - * - * @param value the volume, on a scale of 0 to 100, to set - * @return a future that completes when the volume is changed - * @throws Exception when the volume cannot be set - */ - CompletableFuture setVolume(Integer value) throws Exception; - - /** - * Subscribes to changes in the volume. - * - * @param callback the function to call when the state changes. - */ - void subscribeVolume(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the volume. */ - void unsubscribeVolume(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithVolumeControlType.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithVolumeControlType.java deleted file mode 100644 index 21a6f6c66..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithVolumeControlType.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.televisionspeaker.VolumeControlTypeEnum; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with volume control type {@link - * io.github.hapjava.characteristics.impl.televisionspeaker.VolumeControlTypeCharacteristic} - */ -public interface AccessoryWithVolumeControlType { - - /** - * Retrieves the current volume control type. see {@link VolumeControlTypeEnum} for possible - * values - * - * @return a future that will contain the type. - */ - CompletableFuture getVolumeControlType(); - - /** - * Subscribes to changes in the volume. - * - * @param callback the function to call when the state changes. - */ - void subscribeVolumeControlType(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the volume. */ - void unsubscribeVolumeControlType(); -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithVolumeSelector.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithVolumeSelector.java deleted file mode 100644 index 0c2a2890f..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithVolumeSelector.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.impl.televisionspeaker.VolumeSelectorEnum; -import java.util.concurrent.CompletableFuture; - -/** - * Accessory with volume selector {@link - * io.github.hapjava.characteristics.impl.televisionspeaker.VolumeSelectorCharacteristic} - */ -public interface AccessoryWithVolumeSelector { - - /** - * Sets the volume selector - * - * @param value the volume selector - * @return a future that completes when the volume selector is changed - * @throws Exception when the volume selector cannot be set - */ - CompletableFuture setVolumeSelector(VolumeSelectorEnum value) throws Exception; -} diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithWaterLevel.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithWaterLevel.java deleted file mode 100644 index 591a1b5ac..000000000 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithWaterLevel.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.github.hapjava.accessories.optionalcharacteristic; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.concurrent.CompletableFuture; - -/** Accessory with water level. */ -public interface AccessoryWithWaterLevel { - - /** - * Retrieves the water level in percent. - * - * @return a future that will contain the water level, expressed as an double between 0 and 100. - */ - CompletableFuture getWaterLevel(); - - /** - * Subscribes to changes in the water level. - * - * @param callback the function to call when the state changes. - */ - void subscribeWaterLevel(HomekitCharacteristicChangeCallback callback); - - /** Unsubscribes from changes in the water level. */ - void unsubscribeWaterLevel(); -} diff --git a/src/main/java/io/github/hapjava/accessories/package-info.java b/src/main/java/io/github/hapjava/accessories/package-info.java deleted file mode 100644 index 0678de41f..000000000 --- a/src/main/java/io/github/hapjava/accessories/package-info.java +++ /dev/null @@ -1,2 +0,0 @@ -/** Contains interfaces that can be implemented to represent an exposed accessory. */ -package io.github.hapjava.accessories; diff --git a/src/main/java/io/github/hapjava/characteristics/Characteristic.java b/src/main/java/io/github/hapjava/characteristics/Characteristic.java deleted file mode 100644 index b2454e5f9..000000000 --- a/src/main/java/io/github/hapjava/characteristics/Characteristic.java +++ /dev/null @@ -1,57 +0,0 @@ -package io.github.hapjava.characteristics; - -import java.util.concurrent.CompletableFuture; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import javax.json.JsonValue; - -/** - * Interface for the characteristics provided by a Service. - * - *

Characteristics are the lowest level building block of the HomeKit Accessory Protocol. They - * define variables that can be retrieved or set by the remote client. Most consumers of this - * library will be better served by using one of the characteristic classes in {@link - * io.github.hapjava.characteristics} when creating custom accessory types (the standard accessories - * from {@link io.github.hapjava.accessories} already include the necessary characteristics), - * instead of trying to implement the JSON formats directly. - * - * @author Andy Lintner - */ -public interface Characteristic { - /** @return The UUID type for this characteristic. */ - String getType(); - - /** - * Adds an attribute to the passed JsonObjectBuilder named "value" with the current value of the - * characteristic. - * - * @param characteristicBuilder the JsonObjectBuilder to add the value attribute to. - */ - void supplyValue(JsonObjectBuilder characteristicBuilder); - - /** - * Creates the JSON representation of the characteristic, in accordance with the HomeKit Accessory - * Protocol. - * - * @param iid The instance ID of the characteristic to be included in the serialization. - * @return the future completing with the resulting JSON. - */ - CompletableFuture toJson(int iid); - - /** - * Invoked by the remote client, this updates the current value of the characteristic. - * - * @param jsonValue the JSON serialized value to set. - */ - void setValue(JsonValue jsonValue); - - /** - * Invoked by the remote client, this updates the current value of the characteristic. - * - * @param jsonValue the JSON serialized value to set. - * @param username the authenticated username making the request - */ - default void setValue(JsonValue jsonValue, String username) { - setValue(jsonValue); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/CharacteristicEnum.java b/src/main/java/io/github/hapjava/characteristics/CharacteristicEnum.java deleted file mode 100644 index bc8dbc9c2..000000000 --- a/src/main/java/io/github/hapjava/characteristics/CharacteristicEnum.java +++ /dev/null @@ -1,5 +0,0 @@ -package io.github.hapjava.characteristics; - -public interface CharacteristicEnum { - int getCode(); -} diff --git a/src/main/java/io/github/hapjava/characteristics/EventableCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/EventableCharacteristic.java deleted file mode 100644 index 1da8f228b..000000000 --- a/src/main/java/io/github/hapjava/characteristics/EventableCharacteristic.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.github.hapjava.characteristics; - -/** - * A characteristic that can be listened to by the connected iOS device. - * - * @author Andy Lintner - */ -public interface EventableCharacteristic extends Characteristic { - - /** - * Begin listening to changes to this characteristic. When a change is made, call the provided - * function. - * - * @param callback a function to call when a change is made to the characteristic value. - */ - void subscribe(HomekitCharacteristicChangeCallback callback); - - /** Stop listening to changes to this characteristic. */ - void unsubscribe(); -} diff --git a/src/main/java/io/github/hapjava/characteristics/ExceptionalConsumer.java b/src/main/java/io/github/hapjava/characteristics/ExceptionalConsumer.java deleted file mode 100644 index 1c625470d..000000000 --- a/src/main/java/io/github/hapjava/characteristics/ExceptionalConsumer.java +++ /dev/null @@ -1,9 +0,0 @@ -package io.github.hapjava.characteristics; - -public interface ExceptionalConsumer { - void accept(T t) throws Exception; - - default void accept(T t, String username) throws Exception { - accept(t); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/HomekitCharacteristicChangeCallback.java b/src/main/java/io/github/hapjava/characteristics/HomekitCharacteristicChangeCallback.java deleted file mode 100644 index e2d5bc5f2..000000000 --- a/src/main/java/io/github/hapjava/characteristics/HomekitCharacteristicChangeCallback.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.github.hapjava.characteristics; - -/** - * A callback interface for notifying subscribers that a characteristic value has changed. - * - *

{@link EventableCharacteristic}s can be subscribed to, and in doing so, are supplied an - * instance of this class. Implementors should call the {@link #changed()} method on the passed - * object when a subscribed characteristic changes. - * - * @author Andy Lintner - */ -@FunctionalInterface -public interface HomekitCharacteristicChangeCallback { - - /** - * Call when the value of the characteristic that was subscribed to when this object was passed - * changes. - */ - void changed(); -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/AccessoryFlagsCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/AccessoryFlagsCharacteristic.java deleted file mode 100644 index f04a4dd8e..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/AccessoryFlagsCharacteristic.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.hapjava.characteristics.impl.accessoryinformation; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic indicates whether accessory requires additional setup. See {@link - * AccessoryFlagsEnum} for possible values. - */ -public class AccessoryFlagsCharacteristic extends EnumCharacteristic { - - public AccessoryFlagsCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000A6-0000-1000-8000-0026BB765291", - "accessory flags", - AccessoryFlagsEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/AccessoryFlagsEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/AccessoryFlagsEnum.java deleted file mode 100644 index a849383e8..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/AccessoryFlagsEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.accessoryinformation; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0x0001 (bit0) ”Requires additional setup” 0x0002 - 0xFFFF ”Reserved” */ -public enum AccessoryFlagsEnum implements CharacteristicEnum { - NO_FLAGS(0), - REQUIRES_ADDITIONAL_SETUP(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(AccessoryFlagsEnum.values()) - .collect(Collectors.toMap(AccessoryFlagsEnum::getCode, t -> t)); - } - - public static AccessoryFlagsEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - AccessoryFlagsEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/FirmwareRevisionCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/FirmwareRevisionCharacteristic.java deleted file mode 100644 index 542cb805b..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/FirmwareRevisionCharacteristic.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.github.hapjava.characteristics.impl.accessoryinformation; - -import io.github.hapjava.characteristics.impl.base.StaticStringCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - -/** This characteristic describes a firmware revision string */ -public class FirmwareRevisionCharacteristic extends StaticStringCharacteristic { - - public FirmwareRevisionCharacteristic(Supplier> getter) { - super( - "00000052-0000-1000-8000-0026BB765291", - "firmware revision", - Optional.of(getter), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/HardwareRevisionCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/HardwareRevisionCharacteristic.java deleted file mode 100644 index f323de0d8..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/HardwareRevisionCharacteristic.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.github.hapjava.characteristics.impl.accessoryinformation; - -import io.github.hapjava.characteristics.impl.base.StaticStringCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - -/** This characteristic describes a hardware revision in a form x[.y[.z]] (e.g. ”100.1.1”) */ -public class HardwareRevisionCharacteristic extends StaticStringCharacteristic { - - public HardwareRevisionCharacteristic(Supplier> getter) { - super( - "00000053-0000-1000-8000-0026BB765291", - "hardware revision", - Optional.of(getter), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/IdentifyCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/IdentifyCharacteristic.java deleted file mode 100644 index 8936ba77d..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/IdentifyCharacteristic.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.github.hapjava.characteristics.impl.accessoryinformation; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.impl.base.BooleanCharacteristic; -import java.util.Optional; - -/** This characteristic enables accessory to run its identify routine. */ -public class IdentifyCharacteristic extends BooleanCharacteristic { - - public IdentifyCharacteristic(ExceptionalConsumer setter) { - super( - "00000014-0000-1000-8000-0026BB765291", - "identifies the accessory", - Optional.empty(), - Optional.of(setter), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/ManufacturerCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/ManufacturerCharacteristic.java deleted file mode 100644 index 777b571c2..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/ManufacturerCharacteristic.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.github.hapjava.characteristics.impl.accessoryinformation; - -import io.github.hapjava.characteristics.impl.base.StaticStringCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - -/** This characteristic contains the name of the company whose brand will appear on the accessory */ -public class ManufacturerCharacteristic extends StaticStringCharacteristic { - - public ManufacturerCharacteristic(Supplier> getter) { - super( - "00000020-0000-1000-8000-0026BB765291", - "manufacturer", - Optional.of(getter), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/ModelCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/ModelCharacteristic.java deleted file mode 100644 index 4df7975af..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/ModelCharacteristic.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.github.hapjava.characteristics.impl.accessoryinformation; - -import io.github.hapjava.characteristics.impl.base.StaticStringCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - -/** This characteristic contains the manufacturer-specific model of the accessory */ -public class ModelCharacteristic extends StaticStringCharacteristic { - - public ModelCharacteristic(Supplier> getter) { - super( - "00000021-0000-1000-8000-0026BB765291", - "model", - Optional.of(getter), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/SerialNumberCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/SerialNumberCharacteristic.java deleted file mode 100644 index 0c9860d73..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/accessoryinformation/SerialNumberCharacteristic.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.github.hapjava.characteristics.impl.accessoryinformation; - -import io.github.hapjava.characteristics.impl.base.StaticStringCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - -/** This characteristic contains the manufacturer-specific serial number of the accessory. */ -public class SerialNumberCharacteristic extends StaticStringCharacteristic { - - public SerialNumberCharacteristic(Supplier> getter) { - super( - "00000030-0000-1000-8000-0026BB765291", - "serial number", - Optional.of(getter), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/airpurifier/CurrentAirPurifierCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/airpurifier/CurrentAirPurifierCharacteristic.java deleted file mode 100644 index c5b506c40..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/airpurifier/CurrentAirPurifierCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.airpurifier; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes the current state of the air purifier. See {@link - * CurrentAirPurifierStateEnum} for possible values. - */ -public class CurrentAirPurifierCharacteristic - extends EnumCharacteristic { - - public CurrentAirPurifierCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000A9-0000-1000-8000-0026BB765291", - "current air purifier state", - CurrentAirPurifierStateEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/airpurifier/CurrentAirPurifierStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/airpurifier/CurrentAirPurifierStateEnum.java deleted file mode 100644 index ce4d8cc0d..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/airpurifier/CurrentAirPurifierStateEnum.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.hapjava.characteristics.impl.airpurifier; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Inactive” 1 ”Idle” 2 ”Purifying Air” */ -public enum CurrentAirPurifierStateEnum implements CharacteristicEnum { - INACTIVE(0), - IDLE(1), - PURIFYING_AIR(2); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(CurrentAirPurifierStateEnum.values()) - .collect(Collectors.toMap(CurrentAirPurifierStateEnum::getCode, t -> t)); - } - - public static CurrentAirPurifierStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - CurrentAirPurifierStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/airpurifier/TargetAirPurifierStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/airpurifier/TargetAirPurifierStateCharacteristic.java deleted file mode 100644 index e8452d655..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/airpurifier/TargetAirPurifierStateCharacteristic.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.github.hapjava.characteristics.impl.airpurifier; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes the target state of the air purifier. See {@link - * TargetAirPurifierStateEnum} for possible values. - */ -public class TargetAirPurifierStateCharacteristic - extends EnumCharacteristic { - - public TargetAirPurifierStateCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000A8-0000-1000-8000-0026BB765291", - "Air purifier state", - TargetAirPurifierStateEnum.values(), - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/airpurifier/TargetAirPurifierStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/airpurifier/TargetAirPurifierStateEnum.java deleted file mode 100644 index a20a73e9f..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/airpurifier/TargetAirPurifierStateEnum.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.github.hapjava.characteristics.impl.airpurifier; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Manual” 1 ”Auto” */ -public enum TargetAirPurifierStateEnum implements CharacteristicEnum { - MANUAL(0), - AUTO(1); - private static final Map reverse; - - static { - reverse = - Arrays.stream(TargetAirPurifierStateEnum.values()) - .collect(Collectors.toMap(t -> t.getCode(), t -> t)); - } - - public static TargetAirPurifierStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - private TargetAirPurifierStateEnum(int code) { - this.code = code; - } - - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/airquality/AirQualityCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/airquality/AirQualityCharacteristic.java deleted file mode 100644 index 448b90383..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/airquality/AirQualityCharacteristic.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.hapjava.characteristics.impl.airquality; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes the air quality. See {@link AirQualityEnum} for possible values. - */ -public class AirQualityCharacteristic extends EnumCharacteristic { - - public AirQualityCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000095-0000-1000-8000-0026BB765291", - "air quality", - AirQualityEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/airquality/AirQualityEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/airquality/AirQualityEnum.java deleted file mode 100644 index 390b51dfe..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/airquality/AirQualityEnum.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.github.hapjava.characteristics.impl.airquality; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Unknown” 1 ”Excellent” 2 ”Good” 3 ”Fair” 4 ”Inferior” 5 ”Poor” */ -public enum AirQualityEnum implements CharacteristicEnum { - UNKNOWN(0), - EXCELLENT(1), - GOOD(2), - FAIR(3), - INFERIOR(4), - POOR(5); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(AirQualityEnum.values()) - .collect(Collectors.toMap(AirQualityEnum::getCode, t -> t)); - } - - public static AirQualityEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - AirQualityEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/airquality/NitrogenDioxideDensityCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/airquality/NitrogenDioxideDensityCharacteristic.java deleted file mode 100644 index 1e37e28b6..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/airquality/NitrogenDioxideDensityCharacteristic.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.hapjava.characteristics.impl.airquality; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic contains the current NO2 density in micrograms/m3. */ -public class NitrogenDioxideDensityCharacteristic extends FloatCharacteristic { - public static final double DEFAULT_MIN_VALUE = 0; - public static final double DEFAULT_MAX_VALUE = 1000; - public static final double DEFAULT_STEP = 1; - - public NitrogenDioxideDensityCharacteristic( - double minValue, - double maxValue, - double minStep, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000C4-0000-1000-8000-0026BB765291", - "nitrogen dioxide density", - minValue, - maxValue, - minStep, - "micrograms", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public NitrogenDioxideDensityCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, DEFAULT_STEP, getter, subscriber, unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/airquality/OzoneDensityCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/airquality/OzoneDensityCharacteristic.java deleted file mode 100644 index 577339288..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/airquality/OzoneDensityCharacteristic.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.hapjava.characteristics.impl.airquality; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic contains the current ozone density in micrograms/m3. */ -public class OzoneDensityCharacteristic extends FloatCharacteristic { - public static final double DEFAULT_MIN_VALUE = 0; - public static final double DEFAULT_MAX_VALUE = 1000; - public static final double DEFAULT_STEP = 1; - - public OzoneDensityCharacteristic( - double minValue, - double maxValue, - double minStep, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000C3-0000-1000-8000-0026BB765291", - "ozone density", - minValue, - maxValue, - minStep, - "micrograms", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public OzoneDensityCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, DEFAULT_STEP, getter, subscriber, unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/airquality/PM10DensityCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/airquality/PM10DensityCharacteristic.java deleted file mode 100644 index a7b9c1245..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/airquality/PM10DensityCharacteristic.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.github.hapjava.characteristics.impl.airquality; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic contains the current PM10 micrometer particulate density in micrograms/m3. - */ -public class PM10DensityCharacteristic extends FloatCharacteristic { - public static final double DEFAULT_MIN_VALUE = 0; - public static final double DEFAULT_MAX_VALUE = 1000; - public static final double DEFAULT_STEP = 1; - - public PM10DensityCharacteristic( - double minValue, - double maxValue, - double minStep, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000C7-0000-1000-8000-0026BB765291", - "PM10 density", - minValue, - maxValue, - minStep, - "micrograms", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public PM10DensityCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, DEFAULT_STEP, getter, subscriber, unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/airquality/PM25DensityCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/airquality/PM25DensityCharacteristic.java deleted file mode 100644 index 1667934ef..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/airquality/PM25DensityCharacteristic.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.github.hapjava.characteristics.impl.airquality; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic contains the current PM2.5 micrometer particulate density in micrograms/m3. - */ -public class PM25DensityCharacteristic extends FloatCharacteristic { - public static final double DEFAULT_MIN_VALUE = 0; - public static final double DEFAULT_MAX_VALUE = 1000; - public static final double DEFAULT_STEP = 1; - - public PM25DensityCharacteristic( - double minValue, - double maxValue, - double minStep, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000C6-0000-1000-8000-0026BB765291", - "PM2.5 density", - minValue, - maxValue, - minStep, - "micrograms", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public PM25DensityCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, DEFAULT_STEP, getter, subscriber, unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/airquality/SulphurDioxideDensityCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/airquality/SulphurDioxideDensityCharacteristic.java deleted file mode 100644 index 81df2c64b..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/airquality/SulphurDioxideDensityCharacteristic.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.hapjava.characteristics.impl.airquality; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic contains the current SO2 density in micrograms/m3. */ -public class SulphurDioxideDensityCharacteristic extends FloatCharacteristic { - public static final double DEFAULT_MIN_VALUE = 0; - public static final double DEFAULT_MAX_VALUE = 1000; - public static final double DEFAULT_STEP = 1; - - public SulphurDioxideDensityCharacteristic( - double minValue, - double maxValue, - double minStep, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000C5-0000-1000-8000-0026BB765291", - "sulphur dioxide density", - minValue, - maxValue, - minStep, - "micrograms", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public SulphurDioxideDensityCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, DEFAULT_STEP, getter, subscriber, unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/airquality/VOCDensityCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/airquality/VOCDensityCharacteristic.java deleted file mode 100644 index a752161c9..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/airquality/VOCDensityCharacteristic.java +++ /dev/null @@ -1,45 +0,0 @@ -package io.github.hapjava.characteristics.impl.airquality; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic indicates the current volatile organic compound (VOC) density in - * micrograms/m3. - */ -public class VOCDensityCharacteristic extends FloatCharacteristic { - public static final double DEFAULT_MIN_VALUE = 0; - public static final double DEFAULT_MAX_VALUE = 1000; - public static final double DEFAULT_STEP = 1; - - public VOCDensityCharacteristic( - double minValue, - double maxValue, - double minStep, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000C8-0000-1000-8000-0026BB765291", - "VOC density", - minValue, - maxValue, - minStep, - "micrograms", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public VOCDensityCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, DEFAULT_STEP, getter, subscriber, unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/audio/MuteCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/audio/MuteCharacteristic.java deleted file mode 100644 index 105ca0977..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/audio/MuteCharacteristic.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.characteristics.impl.audio; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.BooleanCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** Mute characteristic to control audio input or output accessory. */ -public class MuteCharacteristic extends BooleanCharacteristic { - public MuteCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000011A-0000-1000-8000-0026BB765291", - "Mute", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/audio/VolumeCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/audio/VolumeCharacteristic.java deleted file mode 100644 index 2d1caedd7..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/audio/VolumeCharacteristic.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.hapjava.characteristics.impl.audio; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** Volume characteristic to control audio volume. */ -public class VolumeCharacteristic extends IntegerCharacteristic implements EventableCharacteristic { - - public VolumeCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000119-0000-1000-8000-0026BB765291", - "volume", - 0, - 100, - "percentage", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/base/BaseCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/base/BaseCharacteristic.java deleted file mode 100644 index 0808883bb..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/base/BaseCharacteristic.java +++ /dev/null @@ -1,247 +0,0 @@ -package io.github.hapjava.characteristics.impl.base; - -import io.github.hapjava.characteristics.Characteristic; -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; -import java.util.function.Consumer; -import javax.json.Json; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import javax.json.JsonValue; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Base class for implementing {@link Characteristic}. - * - * @author Andy Lintner - */ -public abstract class BaseCharacteristic implements Characteristic, EventableCharacteristic { - - private final Logger logger = LoggerFactory.getLogger(BaseCharacteristic.class); - - private final String type; - private final String shortType; - private final String format; - private final String description; - private final boolean isReadable; - private final boolean isWritable; - private final Optional> subscriber; - private final Optional unsubscriber; - - /** - * Default constructor - * - * @param type a string containing a UUID that indicates the type of characteristic. Apple defines - * a set of these, however implementors can create their own as well. - * @param format a string indicating the value type, which must be a recognized type by the - * consuming device. - * @param isWritable indicates whether the value can be changed. - * @param isReadable indicates whether the value can be retrieved. - * @param description a description of the characteristic to be passed to the consuming device. - * @param subscriber subscribes to changes - * @param unsubscriber unsubscribes to changes - */ - public BaseCharacteristic( - String type, - String format, - String description, - boolean isReadable, - boolean isWritable, - Optional> subscriber, - Optional unsubscriber) { - if (type == null || format == null || description == null) { - throw new NullPointerException(); - } - - this.type = type; - this.shortType = this.type.replaceAll("^0*([0-9a-fA-F]+)-0000-1000-8000-0026BB765291$", "$1"); - this.format = format; - this.description = description; - this.isReadable = isReadable; - this.isWritable = isWritable; - this.subscriber = subscriber; - this.unsubscriber = unsubscriber; - } - - @Override - /** {@inheritDoc} */ - public String getType() { - return type; - } - - @Override - /** {@inheritDoc} */ - public final CompletableFuture toJson(int iid) { - return makeBuilder(iid).thenApply(builder -> builder.build()); - } - - /** - * Creates the JSON serialized form of the accessory for use over the HomeKit Accessory Protocol. - * - * @param instanceId the static id of the accessory. - * @return a future that will complete with the JSON builder for the object. - */ - protected CompletableFuture makeBuilder(int instanceId) { - CompletableFuture futureValue = getValue(); - - if (futureValue == null) { - futureValue = CompletableFuture.completedFuture(getDefault()); - } - - return futureValue - .exceptionally( - t -> { - logger.warn("Could not retrieve value " + this.getClass().getName(), t); - return null; - }) - .thenApply( - value -> { - JsonArrayBuilder perms = Json.createArrayBuilder(); - if (isReadable) { - perms.add("pr"); - } - if (isWritable) { - perms.add("pw"); - } - if (subscriber.isPresent()) { - perms.add("ev"); - } - JsonObjectBuilder builder = - Json.createObjectBuilder() - .add("iid", instanceId) - .add("type", shortType) - .add("perms", perms.build()) - .add("format", format); - if (shortType.length() == type.length()) builder.add("description", description); - if (isReadable) setJsonValue(builder, value); - return builder; - }); - } - - /** {@inheritDoc} */ - @Override - public final void setValue(JsonValue jsonValue) { - setValue(jsonValue, null); - } - - /** {@inheritDoc} */ - @Override - public final void setValue(JsonValue jsonValue, String username) { - try { - setValue(convert(jsonValue), username); - } catch (Exception e) { - logger.warn( - "Error while setting JSON value {} for characteristic {} from user {}", - jsonValue, - getClass().getName(), - username, - e); - } - } - - /** {@inheritDoc} */ - @Override - public void supplyValue(JsonObjectBuilder builder) { - CompletableFuture futureValue = getValue(); - - if (futureValue == null) { - setJsonValue(builder, getDefault()); - return; - } - - try { - setJsonValue(builder, futureValue.get()); - } catch (InterruptedException | ExecutionException e) { - logger.warn("Error retrieving value", e); - setJsonValue(builder, getDefault()); - } - } - - /** {@inheritDoc} */ - @Override - public void subscribe(HomekitCharacteristicChangeCallback callback) { - subscriber.ifPresent(s -> s.accept(callback)); - } - - /** {@inheritDoc} */ - @Override - public void unsubscribe() { - unsubscriber.ifPresent(u -> u.run()); - } - - /** - * Converts from the JSON value to a Java object of the type T - * - * @param jsonValue the JSON value to convert from. - * @return the converted Java object. - */ - protected abstract T convert(JsonValue jsonValue); - - /** - * Update the characteristic value using a new value supplied by the connected client. - * - * @param value the new value to set. - * @throws Exception if the value cannot be set. - */ - public abstract void setValue(T value) throws Exception; - - /** - * Update the characteristic value using a new value supplied by the connected client. - * - * @param value the new value to set. - * @param username the authenticated username making the request - * @throws Exception if the value cannot be set. - */ - public void setValue(T value, String username) throws Exception { - setValue(value); - } - - /** - * Retrieves the current value of the characteristic. - * - * @return a future that will complete with the current value. - */ - public abstract CompletableFuture getValue(); - - /** - * Supplies a default value for the characteristic to send to connected clients when the real - * value. cannot be retrieved. - * - * @return a sensible default value. - */ - public abstract T getDefault(); - - /** - * Writes the value key to the serialized characteristic - * - * @param builder The JSON builder to add the value to - * @param value The value to add - */ - protected void setJsonValue(JsonObjectBuilder builder, T value) { - // I don't like this - there should really be a way to construct a disconnected JSONValue... - if (value instanceof Boolean) { - builder.add("value", (Boolean) value); - } else if (value instanceof Double) { - builder.add("value", (Double) value); - } else if (value instanceof Integer) { - builder.add("value", (Integer) value); - } else if (value instanceof Long) { - builder.add("value", (Long) value); - } else if (value instanceof BigInteger) { - builder.add("value", (BigInteger) value); - } else if (value instanceof BigDecimal) { - builder.add("value", (BigDecimal) value); - } else if (value == null) { - builder.addNull("value"); - } else { - builder.add("value", value.toString()); - } - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/base/BooleanCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/base/BooleanCharacteristic.java deleted file mode 100644 index b8c93a4e9..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/base/BooleanCharacteristic.java +++ /dev/null @@ -1,82 +0,0 @@ -package io.github.hapjava.characteristics.impl.base; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; -import javax.json.JsonNumber; -import javax.json.JsonValue; -import javax.json.JsonValue.ValueType; - -/** - * Characteristic that exposes a Boolean value. - * - * @author Andy Lintner - */ -public abstract class BooleanCharacteristic extends BaseCharacteristic { - - private final Optional>> getter; - private final Optional> setter; - - /** - * Default constructor - * - * @param type a string containing a UUID that indicates the type of characteristic. Apple defines - * a set of these, however implementors can create their own as well. - * @param description a description of the characteristic to be passed to the consuming device. - * @param getter getter to retrieve the value - * @param setter setter to set value - * @param subscriber subscriber to subscribe to changes - * @param unsubscriber unsubscriber to unsubscribe from chnages - */ - public BooleanCharacteristic( - String type, - String description, - Optional>> getter, - Optional> setter, - Optional> subscriber, - Optional unsubscriber) { - super( - type, - "bool", - description, - getter.isPresent(), - setter.isPresent(), - subscriber, - unsubscriber); - this.getter = getter; - this.setter = setter; - } - - /** {@inheritDoc} */ - @Override - protected Boolean convert(JsonValue jsonValue) { - if (jsonValue.getValueType().equals(ValueType.NUMBER)) { - return ((JsonNumber) jsonValue).intValue() > 0; - } - return jsonValue.equals(JsonValue.TRUE); - } - - @Override - public CompletableFuture getValue() { - return getter.isPresent() ? getter.map(booleanGetter -> booleanGetter.get()).get() : null; - } - - @Override - public void setValue(Boolean value) throws Exception { - setValue(value, null); - } - - @Override - public void setValue(Boolean value, String username) throws Exception { - if (setter.isPresent()) setter.get().accept(value, username); - } - - /** {@inheritDoc} */ - @Override - public Boolean getDefault() { - return false; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/base/EnumCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/base/EnumCharacteristic.java deleted file mode 100644 index a12cb0673..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/base/EnumCharacteristic.java +++ /dev/null @@ -1,162 +0,0 @@ -package io.github.hapjava.characteristics.impl.base; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.Arrays; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; -import javax.json.Json; -import javax.json.JsonArrayBuilder; -import javax.json.JsonNumber; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import javax.json.JsonValue; - -/** - * Characteristic that exposes an Enum value. Enums are represented as an Integer value in the - * HomeKit protocol, and classes extending this one must handle the static mapping to an Integer - * value. - * - * @author Andy Lintner - */ -public abstract class EnumCharacteristic - extends BaseCharacteristic { - - private final T[] validValues; - protected Optional>> getter; - protected Optional> setter; - - /** - * Default constructor - * - * @param type a string containing a UUID that indicates the type of characteristic. Apple defines - * a set of these, however implementors can create their own as well. - * @param description a description of the characteristic to be passed to the consuming device. - * @param validValues an array of valid values for enum. - * @param getter getter to retrieve the value - * @param setter setter to set value - * @param subscriber subscriber to subscribe to changes - * @param unsubscriber unsubscriber to unsubscribe from chnages - */ - public EnumCharacteristic( - String type, - String description, - T[] validValues, - Optional>> getter, - Optional> setter, - Optional> subscriber, - Optional unsubscriber) { - super( - type, "int", description, getter.isPresent(), setter.isPresent(), subscriber, unsubscriber); - this.getter = getter; - this.setter = setter; - this.validValues = validValues; - } - - /** {@inheritDoc} */ - @Override - protected CompletableFuture makeBuilder(int iid) { - JsonArrayBuilder validValuesBuilder = Json.createArrayBuilder(); - if (validValues != null && validValues.length != 0) { - Arrays.stream(validValues).forEach((T value) -> validValuesBuilder.add(value.getCode())); - } - return super.makeBuilder(iid) - .thenApply( - builder -> { - return builder.add("valid-values", validValuesBuilder); - }); - } - - /** {@inheritDoc} */ - @Override - protected Integer convert(JsonValue jsonValue) { - if (jsonValue instanceof JsonNumber) { - return ((JsonNumber) jsonValue).intValue(); - } else if (jsonValue == JsonObject.TRUE) { - return 1; // For at least one enum type (locks), homekit will send a true instead of 1 - } else if (jsonValue == JsonObject.FALSE) { - return 0; - } else { - throw new IndexOutOfBoundsException("Cannot convert " + jsonValue.getClass() + " to int"); - } - } - - /** - * @return the current value of this characteristic, or null if it has no value or can't be - * fetched - */ - public CompletableFuture getEnumValue() { - if (!getter.isPresent()) { - return null; - } - return getter.get().get(); - } - - @Override - public CompletableFuture getValue() { - if (!getter.isPresent()) { - return null; - } - return getter - .get() - .get() - .thenApply( - e -> { - if (e == null) { - return null; - } - return e.getCode(); - }); - } - - public void setValue(T value) throws Exception { - setValue(value, null); - } - - public void setValue(T value, String username) throws Exception { - if (!setter.isPresent()) { - return; - } - - setter.get().accept(value, username); - } - - @Override - public void setValue(Integer value) throws Exception { - setValue(value, null); - } - - @Override - public void setValue(Integer value, String username) throws Exception { - if (!setter.isPresent()) { - return; - } - - // check if value is in valid values - if (validValues != null && value != null) { - for (T valid : validValues) { - if (valid.getCode() == value) { - setValue(valid, username); - return; - } - } - } - } - - /** {@inheritDoc} */ - @Override - public Integer getDefault() { - // as default return first item from valid values - if (validValues != null && validValues.length > 0) { - return validValues[0].getCode(); - } - return 0; - } - - public T[] getValidValues() { - return validValues; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/base/FloatCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/base/FloatCharacteristic.java deleted file mode 100644 index f4b5fa562..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/base/FloatCharacteristic.java +++ /dev/null @@ -1,158 +0,0 @@ -package io.github.hapjava.characteristics.impl.base; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; -import javax.json.JsonNumber; -import javax.json.JsonObjectBuilder; -import javax.json.JsonValue; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * A characteristic that provides a Float value type. - * - * @author Andy Lintner - */ -public abstract class FloatCharacteristic extends BaseCharacteristic { - - private static final Logger LOGGER = LoggerFactory.getLogger(FloatCharacteristic.class); - - private final double minValue; - private final double maxValue; - private final double minStep; - private final String unit; - private final Optional>> getter; - private final Optional> setter; - - /** - * Default constructor - * - * @param type a string containing a UUID that indicates the type of characteristic. Apple defines - * a set of these, however implementors can create their own as well. - * @param description a description of the characteristic to be passed to the consuming device. - * @param minValue the minimum supported value. - * @param maxValue the maximum supported value - * @param minStep the smallest supported step. Values will be rounded to a multiple of this. - * @param unit a description of the unit this characteristic supports. - * @param getter getter to retrieve the value - * @param setter setter to set value - * @param subscriber subscriber to subscribe to changes - * @param unsubscriber unsubscriber to unsubscribe from chnages - */ - public FloatCharacteristic( - String type, - String description, - double minValue, - double maxValue, - double minStep, - String unit, - Optional>> getter, - Optional> setter, - Optional> subscriber, - Optional unsubscriber) { - super( - type, - "float", - description, - getter.isPresent(), - setter.isPresent(), - subscriber, - unsubscriber); - this.minValue = minValue; - this.maxValue = maxValue; - this.unit = unit; - this.getter = getter; - this.setter = setter; - this.minStep = minStep; - } - - /** {@inheritDoc} */ - @Override - protected CompletableFuture makeBuilder(int iid) { - return super.makeBuilder(iid) - .thenApply( - builder -> - builder - .add("minValue", minValue) - .add("maxValue", maxValue) - .add("minStep", minStep) - .add("unit", unit)); - } - - /** {@inheritDoc} */ - @Override - protected Double convert(JsonValue jsonValue) { - return ((JsonNumber) jsonValue).doubleValue(); - } - - /** - * {@inheritDoc}. Calls the getDoubleValue method and applies rounding to the minStep supplied in - * the constructor. - */ - @Override - public final CompletableFuture getValue() { - if (!getter.isPresent()) { - return null; - } - double rounder = 1 / this.minStep; - return getter - .get() - .get() - .thenApply(d -> d == null ? null : Math.round(d * rounder) / rounder) - .thenApply( - d -> { - if (d != null) { - if (d < minValue) { - LOGGER.warn( - "Detected value out of range " - + d - + ". Returning min value instead. Characteristic " - + this); - return minValue; - } - if (d > maxValue) { - LOGGER.warn( - "Detected value out of range " - + d - + ". Returning max value instead. Characteristic " - + this); - return maxValue; - } - return d; - } - return null; - }); - } - - @Override - public void setValue(Double value) throws Exception { - setValue(value, null); - } - - @Override - public void setValue(Double value, String username) throws Exception { - if (setter.isPresent()) setter.get().accept(value, username); - } - - /** {@inheritDoc} */ - @Override - public Double getDefault() { - return minValue; - } - - public double getMinValue() { - return minValue; - } - - public double getMaxValue() { - return maxValue; - } - - public double getMinStep() { - return minStep; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/base/IntegerCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/base/IntegerCharacteristic.java deleted file mode 100644 index 96448eea8..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/base/IntegerCharacteristic.java +++ /dev/null @@ -1,99 +0,0 @@ -package io.github.hapjava.characteristics.impl.base; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; -import javax.json.JsonNumber; -import javax.json.JsonObjectBuilder; -import javax.json.JsonValue; - -/** - * A characteristic that provides an Integer data type. - * - * @author Andy Lintner - */ -public abstract class IntegerCharacteristic extends BaseCharacteristic { - - private final int minValue; - private final int maxValue; - private final String unit; - private final Optional>> getter; - private final Optional> setter; - - /** - * Default constructor - * - * @param type a string containing a UUID that indicates the type of characteristic. Apple defines - * a set of these, however implementors can create their own as well. - * @param description a description of the characteristic to be passed to the consuming device. - * @param minValue the minimum supported value. - * @param maxValue the maximum supported value - * @param unit a description of the unit this characteristic supports. - * @param getter getter for value - * @param setter setter for value - * @param subscriber subscribers to changes - * @param unsubscriber unsubscribers to changes - */ - public IntegerCharacteristic( - String type, - String description, - int minValue, - int maxValue, - String unit, - Optional>> getter, - Optional> setter, - Optional> subscriber, - Optional unsubscriber) { - super( - type, "int", description, getter.isPresent(), setter.isPresent(), subscriber, unsubscriber); - this.minValue = minValue; - this.maxValue = maxValue; - this.unit = unit; - this.getter = getter; - this.setter = setter; - } - - /** {@inheritDoc} */ - @Override - protected CompletableFuture makeBuilder(int iid) { - return super.makeBuilder(iid) - .thenApply( - builder -> { - builder.add("minValue", minValue).add("maxValue", maxValue).add("minStep", 1); - if (this.unit != null) { - builder.add("unit", unit); - } - return builder; - }); - } - - @Override - public CompletableFuture getValue() { - return getter.map(integerGetter -> integerGetter.get()).orElse(null); - } - - @Override - public void setValue(Integer value) throws Exception { - setValue(value, null); - } - - @Override - public void setValue(Integer value, String username) throws Exception { - if (setter.isPresent()) setter.get().accept(value, username); - } - - /** {@inheritDoc} */ - @Override - public Integer getDefault() { - return minValue; - } - - /** {@inheritDoc} */ - @Override - protected Integer convert(JsonValue jsonValue) { - return ((JsonNumber) jsonValue).intValue(); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/base/StaticStringCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/base/StaticStringCharacteristic.java deleted file mode 100644 index fc5961d4d..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/base/StaticStringCharacteristic.java +++ /dev/null @@ -1,71 +0,0 @@ -package io.github.hapjava.characteristics.impl.base; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; -import javax.json.JsonObjectBuilder; -import javax.json.JsonString; -import javax.json.JsonValue; - -/** - * A characteristic that provides an immutable String value. - * - * @author Andy Lintner - */ -public class StaticStringCharacteristic extends BaseCharacteristic { - - private static final int MAX_LEN = 255; - - private final Optional>> getter; - /** - * Default constructor - * - * @param type a string containing a UUID that indicates the type of characteristic. Apple defines - * a set of these, however implementors can create their own as well. - * @param description a description of the characteristic to be passed to the consuming device. - * @param getter getter to retrieve the value - * @param subscriber subscriber to subscribe to changes - * @param unsubscriber unsubscriber to unsubscribe from chnages - */ - public StaticStringCharacteristic( - String type, - String description, - Optional>> getter, - Optional> subscriber, - Optional unsubscriber) { - super(type, "string", description, getter.isPresent(), false, subscriber, unsubscriber); - this.getter = getter; - } - - /** {@inheritDoc} */ - @Override - protected CompletableFuture makeBuilder(int iid) { - return super.makeBuilder(iid).thenApply(builder -> builder.add("maxLen", MAX_LEN)); - } - - /** {@inheritDoc} */ - @Override - public String convert(JsonValue jsonValue) { - return ((JsonString) jsonValue).getString(); - } - - /** {@inheritDoc} */ - @Override - public void setValue(String value) throws Exception { - throw new Exception("Cannot modify static strings"); - } - - /** {@inheritDoc} */ - @Override - public CompletableFuture getValue() { - return getter.map(stringGetter -> stringGetter.get()).orElse(null); - } - - /** {@inheritDoc} */ - @Override - public String getDefault() { - return "Unknown"; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/base/StringCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/base/StringCharacteristic.java deleted file mode 100644 index 72ff0afd6..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/base/StringCharacteristic.java +++ /dev/null @@ -1,86 +0,0 @@ -package io.github.hapjava.characteristics.impl.base; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; -import javax.json.JsonObjectBuilder; -import javax.json.JsonString; -import javax.json.JsonValue; - -/** - * A characteristic that provides an string value. - * - * @author Eugen Freiter - */ -public class StringCharacteristic extends BaseCharacteristic { - private final Optional>> getter; - private final Optional> setter; - /** - * Default constructor - * - * @param type a string containing a UUID that indicates the type of characteristic. Apple defines - * a set of these, however implementors can create their own as well. - * @param description a description of the characteristic to be passed to the consuming device. - * @param getter getter to retrieve the value - * @param setter setter for value - * @param subscriber subscriber to subscribe to changes - * @param unsubscriber unsubscriber to unsubscribe from chnages - */ - public StringCharacteristic( - String type, - String description, - Optional>> getter, - Optional> setter, - Optional> subscriber, - Optional unsubscriber) { - super( - type, - "string", - description, - getter.isPresent(), - setter.isPresent(), - subscriber, - unsubscriber); - this.getter = getter; - this.setter = setter; - } - - /** {@inheritDoc} */ - @Override - protected CompletableFuture makeBuilder(int iid) { - return super.makeBuilder(iid); - } - - /** {@inheritDoc} */ - @Override - public String convert(JsonValue jsonValue) { - return ((JsonString) jsonValue).getString(); - } - - /** {@inheritDoc} */ - @Override - public void setValue(String value) throws Exception { - setValue(value, null); - } - - /** {@inheritDoc} */ - @Override - public void setValue(String value, String username) throws Exception { - if (setter.isPresent()) setter.get().accept(value, username); - } - - /** {@inheritDoc} */ - @Override - public CompletableFuture getValue() { - return getter.map(stringGetter -> stringGetter.get()).orElse(null); - } - - /** {@inheritDoc} */ - @Override - public String getDefault() { - return "Unknown"; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/battery/BatteryLevelCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/battery/BatteryLevelCharacteristic.java deleted file mode 100644 index 0fa56ff40..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/battery/BatteryLevelCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.battery; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the current level of the battery. */ -public class BatteryLevelCharacteristic extends IntegerCharacteristic - implements EventableCharacteristic { - - public BatteryLevelCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000068-0000-1000-8000-0026BB765291", - "battery level", - 0, - 100, - "%", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/battery/ChargingStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/battery/ChargingStateCharacteristic.java deleted file mode 100644 index f034e2c3c..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/battery/ChargingStateCharacteristic.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.hapjava.characteristics.impl.battery; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes the charging state of a battery or an accessory. See {@link - * ChargingStateEnum} for possible values. - */ -public class ChargingStateCharacteristic extends EnumCharacteristic { - - public ChargingStateCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000008F-0000-1000-8000-0026BB765291", - "Charging state", - ChargingStateEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/battery/ChargingStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/battery/ChargingStateEnum.java deleted file mode 100644 index d790ff2f7..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/battery/ChargingStateEnum.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.hapjava.characteristics.impl.battery; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Not Charging” 1 ”Charging” 2 ”Not Chargeable” */ -public enum ChargingStateEnum implements CharacteristicEnum { - NOT_CHARGING(0), - CHARGING(1), - NOT_CHARABLE(2); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(ChargingStateEnum.values()) - .collect(Collectors.toMap(ChargingStateEnum::getCode, t -> t)); - } - - public static ChargingStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - ChargingStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/battery/StatusLowBatteryCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/battery/StatusLowBatteryCharacteristic.java deleted file mode 100644 index fac7f3ead..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/battery/StatusLowBatteryCharacteristic.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.hapjava.characteristics.impl.battery; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes an accessory battery status. See {@link StatusLowBatteryEnum} for - * possible values - */ -public class StatusLowBatteryCharacteristic extends EnumCharacteristic { - - public StatusLowBatteryCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000079-0000-1000-8000-0026BB765291", - "Status Low Battery", - StatusLowBatteryEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/battery/StatusLowBatteryEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/battery/StatusLowBatteryEnum.java deleted file mode 100644 index 92981247d..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/battery/StatusLowBatteryEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.battery; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Battery level is normal” 1 ”Battery level is low” */ -public enum StatusLowBatteryEnum implements CharacteristicEnum { - NORMAL(0), - LOW(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(StatusLowBatteryEnum.values()) - .collect(Collectors.toMap(StatusLowBatteryEnum::getCode, t -> t)); - } - - public static StatusLowBatteryEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - StatusLowBatteryEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/carbondioxidesensor/CarbonDioxideDetectedCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/carbondioxidesensor/CarbonDioxideDetectedCharacteristic.java deleted file mode 100644 index ab327a40e..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/carbondioxidesensor/CarbonDioxideDetectedCharacteristic.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.hapjava.characteristics.impl.carbondioxidesensor; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic indicates the levels of Carbon Dioxide. See {@link CarbonDioxideDetectedEnum} - * for possible values. - */ -public class CarbonDioxideDetectedCharacteristic - extends EnumCharacteristic implements EventableCharacteristic { - - public CarbonDioxideDetectedCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000092-0000-1000-8000-0026BB765291", - "Carbon Dioxide Detected", - CarbonDioxideDetectedEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/carbondioxidesensor/CarbonDioxideDetectedEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/carbondioxidesensor/CarbonDioxideDetectedEnum.java deleted file mode 100644 index a6fe144b0..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/carbondioxidesensor/CarbonDioxideDetectedEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.carbondioxidesensor; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Carbon Dioxide levels are normal” 1 ”Carbon Dioxide levels are abnormal” */ -public enum CarbonDioxideDetectedEnum implements CharacteristicEnum { - NORMAL(0), - ABNORMAL(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(CarbonDioxideDetectedEnum.values()) - .collect(Collectors.toMap(CarbonDioxideDetectedEnum::getCode, t -> t)); - } - - public static CarbonDioxideDetectedEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - CarbonDioxideDetectedEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/carbondioxidesensor/CarbonDioxideLevelCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/carbondioxidesensor/CarbonDioxideLevelCharacteristic.java deleted file mode 100644 index b9b320564..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/carbondioxidesensor/CarbonDioxideLevelCharacteristic.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.github.hapjava.characteristics.impl.carbondioxidesensor; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic indicates the detected level of Carbon Dioxide in parts per million (ppm). - */ -public class CarbonDioxideLevelCharacteristic extends FloatCharacteristic { - public static final double DEFAULT_MIN_VALUE = 0; - public static final double DEFAULT_MAX_VALUE = 100000; - public static final double DEFAULT_STEP = 1; - - public CarbonDioxideLevelCharacteristic( - double minValue, - double maxValue, - double minStep, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000093-0000-1000-8000-0026BB765291", - "Carbon Dioxide Level", - minValue, - maxValue, - minStep, - "ppm", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public CarbonDioxideLevelCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, DEFAULT_STEP, getter, subscriber, unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/carbondioxidesensor/CarbonDioxidePeakLevelCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/carbondioxidesensor/CarbonDioxidePeakLevelCharacteristic.java deleted file mode 100644 index 1a1793773..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/carbondioxidesensor/CarbonDioxidePeakLevelCharacteristic.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.hapjava.characteristics.impl.carbondioxidesensor; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic indicates the highest detected level (ppm) of carbon dioxide. */ -public class CarbonDioxidePeakLevelCharacteristic extends FloatCharacteristic { - public static final double DEFAULT_MIN_VALUE = 0; - public static final double DEFAULT_MAX_VALUE = 100000; - public static final double DEFAULT_STEP = 1; - - public CarbonDioxidePeakLevelCharacteristic( - double minValue, - double maxValue, - double minStep, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000094-0000-1000-8000-0026BB765291", - "Carbon Dioxide Level", - minValue, - maxValue, - minStep, - "ppm", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public CarbonDioxidePeakLevelCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, DEFAULT_STEP, getter, subscriber, unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/carbonmonoxidesensor/CarbonMonoxideDetectedCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/carbonmonoxidesensor/CarbonMonoxideDetectedCharacteristic.java deleted file mode 100644 index 2ef603b6e..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/carbonmonoxidesensor/CarbonMonoxideDetectedCharacteristic.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.hapjava.characteristics.impl.carbonmonoxidesensor; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic indicates the levels of Carbon Monoxide. See {@link - * CarbonMonoxideDetectedEnum} for possible values - */ -public class CarbonMonoxideDetectedCharacteristic - extends EnumCharacteristic implements EventableCharacteristic { - - public CarbonMonoxideDetectedCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000069-0000-1000-8000-0026BB765291", - "Carbon Monoxide Detected", - CarbonMonoxideDetectedEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/carbonmonoxidesensor/CarbonMonoxideDetectedEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/carbonmonoxidesensor/CarbonMonoxideDetectedEnum.java deleted file mode 100644 index 2d1adf7f0..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/carbonmonoxidesensor/CarbonMonoxideDetectedEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.carbonmonoxidesensor; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Carbon Monoxide levels are normal” 1 ”Carbon Monoxide levels are abnormal” */ -public enum CarbonMonoxideDetectedEnum implements CharacteristicEnum { - NORMAL(0), - ABNORMAL(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(CarbonMonoxideDetectedEnum.values()) - .collect(Collectors.toMap(CarbonMonoxideDetectedEnum::getCode, t -> t)); - } - - public static CarbonMonoxideDetectedEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - CarbonMonoxideDetectedEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/carbonmonoxidesensor/CarbonMonoxideLevelCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/carbonmonoxidesensor/CarbonMonoxideLevelCharacteristic.java deleted file mode 100644 index e35171b38..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/carbonmonoxidesensor/CarbonMonoxideLevelCharacteristic.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.hapjava.characteristics.impl.carbonmonoxidesensor; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic contains the Carbon Monoxide levels in parts per million (ppm). */ -public class CarbonMonoxideLevelCharacteristic extends FloatCharacteristic { - public static final double DEFAULT_MIN_VALUE = 0; - public static final double DEFAULT_MAX_VALUE = 100; - public static final double DEFAULT_STEP = 1; - - public CarbonMonoxideLevelCharacteristic( - double minValue, - double maxValue, - double minStep, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000090-0000-1000-8000-0026BB765291", - "Carbon Monoxide Level", - minValue, - maxValue, - minStep, - "ppm", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public CarbonMonoxideLevelCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, DEFAULT_STEP, getter, subscriber, unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/carbonmonoxidesensor/CarbonMonoxidePeakLevelCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/carbonmonoxidesensor/CarbonMonoxidePeakLevelCharacteristic.java deleted file mode 100644 index 892901866..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/carbonmonoxidesensor/CarbonMonoxidePeakLevelCharacteristic.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.hapjava.characteristics.impl.carbonmonoxidesensor; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic indicates the highest detected level (ppm) of Carbon Monoxide. */ -public class CarbonMonoxidePeakLevelCharacteristic extends FloatCharacteristic { - public static final double DEFAULT_MIN_VALUE = 0; - public static final double DEFAULT_MAX_VALUE = 100; - public static final double DEFAULT_STEP = 1; - - public CarbonMonoxidePeakLevelCharacteristic( - double minValue, - double maxValue, - double minStep, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000091-0000-1000-8000-0026BB765291", - "Carbon Monoxide Peak Level", - minValue, - maxValue, - minStep, - "ppm", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public CarbonMonoxidePeakLevelCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, DEFAULT_STEP, getter, subscriber, unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/ActiveCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/ActiveCharacteristic.java deleted file mode 100644 index 0d7fc2c1c..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/ActiveCharacteristic.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * Active characteristic indicates whether the service is currently active. See {@link ActiveEnum} - * for possible values. - */ -public class ActiveCharacteristic extends EnumCharacteristic { - - public ActiveCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000B0-0000-1000-8000-0026BB765291", - "Active", - ActiveEnum.values(), - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/ActiveEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/common/ActiveEnum.java deleted file mode 100644 index 7fd0318c4..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/ActiveEnum.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Inactive” 1 ”Active” 2-255 ”Reserved” */ -public enum ActiveEnum implements CharacteristicEnum { - INACTIVE(0), - ACTIVE(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(ActiveEnum.values()).collect(Collectors.toMap(ActiveEnum::getCode, t -> t)); - } - - public static ActiveEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - ActiveEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/ActiveIdentifierCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/ActiveIdentifierCharacteristic.java deleted file mode 100644 index 587c1b666..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/ActiveIdentifierCharacteristic.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -public class ActiveIdentifierCharacteristic extends IntegerCharacteristic { - - public ActiveIdentifierCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000E7-0000-1000-8000-0026BB765291", - "active identifier", - 0, - 1000, - "", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/AirPlayEnableCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/AirPlayEnableCharacteristic.java deleted file mode 100644 index 6158f13be..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/AirPlayEnableCharacteristic.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** characteristic to control air play. */ -public class AirPlayEnableCharacteristic extends IntegerCharacteristic - implements EventableCharacteristic { - - public AirPlayEnableCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000025B-0000-1000-8000-0026BB765291", - "AirPlay enable", - 0, - 1, - "", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/ConfiguredNameCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/ConfiguredNameCharacteristic.java deleted file mode 100644 index 471d5a368..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/ConfiguredNameCharacteristic.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.StringCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes a configured name. */ -public class ConfiguredNameCharacteristic extends StringCharacteristic { - - public ConfiguredNameCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000E3-0000-1000-8000-0026BB765291", - "configured name", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/IdentifierCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/IdentifierCharacteristic.java deleted file mode 100644 index 4b8f7613c..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/IdentifierCharacteristic.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - -public class IdentifierCharacteristic extends IntegerCharacteristic { - - public IdentifierCharacteristic(Supplier> getter) { - super( - "000000E6-0000-1000-8000-0026BB765291", - "identifier", - 0, - 1000, - "", - Optional.of(getter), - Optional.empty(), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/InUseCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/InUseCharacteristic.java deleted file mode 100644 index 882c27a01..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/InUseCharacteristic.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic indicates whether the service is in use. See {@link InUseEnum} for possible - * values. - */ -public class InUseCharacteristic extends EnumCharacteristic { - public InUseCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000D2-0000-1000-8000-0026BB765291", - "In Use", - InUseEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/InUseEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/common/InUseEnum.java deleted file mode 100644 index 0b368b128..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/InUseEnum.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Not in use” 1 ”In use” 2-255 ”Reserved” */ -public enum InUseEnum implements CharacteristicEnum { - NOT_IN_USE(0), - IN_USE(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(InUseEnum.values()).collect(Collectors.toMap(InUseEnum::getCode, t -> t)); - } - - public static InUseEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - InUseEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/IsConfiguredCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/IsConfiguredCharacteristic.java deleted file mode 100644 index c016e87c9..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/IsConfiguredCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes whether the service is configured for use. See {@link - * IsConfiguredEnum} for possible values. - */ -public class IsConfiguredCharacteristic extends EnumCharacteristic { - public IsConfiguredCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000D6-0000-1000-8000-0026BB765291", - "Is Configured", - IsConfiguredEnum.values(), - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/IsConfiguredEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/common/IsConfiguredEnum.java deleted file mode 100644 index 1d20f6b3b..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/IsConfiguredEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Not Configured” 1 ”Configured” 2-255 ”Reserved” */ -public enum IsConfiguredEnum implements CharacteristicEnum { - NOT_CONFIGURED(0), - CONFIGURED(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(IsConfiguredEnum.values()) - .collect(Collectors.toMap(IsConfiguredEnum::getCode, t -> t)); - } - - public static IsConfiguredEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - IsConfiguredEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/NameCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/NameCharacteristic.java deleted file mode 100644 index 49c3a824a..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/NameCharacteristic.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.impl.base.StaticStringCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - -/** This characteristic describes a name and must not be a null value. */ -public class NameCharacteristic extends StaticStringCharacteristic { - - public NameCharacteristic(Supplier> getter) { - super( - "00000023-0000-1000-8000-0026BB765291", - "name", - Optional.of(getter), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/ObstructionDetectedCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/ObstructionDetectedCharacteristic.java deleted file mode 100644 index 2644232e3..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/ObstructionDetectedCharacteristic.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.BooleanCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the current state of an obstruction sensor. */ -public class ObstructionDetectedCharacteristic extends BooleanCharacteristic { - public ObstructionDetectedCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000024-0000-1000-8000-0026BB765291", - "Obstruction", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/OnCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/OnCharacteristic.java deleted file mode 100644 index 99da018b8..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/OnCharacteristic.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.BooleanCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic represents the states for “on” and “off”. */ -public class OnCharacteristic extends BooleanCharacteristic { - - public OnCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000025-0000-1000-8000-0026BB765291", - "On / Off state", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/ProgramModeCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/ProgramModeCharacteristic.java deleted file mode 100644 index 1580ae392..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/ProgramModeCharacteristic.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes if there are programs scheduled on the accessory. See {@link - * ProgramModeEnum} for possible values. - */ -public class ProgramModeCharacteristic extends EnumCharacteristic { - public ProgramModeCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000D1-0000-1000-8000-0026BB765291", - "Program Mode", - ProgramModeEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/ProgramModeEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/common/ProgramModeEnum.java deleted file mode 100644 index 7924f370b..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/ProgramModeEnum.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * 0 ”No Programs Scheduled” 1 ”Program Scheduled” 2 ”Program Scheduled, currently overriden to - * manual mode” - */ -public enum ProgramModeEnum implements CharacteristicEnum { - NO_SCHEDULED(0), - SCHEDULED(1), - SCHEDULED_MANUAL(2); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(ProgramModeEnum.values()) - .collect(Collectors.toMap(ProgramModeEnum::getCode, t -> t)); - } - - public static ProgramModeEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - ProgramModeEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/ProgrammableSwitchEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/common/ProgrammableSwitchEnum.java deleted file mode 100644 index 988472a0c..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/ProgrammableSwitchEnum.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Single Press” 1 ”Double Press” 2 ”Long Press” 3-255 ”Reserved” */ -public enum ProgrammableSwitchEnum implements CharacteristicEnum { - SINGLE_PRESS(0), - DOUBLE_PRESS(1), - LONG_PRESS(2); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(ProgrammableSwitchEnum.values()) - .collect(Collectors.toMap(ProgrammableSwitchEnum::getCode, t -> t)); - } - - public static ProgrammableSwitchEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - ProgrammableSwitchEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/ProgrammableSwitchEventCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/ProgrammableSwitchEventCharacteristic.java deleted file mode 100644 index b19430100..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/ProgrammableSwitchEventCharacteristic.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes an event generated by a programmable switch. For BLE accessories, - * read request should return the last event. For IP accessory, read request must return "null". The - * changes are reported via events - * - *

See {@link ProgrammableSwitchEnum} for possible values. - */ -public class ProgrammableSwitchEventCharacteristic - extends EnumCharacteristic { - - public ProgrammableSwitchEventCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - this(ProgrammableSwitchEnum.values(), getter, subscriber, unsubscriber); - } - - public ProgrammableSwitchEventCharacteristic( - ProgrammableSwitchEnum[] validValues, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000073-0000-1000-8000-0026BB765291", - "Switch Event", - validValues, - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/ServiceLabelIndexCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/ServiceLabelIndexCharacteristic.java deleted file mode 100644 index 522cb04fe..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/ServiceLabelIndexCharacteristic.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - -/** - * This characteristic is used to identify the index of the label according to {@link - * ServiceLabelNamespaceCharacteristic} - */ -public class ServiceLabelIndexCharacteristic extends IntegerCharacteristic - implements EventableCharacteristic { - - public ServiceLabelIndexCharacteristic(Supplier> getter) { - super( - "000000CB-0000-1000-8000-0026BB765291", - "service label index", - 0, - 100, - "%", - Optional.of(getter), - Optional.empty(), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/ServiceLabelNamespaceCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/ServiceLabelNamespaceCharacteristic.java deleted file mode 100644 index 9f8dd3248..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/ServiceLabelNamespaceCharacteristic.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - -/** - * This characteristic describes the naming schema for an accessory. See {@link - * ServiceLabelNamespaceEnum} for possible values. - */ -public class ServiceLabelNamespaceCharacteristic - extends EnumCharacteristic { - public ServiceLabelNamespaceCharacteristic( - Supplier> getter) { - super( - "000000CD-0000-1000-8000-0026BB765291", - "service label namespace", - ServiceLabelNamespaceEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/ServiceLabelNamespaceEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/common/ServiceLabelNamespaceEnum.java deleted file mode 100644 index a9b2df513..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/ServiceLabelNamespaceEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Dots. For e.g ”.” ”..” ”...” ”....”” 1 ”Arabic numerals. For e.g. 0,1,2,3” */ -public enum ServiceLabelNamespaceEnum implements CharacteristicEnum { - DOTS(0), - ARABIC_NUMERALS(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(ServiceLabelNamespaceEnum.values()) - .collect(Collectors.toMap(ServiceLabelNamespaceEnum::getCode, t -> t)); - } - - public static ServiceLabelNamespaceEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - ServiceLabelNamespaceEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/StatusActiveCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/StatusActiveCharacteristic.java deleted file mode 100644 index a242ae6a1..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/StatusActiveCharacteristic.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.BooleanCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes current working (active and functional) status of accessory. */ -public class StatusActiveCharacteristic extends BooleanCharacteristic { - public StatusActiveCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000075-0000-1000-8000-0026BB765291", - "Active status", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/StatusFaultCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/StatusFaultCharacteristic.java deleted file mode 100644 index 5754e11a8..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/StatusFaultCharacteristic.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes fault status. See {@link StatusFaultEnum} for possible values. */ -public class StatusFaultCharacteristic extends EnumCharacteristic { - - public StatusFaultCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000077-0000-1000-8000-0026BB765291", - "Status Fault", - StatusFaultEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/StatusFaultEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/common/StatusFaultEnum.java deleted file mode 100644 index 4fd866847..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/StatusFaultEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”No Fault” 1 ”General Fault” */ -public enum StatusFaultEnum implements CharacteristicEnum { - NO_FAULT(0), - GENERAL_FAULT(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(StatusFaultEnum.values()) - .collect(Collectors.toMap(StatusFaultEnum::getCode, t -> t)); - } - - public static StatusFaultEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - StatusFaultEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/StatusTamperedCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/StatusTamperedCharacteristic.java deleted file mode 100644 index 501bbaedb..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/StatusTamperedCharacteristic.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes tampered status. See {@link StatusTamperedEnum} for possible - * values. - */ -public class StatusTamperedCharacteristic extends EnumCharacteristic { - - public StatusTamperedCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000007A-0000-1000-8000-0026BB765291", - "Status Tampered", - StatusTamperedEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/StatusTamperedEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/common/StatusTamperedEnum.java deleted file mode 100644 index 2d725c132..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/StatusTamperedEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Accessory is not tampered” 1 ”Accessory is tampered with” */ -public enum StatusTamperedEnum implements CharacteristicEnum { - NOT_TAMPERED(0), - TAMPERED(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(StatusTamperedEnum.values()) - .collect(Collectors.toMap(StatusTamperedEnum::getCode, t -> t)); - } - - public static StatusTamperedEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - StatusTamperedEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/VersionCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/VersionCharacteristic.java deleted file mode 100644 index 75c8aaf9e..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/VersionCharacteristic.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.impl.base.StaticStringCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - -/** This characteristic describes HAP version. */ -public class VersionCharacteristic extends StaticStringCharacteristic { - - public VersionCharacteristic(Supplier> getter) { - super( - "00000037-0000-1000-8000-0026BB765291", - "HAP version", - Optional.of(getter), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/common/WaterLavelCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/common/WaterLavelCharacteristic.java deleted file mode 100644 index dda11b087..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/common/WaterLavelCharacteristic.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.hapjava.characteristics.impl.common; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the water level. */ -public class WaterLavelCharacteristic extends FloatCharacteristic - implements EventableCharacteristic { - - public WaterLavelCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000B5-0000-1000-8000-0026BB765291", - "water level", - 0, - 100, - 1, - "%", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/contactsensor/ContactSensorStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/contactsensor/ContactSensorStateCharacteristic.java deleted file mode 100644 index 8ac3c1fde..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/contactsensor/ContactSensorStateCharacteristic.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.hapjava.characteristics.impl.contactsensor; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes the state of a door/window contact sensor. See {@link - * ContactStateEnum} for possible values. - */ -public class ContactSensorStateCharacteristic extends EnumCharacteristic - implements EventableCharacteristic { - - public ContactSensorStateCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000006A-0000-1000-8000-0026BB765291", - "Contact Sensor", - ContactStateEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/contactsensor/ContactStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/contactsensor/ContactStateEnum.java deleted file mode 100644 index 275ed9734..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/contactsensor/ContactStateEnum.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.hapjava.characteristics.impl.contactsensor; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/* - * 0 ”Contact is detected” - * 1 ”Contact is not detected” - */ -public enum ContactStateEnum implements CharacteristicEnum { - DETECTED(0), - NOT_DETECTED(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(ContactStateEnum.values()) - .collect(Collectors.toMap(ContactStateEnum::getCode, t -> t)); - } - - public static ContactStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - ContactStateEnum(int code) { - this.code = code; - } - - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/fan/CurrentFanStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/fan/CurrentFanStateCharacteristic.java deleted file mode 100644 index 75f932e50..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/fan/CurrentFanStateCharacteristic.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.hapjava.characteristics.impl.fan; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes the current state of the fan. See {@link CurrentFanStateEnum} for - * possible values. - */ -public class CurrentFanStateCharacteristic extends EnumCharacteristic - implements EventableCharacteristic { - - public CurrentFanStateCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000AF-0000-1000-8000-0026BB765291", - "Current Fan State", - CurrentFanStateEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/fan/CurrentFanStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/fan/CurrentFanStateEnum.java deleted file mode 100644 index 674924e9a..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/fan/CurrentFanStateEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.fan; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -public enum CurrentFanStateEnum implements CharacteristicEnum { - INACTIVE(0), - IDLE(1), - BLOWING_AIR(2); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(CurrentFanStateEnum.values()) - .collect(Collectors.toMap(CurrentFanStateEnum::getCode, t -> t)); - } - - public static CurrentFanStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - CurrentFanStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/fan/LockPhysicalControlsCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/fan/LockPhysicalControlsCharacteristic.java deleted file mode 100644 index 8ea6f35c6..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/fan/LockPhysicalControlsCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.fan; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes physical controls on an accessory (eg. child lock). */ -public class LockPhysicalControlsCharacteristic extends EnumCharacteristic - implements EventableCharacteristic { - - public LockPhysicalControlsCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000A7-0000-1000-8000-0026BB765291", - "Physical Locks", - LockPhysicalControlsEnum.values(), - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/fan/LockPhysicalControlsEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/fan/LockPhysicalControlsEnum.java deleted file mode 100644 index 87503ed96..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/fan/LockPhysicalControlsEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.fan; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Control lock disabled” 1 ”Control lock enabled” */ -public enum LockPhysicalControlsEnum implements CharacteristicEnum { - CONTROL_LOCK_DISABLED(0), - CONTROL_LOCK_ENABLED(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(LockPhysicalControlsEnum.values()) - .collect(Collectors.toMap(LockPhysicalControlsEnum::getCode, t -> t)); - } - - public static LockPhysicalControlsEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - LockPhysicalControlsEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationDirectionCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationDirectionCharacteristic.java deleted file mode 100644 index efa82681f..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationDirectionCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.fan; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the direction of rotation of a fan. */ -public class RotationDirectionCharacteristic extends EnumCharacteristic - implements EventableCharacteristic { - - public RotationDirectionCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000028-0000-1000-8000-0026BB765291", - "Rotation direction", - RotationDirectionEnum.values(), - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationDirectionEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationDirectionEnum.java deleted file mode 100644 index 20651fd1c..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationDirectionEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.fan; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Clockwise” 1 ”Counter-clockwise” 2-255 ”Reserved” */ -public enum RotationDirectionEnum implements CharacteristicEnum { - CLOCKWISE(0), - COUNTER_CLOCKWISE(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(RotationDirectionEnum.values()) - .collect(Collectors.toMap(RotationDirectionEnum::getCode, t -> t)); - } - - public static RotationDirectionEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - RotationDirectionEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java deleted file mode 100644 index d7a1d6929..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java +++ /dev/null @@ -1,54 +0,0 @@ -package io.github.hapjava.characteristics.impl.fan; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the rotation speed of a fan. */ -public class RotationSpeedCharacteristic extends FloatCharacteristic - implements EventableCharacteristic { - public static final double DEFAULT_MIN_VALUE = 0; - public static final double DEFAULT_MAX_VALUE = 100; - public static final double DEFAULT_STEP = 1; - - public RotationSpeedCharacteristic( - double minValue, - double maxValue, - double minStep, - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000029-0000-1000-8000-0026BB765291", - "Rotation Speed", - minValue, - maxValue, - minStep, - "%", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public RotationSpeedCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - this( - DEFAULT_MIN_VALUE, - DEFAULT_MAX_VALUE, - DEFAULT_STEP, - getter, - setter, - subscriber, - unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/fan/SwingModeCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/fan/SwingModeCharacteristic.java deleted file mode 100644 index ba58dfd0f..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/fan/SwingModeCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.fan; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes if swing mode is enabled. */ -public class SwingModeCharacteristic extends EnumCharacteristic - implements EventableCharacteristic { - - public SwingModeCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000B6-0000-1000-8000-0026BB765291", - "Swing Mode", - SwingModeEnum.values(), - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/fan/SwingModeEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/fan/SwingModeEnum.java deleted file mode 100644 index 928bafd27..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/fan/SwingModeEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.fan; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Swing disabled” 1 ”Swing enabled” */ -public enum SwingModeEnum implements CharacteristicEnum { - SWING_DISABLED(0), - SWING_ENABLED(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(SwingModeEnum.values()) - .collect(Collectors.toMap(SwingModeEnum::getCode, t -> t)); - } - - public static SwingModeEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - SwingModeEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/fan/TargetFanStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/fan/TargetFanStateCharacteristic.java deleted file mode 100644 index 1ab9ca305..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/fan/TargetFanStateCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.fan; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the target state of the fan. */ -public class TargetFanStateCharacteristic extends EnumCharacteristic - implements EventableCharacteristic { - - public TargetFanStateCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000BF-0000-1000-8000-0026BB765291", - "Target Fan State", - TargetFanStateEnum.values(), - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/fan/TargetFanStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/fan/TargetFanStateEnum.java deleted file mode 100644 index 600f07401..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/fan/TargetFanStateEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.fan; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Manual” 1 ”Auto” */ -public enum TargetFanStateEnum implements CharacteristicEnum { - MANUAL(0), - AUTO(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(TargetFanStateEnum.values()) - .collect(Collectors.toMap(TargetFanStateEnum::getCode, t -> t)); - } - - public static TargetFanStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - TargetFanStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/FilterChangeIndicationCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/FilterChangeIndicationCharacteristic.java deleted file mode 100644 index 31ccbb25e..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/FilterChangeIndicationCharacteristic.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.github.hapjava.characteristics.impl.filtermaintenance; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -public class FilterChangeIndicationCharacteristic - extends EnumCharacteristic implements EventableCharacteristic { - - public FilterChangeIndicationCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000AC-0000-1000-8000-0026BB765291", - "filter change indication", - FilterChangeIndicationEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/FilterChangeIndicationEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/FilterChangeIndicationEnum.java deleted file mode 100644 index 03d610afb..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/FilterChangeIndicationEnum.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.characteristics.impl.filtermaintenance; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -public enum FilterChangeIndicationEnum implements CharacteristicEnum { - NO_CHANGE_NEEDED(0), - CHANGE_NEEDED(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(FilterChangeIndicationEnum.values()) - .collect(Collectors.toMap(FilterChangeIndicationEnum::getCode, t -> t)); - } - - public static FilterChangeIndicationEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - FilterChangeIndicationEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/FilterLifeLevelCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/FilterLifeLevelCharacteristic.java deleted file mode 100644 index 29cdf8d6e..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/FilterLifeLevelCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.filtermaintenance; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -public class FilterLifeLevelCharacteristic extends FloatCharacteristic - implements EventableCharacteristic { - - public FilterLifeLevelCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000AB-0000-1000-8000-0026BB765291", - "Filter Life Level", - 0, - 100, - 1, - "%", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/ResetFilterIndicationCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/ResetFilterIndicationCharacteristic.java deleted file mode 100644 index 10d06bf96..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/filtermaintenance/ResetFilterIndicationCharacteristic.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.github.hapjava.characteristics.impl.filtermaintenance; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; - -public class ResetFilterIndicationCharacteristic extends IntegerCharacteristic { - - public ResetFilterIndicationCharacteristic(ExceptionalConsumer setter) { - super( - "000000AD-0000-1000-8000-0026BB765291", - "Reset Filter Indication", - 1, - 1, - null, - Optional.empty(), - Optional.of(setter), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/garagedoor/CurrentDoorStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/garagedoor/CurrentDoorStateCharacteristic.java deleted file mode 100644 index e06937daa..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/garagedoor/CurrentDoorStateCharacteristic.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.hapjava.characteristics.impl.garagedoor; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the current state of a door. */ -public class CurrentDoorStateCharacteristic extends EnumCharacteristic - implements EventableCharacteristic { - - public CurrentDoorStateCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000000E-0000-1000-8000-0026BB765291", - "Current Door State", - CurrentDoorStateEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/garagedoor/CurrentDoorStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/garagedoor/CurrentDoorStateEnum.java deleted file mode 100644 index 88474e6cc..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/garagedoor/CurrentDoorStateEnum.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.hapjava.characteristics.impl.garagedoor; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * 0 ”Open. The door is fully open.” 1 ”Closed. The door is fully closed.” 2 ”Opening. The door is - * actively opening.” 3 ”Closing. The door is actively closing.” 4 ”Stopped. The door is not moving, - * and it is not fully open nor fully closed.” - */ -public enum CurrentDoorStateEnum implements CharacteristicEnum { - OPEN(0), - CLOSED(1), - OPENING(2), - CLOSING(3), - STOPPED(4); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(CurrentDoorStateEnum.values()) - .collect(Collectors.toMap(CurrentDoorStateEnum::getCode, t -> t)); - } - - public static CurrentDoorStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - CurrentDoorStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/garagedoor/TargetDoorStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/garagedoor/TargetDoorStateCharacteristic.java deleted file mode 100644 index f5b490c6e..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/garagedoor/TargetDoorStateCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.garagedoor; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the target state of a door. */ -public class TargetDoorStateCharacteristic extends EnumCharacteristic - implements EventableCharacteristic { - - public TargetDoorStateCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000032-0000-1000-8000-0026BB765291", - "Target Door State", - TargetDoorStateEnum.values(), - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/garagedoor/TargetDoorStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/garagedoor/TargetDoorStateEnum.java deleted file mode 100644 index ca282fdc3..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/garagedoor/TargetDoorStateEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.garagedoor; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Open” 1 ”Closed” 2-255 ”Reserved” */ -public enum TargetDoorStateEnum implements CharacteristicEnum { - OPEN(0), - CLOSED(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(TargetDoorStateEnum.values()) - .collect(Collectors.toMap(TargetDoorStateEnum::getCode, t -> t)); - } - - public static TargetDoorStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - TargetDoorStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/heatercooler/CurrentHeaterCoolerStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/heatercooler/CurrentHeaterCoolerStateCharacteristic.java deleted file mode 100644 index f7d48bae6..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/heatercooler/CurrentHeaterCoolerStateCharacteristic.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.hapjava.characteristics.impl.heatercooler; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the current state of a heater cooler. */ -public class CurrentHeaterCoolerStateCharacteristic - extends EnumCharacteristic implements EventableCharacteristic { - - public CurrentHeaterCoolerStateCharacteristic( - CurrentHeaterCoolerStateEnum[] validValues, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000B1-0000-1000-8000-0026BB765291", - "current heater cooler state", - validValues, - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/heatercooler/CurrentHeaterCoolerStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/heatercooler/CurrentHeaterCoolerStateEnum.java deleted file mode 100644 index 9864acb12..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/heatercooler/CurrentHeaterCoolerStateEnum.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.hapjava.characteristics.impl.heatercooler; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Inactive” 1 ”Idle” 2 ”Heating” 3 ”Cooling” */ -public enum CurrentHeaterCoolerStateEnum implements CharacteristicEnum { - INACTIVE(0), - IDLE(1), - HEATING(2), - COOLING(3); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(CurrentHeaterCoolerStateEnum.values()) - .collect(Collectors.toMap(CurrentHeaterCoolerStateEnum::getCode, t -> t)); - } - - public static CurrentHeaterCoolerStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - CurrentHeaterCoolerStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/heatercooler/TargetHeaterCoolerStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/heatercooler/TargetHeaterCoolerStateCharacteristic.java deleted file mode 100644 index a9a167d45..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/heatercooler/TargetHeaterCoolerStateCharacteristic.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.hapjava.characteristics.impl.heatercooler; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the target state of heater cooler. */ -public class TargetHeaterCoolerStateCharacteristic - extends EnumCharacteristic implements EventableCharacteristic { - - public TargetHeaterCoolerStateCharacteristic( - TargetHeaterCoolerStateEnum[] validValues, - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000B2-0000-1000-8000-0026BB765291", - "target heater cooler state", - validValues, - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/heatercooler/TargetHeaterCoolerStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/heatercooler/TargetHeaterCoolerStateEnum.java deleted file mode 100644 index a16d3cd6a..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/heatercooler/TargetHeaterCoolerStateEnum.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.hapjava.characteristics.impl.heatercooler; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 AUTO - ”Heat or Cool” 1 ”Heat” 2 ”Cool” */ -public enum TargetHeaterCoolerStateEnum implements CharacteristicEnum { - AUTO(0), - HEAT(1), - COOL(2); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(TargetHeaterCoolerStateEnum.values()) - .collect(Collectors.toMap(TargetHeaterCoolerStateEnum::getCode, t -> t)); - } - - public static TargetHeaterCoolerStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - TargetHeaterCoolerStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/CurrentHumidifierDehumidifierStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/humidifier/CurrentHumidifierDehumidifierStateCharacteristic.java deleted file mode 100644 index 229d0aa73..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/CurrentHumidifierDehumidifierStateCharacteristic.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.hapjava.characteristics.impl.humidifier; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the current state of a humidifier or/and a dehumidifier. */ -public class CurrentHumidifierDehumidifierStateCharacteristic - extends EnumCharacteristic - implements EventableCharacteristic { - - public CurrentHumidifierDehumidifierStateCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000B3-0000-1000-8000-0026BB765291", - "current humidifier state", - CurrentHumidifierDehumidifierStateEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/CurrentHumidifierDehumidifierStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/humidifier/CurrentHumidifierDehumidifierStateEnum.java deleted file mode 100644 index d6ec775de..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/CurrentHumidifierDehumidifierStateEnum.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.hapjava.characteristics.impl.humidifier; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Inactive” 1 ”Idle” 2 ”Humidifying” 3 ”Dehumidifying” */ -public enum CurrentHumidifierDehumidifierStateEnum implements CharacteristicEnum { - INACTIVE(0), - IDLE(1), - HUMIDIFYING(2), - DEHUMIDIFYING(3); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(CurrentHumidifierDehumidifierStateEnum.values()) - .collect(Collectors.toMap(CurrentHumidifierDehumidifierStateEnum::getCode, t -> t)); - } - - public static CurrentHumidifierDehumidifierStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - CurrentHumidifierDehumidifierStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/HumidityDehumidifierThresholdCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/humidifier/HumidityDehumidifierThresholdCharacteristic.java deleted file mode 100644 index b8a4ca569..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/HumidityDehumidifierThresholdCharacteristic.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.characteristics.impl.humidifier; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes the relative humidity dehumidifier threshold on which dehumidifier - * turns on. - */ -public class HumidityDehumidifierThresholdCharacteristic extends FloatCharacteristic { - - public HumidityDehumidifierThresholdCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000C9-0000-1000-8000-0026BB765291", - "humidity threshold dehumidifier", - 0, - 100, - 1, - "%", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/HumidityHumidifierThresholdCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/humidifier/HumidityHumidifierThresholdCharacteristic.java deleted file mode 100644 index 2ee8adbf2..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/HumidityHumidifierThresholdCharacteristic.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.characteristics.impl.humidifier; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes the relative humidity humidifier threshold on which humidifier - * turns on. - */ -public class HumidityHumidifierThresholdCharacteristic extends FloatCharacteristic { - - public HumidityHumidifierThresholdCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000CA-0000-1000-8000-0026BB765291", - "humidity threshold humidifier", - 0, - 100, - 1, - "%", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/TargetHumidifierDehumidifierStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/humidifier/TargetHumidifierDehumidifierStateCharacteristic.java deleted file mode 100644 index 4b4a90a54..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/TargetHumidifierDehumidifierStateCharacteristic.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.github.hapjava.characteristics.impl.humidifier; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the target state of a humidifier or/and a dehumidifier.. */ -public class TargetHumidifierDehumidifierStateCharacteristic - extends EnumCharacteristic - implements EventableCharacteristic { - - public TargetHumidifierDehumidifierStateCharacteristic( - TargetHumidifierDehumidifierStateEnum[] validValues, - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000B4-0000-1000-8000-0026BB765291", - "target humidifier state", - validValues, - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/TargetHumidifierDehumidifierStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/humidifier/TargetHumidifierDehumidifierStateEnum.java deleted file mode 100644 index 3d4fee0a5..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/humidifier/TargetHumidifierDehumidifierStateEnum.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.hapjava.characteristics.impl.humidifier; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 - Auto - ”Humidifier or Dehumidifier” 1 ”Humidifier” 2 ”Dehumidifier” */ -public enum TargetHumidifierDehumidifierStateEnum implements CharacteristicEnum { - AUTO(0), - HUMIDIFIER(1), - DEHUMIDIFIER(2); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(TargetHumidifierDehumidifierStateEnum.values()) - .collect(Collectors.toMap(TargetHumidifierDehumidifierStateEnum::getCode, t -> t)); - } - - public static TargetHumidifierDehumidifierStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - TargetHumidifierDehumidifierStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/humiditysensor/CurrentRelativeHumidityCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/humiditysensor/CurrentRelativeHumidityCharacteristic.java deleted file mode 100644 index be77125b6..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/humiditysensor/CurrentRelativeHumidityCharacteristic.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.hapjava.characteristics.impl.humiditysensor; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the current relative humidity. */ -public class CurrentRelativeHumidityCharacteristic extends FloatCharacteristic { - - public CurrentRelativeHumidityCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000010-0000-1000-8000-0026BB765291", - "Current Relative Humidity", - 0, - 100, - 1, - "%", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/humiditysensor/TargetRelativeHumidityCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/humiditysensor/TargetRelativeHumidityCharacteristic.java deleted file mode 100644 index ab8ad7e29..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/humiditysensor/TargetRelativeHumidityCharacteristic.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.hapjava.characteristics.impl.humiditysensor; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the target relative humidity. */ -public class TargetRelativeHumidityCharacteristic extends FloatCharacteristic { - - public TargetRelativeHumidityCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000034-0000-1000-8000-0026BB765291", - "Target Relative Humidity", - 0, - 100, - 1, - "%", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/CurrentVisibilityStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/inputsource/CurrentVisibilityStateCharacteristic.java deleted file mode 100644 index 65c358a3f..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/CurrentVisibilityStateCharacteristic.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.github.hapjava.characteristics.impl.inputsource; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes current visibility state. */ -public class CurrentVisibilityStateCharacteristic - extends EnumCharacteristic { - - public CurrentVisibilityStateCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000135-0000-1000-8000-0026BB765291", - "current visibility state", - CurrentVisibilityStateEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/CurrentVisibilityStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/inputsource/CurrentVisibilityStateEnum.java deleted file mode 100644 index 2159393d8..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/CurrentVisibilityStateEnum.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.hapjava.characteristics.impl.inputsource; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -public enum CurrentVisibilityStateEnum implements CharacteristicEnum { - SHOWN(0), - HIDDEN(1), - UNKNOWN_1(2), - UNKNOWN_2(3); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(CurrentVisibilityStateEnum.values()) - .collect(Collectors.toMap(CurrentVisibilityStateEnum::getCode, t -> t)); - } - - public static CurrentVisibilityStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - CurrentVisibilityStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/InputDeviceTypeCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/inputsource/InputDeviceTypeCharacteristic.java deleted file mode 100644 index 51a6fbde5..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/InputDeviceTypeCharacteristic.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.characteristics.impl.inputsource; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes input device type. */ -public class InputDeviceTypeCharacteristic extends EnumCharacteristic { - - public InputDeviceTypeCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000DC-0000-1000-8000-0026BB765291", - "input device type", - InputDeviceTypeEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/InputDeviceTypeEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/inputsource/InputDeviceTypeEnum.java deleted file mode 100644 index 5c7337174..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/InputDeviceTypeEnum.java +++ /dev/null @@ -1,38 +0,0 @@ -package io.github.hapjava.characteristics.impl.inputsource; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -public enum InputDeviceTypeEnum implements CharacteristicEnum { - OTHER(0), - TV(1), - RECORDING(2), - TUNER(3), - PLAYBACK(4), - AUDIO_SYSTEM(5); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(InputDeviceTypeEnum.values()) - .collect(Collectors.toMap(InputDeviceTypeEnum::getCode, t -> t)); - } - - public static InputDeviceTypeEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - InputDeviceTypeEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/InputSourceTypeCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/inputsource/InputSourceTypeCharacteristic.java deleted file mode 100644 index 91134891b..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/InputSourceTypeCharacteristic.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.characteristics.impl.inputsource; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes input source type. */ -public class InputSourceTypeCharacteristic extends EnumCharacteristic { - - public InputSourceTypeCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000DB-0000-1000-8000-0026BB765291", - "input source type", - InputSourceTypeEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/InputSourceTypeEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/inputsource/InputSourceTypeEnum.java deleted file mode 100644 index 94545ec18..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/InputSourceTypeEnum.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.github.hapjava.characteristics.impl.inputsource; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -public enum InputSourceTypeEnum implements CharacteristicEnum { - OTHER(0), - HOME_SCREEN(1), - TUNER(2), - HDMI(3), - COMPOSITE_VIDEO(4), - S_VIDEO(5), - COMPONENT_VIDEO(6), - DVI(7), - AIRPLAY(8), - USB(9), - APPLICATION(10); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(InputSourceTypeEnum.values()) - .collect(Collectors.toMap(InputSourceTypeEnum::getCode, t -> t)); - } - - public static InputSourceTypeEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - InputSourceTypeEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/TargetVisibilityStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/inputsource/TargetVisibilityStateCharacteristic.java deleted file mode 100644 index ea466d182..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/TargetVisibilityStateCharacteristic.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.hapjava.characteristics.impl.inputsource; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes target visibility state. */ -public class TargetVisibilityStateCharacteristic - extends EnumCharacteristic { - - public TargetVisibilityStateCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000134-0000-1000-8000-0026BB765291", - "target visibility state", - TargetVisibilityStateEnum.values(), - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/TargetVisibilityStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/inputsource/TargetVisibilityStateEnum.java deleted file mode 100644 index 6a75b0c30..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/inputsource/TargetVisibilityStateEnum.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.characteristics.impl.inputsource; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -public enum TargetVisibilityStateEnum implements CharacteristicEnum { - SHOWN(0), - HIDDEN(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(TargetVisibilityStateEnum.values()) - .collect(Collectors.toMap(TargetVisibilityStateEnum::getCode, t -> t)); - } - - public static TargetVisibilityStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - TargetVisibilityStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/leaksensor/LeakDetectedStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/leaksensor/LeakDetectedStateCharacteristic.java deleted file mode 100644 index ca0a2043e..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/leaksensor/LeakDetectedStateCharacteristic.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.hapjava.characteristics.impl.leaksensor; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic indicates if a sensor detected a leak (e.g. water leak, gas leak). See {@link - * LeakDetectedStateEnum} for possible values - */ -public class LeakDetectedStateCharacteristic extends EnumCharacteristic - implements EventableCharacteristic { - - public LeakDetectedStateCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000070-0000-1000-8000-0026BB765291", - "Leak Detected State", - LeakDetectedStateEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/leaksensor/LeakDetectedStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/leaksensor/LeakDetectedStateEnum.java deleted file mode 100644 index 1708230c8..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/leaksensor/LeakDetectedStateEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.leaksensor; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Leak is not detected” 1 ”Leak is detected” */ -public enum LeakDetectedStateEnum implements CharacteristicEnum { - LEAK_NOT_DETECTED(0), - LEAK_DETECTED(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(LeakDetectedStateEnum.values()) - .collect(Collectors.toMap(LeakDetectedStateEnum::getCode, t -> t)); - } - - public static LeakDetectedStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - LeakDetectedStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/BrightnessCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/BrightnessCharacteristic.java deleted file mode 100644 index 693e42efc..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/BrightnessCharacteristic.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.lightbulb; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes a perceived level of brightness, The value is a percentage (%) of - * the maximum level of supported brightness. - */ -public class BrightnessCharacteristic extends IntegerCharacteristic - implements EventableCharacteristic { - - public BrightnessCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000008-0000-1000-8000-0026BB765291", - "level of brightness", - 0, - 100, - "%", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/ColorTemperatureCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/ColorTemperatureCharacteristic.java deleted file mode 100644 index 987ab5eee..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/ColorTemperatureCharacteristic.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.github.hapjava.characteristics.impl.lightbulb; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes color temperature in mireds */ -public class ColorTemperatureCharacteristic extends IntegerCharacteristic - implements EventableCharacteristic { - public static final int DEFAULT_MIN_VALUE = 50; - public static final int DEFAULT_MAX_VALUE = 400; - - public ColorTemperatureCharacteristic( - int minValue, - int maxValue, - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000CE-0000-1000-8000-0026BB765291", - "color temperature", - minValue, - maxValue, - "mired", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public ColorTemperatureCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, getter, setter, subscriber, unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/HueCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/HueCharacteristic.java deleted file mode 100644 index 7a00816bc..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/HueCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.lightbulb; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes hue or color. */ -public class HueCharacteristic extends FloatCharacteristic { - public HueCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000013-0000-1000-8000-0026BB765291", - "hue or color", - 0, - 360, - 1, - "arcdegrees", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/SaturationCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/SaturationCharacteristic.java deleted file mode 100644 index 90694ef98..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/lightbulb/SaturationCharacteristic.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.github.hapjava.characteristics.impl.lightbulb; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes color saturation. */ -public class SaturationCharacteristic extends FloatCharacteristic - implements EventableCharacteristic { - - public SaturationCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000002F-0000-1000-8000-0026BB765291", - "color saturation", - 0, - 100, - 1, - "%", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/lightsensor/CurrentAmbientLightLevelCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/lightsensor/CurrentAmbientLightLevelCharacteristic.java deleted file mode 100644 index afec35ce6..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/lightsensor/CurrentAmbientLightLevelCharacteristic.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.hapjava.characteristics.impl.lightsensor; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic indicates the current light level in Lux */ -public class CurrentAmbientLightLevelCharacteristic extends FloatCharacteristic { - public static final double DEFAULT_MIN_VALUE = 0.0001; - public static final double DEFAULT_MAX_VALUE = 100000; - public static final double DEFAULT_STEP = 0.0001; - - public CurrentAmbientLightLevelCharacteristic( - double minValue, - double maxValue, - double minStep, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000006B-0000-1000-8000-0026BB765291", - "ambient light level", - minValue, - maxValue, - minStep, - "lux", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public CurrentAmbientLightLevelCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, DEFAULT_STEP, getter, subscriber, unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/lock/LockCurrentStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/lock/LockCurrentStateCharacteristic.java deleted file mode 100644 index b6946313b..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/lock/LockCurrentStateCharacteristic.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.characteristics.impl.lock; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** The current state of the physical security mechanism (e.g. deadbolt). */ -public class LockCurrentStateCharacteristic extends EnumCharacteristic { - - public LockCurrentStateCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000001D-0000-1000-8000-0026BB765291", - "Current Lock State", - LockCurrentStateEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/lock/LockCurrentStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/lock/LockCurrentStateEnum.java deleted file mode 100644 index 66eb23afe..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/lock/LockCurrentStateEnum.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.hapjava.characteristics.impl.lock; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Unsecured” 1 ”Secured” 2 ”Jammed” 3 ”Unknown” 4-255 ”Reserved” */ -public enum LockCurrentStateEnum implements CharacteristicEnum { - UNSECURED(0), - SECURED(1), - JAMMED(2), - UNKNOWN(3); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(LockCurrentStateEnum.values()) - .collect(Collectors.toMap(LockCurrentStateEnum::getCode, t -> t)); - } - - public static LockCurrentStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - LockCurrentStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/lock/LockTargetStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/lock/LockTargetStateCharacteristic.java deleted file mode 100644 index c46a4eab5..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/lock/LockTargetStateCharacteristic.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.hapjava.characteristics.impl.lock; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** The target state of the physical security mechanism (e.g. deadbolt). */ -public class LockTargetStateCharacteristic extends EnumCharacteristic { - - public LockTargetStateCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000001E-0000-1000-8000-0026BB765291", - "Target Lock State", - LockTargetStateEnum.values(), - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/lock/LockTargetStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/lock/LockTargetStateEnum.java deleted file mode 100644 index d5aa0d536..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/lock/LockTargetStateEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.lock; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Unsecured” 1 ”Secured” 4-255 ”Reserved” */ -public enum LockTargetStateEnum implements CharacteristicEnum { - UNSECURED(0), - SECURED(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(LockTargetStateEnum.values()) - .collect(Collectors.toMap(LockTargetStateEnum::getCode, t -> t)); - } - - public static LockTargetStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - LockTargetStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/motionsensor/MotionDetectedCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/motionsensor/MotionDetectedCharacteristic.java deleted file mode 100644 index 4be591bec..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/motionsensor/MotionDetectedCharacteristic.java +++ /dev/null @@ -1,25 +0,0 @@ -package io.github.hapjava.characteristics.impl.motionsensor; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.BooleanCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic indicates if motion (e.g. a person moving) was detected. */ -public class MotionDetectedCharacteristic extends BooleanCharacteristic { - - public MotionDetectedCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000022-0000-1000-8000-0026BB765291", - "Motion detection", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/occupancysensor/OccupancyDetectedCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/occupancysensor/OccupancyDetectedCharacteristic.java deleted file mode 100644 index 0057b0968..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/occupancysensor/OccupancyDetectedCharacteristic.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.characteristics.impl.occupancysensor; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic indicates if occupancy was detected (e.g. a person present). */ -public class OccupancyDetectedCharacteristic extends EnumCharacteristic { - - public OccupancyDetectedCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000071-0000-1000-8000-0026BB765291", - "Occupancy Detected", - OccupancyDetectedEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/occupancysensor/OccupancyDetectedEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/occupancysensor/OccupancyDetectedEnum.java deleted file mode 100644 index 688fa9d24..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/occupancysensor/OccupancyDetectedEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.occupancysensor; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Occupancy is not detected” 1 ”Occupancy is detected” */ -public enum OccupancyDetectedEnum implements CharacteristicEnum { - NOT_DETECTED(0), - DETECTED(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(OccupancyDetectedEnum.values()) - .collect(Collectors.toMap(OccupancyDetectedEnum::getCode, t -> t)); - } - - public static OccupancyDetectedEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - OccupancyDetectedEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/outlet/OutletInUseCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/outlet/OutletInUseCharacteristic.java deleted file mode 100644 index bd70f46f7..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/outlet/OutletInUseCharacteristic.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.hapjava.characteristics.impl.outlet; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.BooleanCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes if the power outlet has an appliance physically plugged in. This - * characteristic is set to True even if the plugged-in appliance is off. - */ -public class OutletInUseCharacteristic extends BooleanCharacteristic { - - public OutletInUseCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000026-0000-1000-8000-0026BB765291", - "Outlet in Use", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/CurrentSecuritySystemStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/CurrentSecuritySystemStateCharacteristic.java deleted file mode 100644 index 38ec2c3fd..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/CurrentSecuritySystemStateCharacteristic.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.hapjava.characteristics.impl.securitysystem; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the state of a security system */ -public class CurrentSecuritySystemStateCharacteristic - extends EnumCharacteristic { - - public CurrentSecuritySystemStateCharacteristic( - CurrentSecuritySystemStateEnum[] validValues, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000066-0000-1000-8000-0026BB765291", - "Current Security System State", - validValues, - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/CurrentSecuritySystemStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/CurrentSecuritySystemStateEnum.java deleted file mode 100644 index 90a66cf7e..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/CurrentSecuritySystemStateEnum.java +++ /dev/null @@ -1,52 +0,0 @@ -package io.github.hapjava.characteristics.impl.securitysystem; - -import io.github.hapjava.accessories.SecuritySystemAccessory; -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * The current state of a {@link SecuritySystemAccessory}. Unlike {@link - * TargetSecuritySystemStateEnum}, this enum includes a triggered state. 0 ”Stay Arm. The home is - * occupied and the residents are active. e.g. morning or evenings” 1 ”Away Arm. The home is - * unoccupied” 2 ”Night Arm. The home is occupied and the residents are sleeping” 3 ”Disarmed” 4 - * ”Alarm Triggered” 5-255 ”Reserved” - * - * @author Gaston Dombiak - */ -public enum CurrentSecuritySystemStateEnum implements CharacteristicEnum { - - /** The home is occupied and residents are active. */ - STAY_ARM(0), - /** The home is unoccupied. */ - AWAY_ARM(1), - /** The home is occupied and residents are sleeping. */ - NIGHT_ARM(2), - /** The security system is disarmed. */ - DISARMED(3), - /** The security system is triggered. */ - TRIGGERED(4); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(CurrentSecuritySystemStateEnum.values()) - .collect(Collectors.toMap(CurrentSecuritySystemStateEnum::getCode, t -> t)); - } - - public static CurrentSecuritySystemStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - CurrentSecuritySystemStateEnum(int code) { - this.code = code; - } - - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/SecuritySystemAlarmTypeCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/SecuritySystemAlarmTypeCharacteristic.java deleted file mode 100644 index 14c118399..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/SecuritySystemAlarmTypeCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.securitysystem; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes the type of alarm triggered by a security system. See {@link - * SecuritySystemAlarmTypeEnum} for possible values. - */ -public class SecuritySystemAlarmTypeCharacteristic - extends EnumCharacteristic { - - public SecuritySystemAlarmTypeCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000008E-0000-1000-8000-0026BB765291", - "Alert Type", - SecuritySystemAlarmTypeEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/SecuritySystemAlarmTypeEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/SecuritySystemAlarmTypeEnum.java deleted file mode 100644 index 00bc0f24e..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/SecuritySystemAlarmTypeEnum.java +++ /dev/null @@ -1,45 +0,0 @@ -package io.github.hapjava.characteristics.impl.securitysystem; - -import io.github.hapjava.accessories.SecuritySystemAccessory; -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * Type of alarm of a {@link SecuritySystemAccessory}. - * - *

This characteristic describes the type of alarm triggered by a security system. A value of 1 - * indicates an ʼunknownʼ cause. Value should revert to 0 when the alarm conditions are cleared. - * - * @author Gaston Dombiak - */ -public enum SecuritySystemAlarmTypeEnum implements CharacteristicEnum { - - /** Alarm conditions are cleared */ - NO_ALARM(0), - /** Alarm type is not known */ - UNKNOWN(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(SecuritySystemAlarmTypeEnum.values()) - .collect(Collectors.toMap(SecuritySystemAlarmTypeEnum::getCode, t -> t)); - } - - public static SecuritySystemAlarmTypeEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - SecuritySystemAlarmTypeEnum(int code) { - this.code = code; - } - - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/TargetSecuritySystemStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/TargetSecuritySystemStateCharacteristic.java deleted file mode 100644 index 5289ba380..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/TargetSecuritySystemStateCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.securitysystem; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the target state of the security system. */ -public class TargetSecuritySystemStateCharacteristic - extends EnumCharacteristic { - - public TargetSecuritySystemStateCharacteristic( - TargetSecuritySystemStateEnum[] validValues, - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000067-0000-1000-8000-0026BB765291", - "Target Security System State", - validValues, - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/TargetSecuritySystemStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/TargetSecuritySystemStateEnum.java deleted file mode 100644 index 81b0adc22..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/securitysystem/TargetSecuritySystemStateEnum.java +++ /dev/null @@ -1,50 +0,0 @@ -package io.github.hapjava.characteristics.impl.securitysystem; - -import io.github.hapjava.accessories.SecuritySystemAccessory; -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * The target state of a {@link SecuritySystemAccessory}. - * - *

0 ”Stay Arm. The home is occupied and the residents are active. e.g. morning or evenings” 1 - * ”Away Arm. The home is unoccupied” 2 ”Night Arm. The home is occupied and the residents are - * sleeping” 3 ”Disarm” 4-255 ”Reserved” - * - * @author Gaston Dombiak - */ -public enum TargetSecuritySystemStateEnum implements CharacteristicEnum { - - /** Arm the system when the home is occupied and residents are active. */ - STAY_ARM(0), - /** Arm the system when the home is unoccupied. */ - AWAY_ARM(1), - /** Arm the system when the home is occupied and residents are sleeping. */ - NIGHT_ARM(2), - /** Disarm the system. */ - DISARM(3); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(TargetSecuritySystemStateEnum.values()) - .collect(Collectors.toMap(TargetSecuritySystemStateEnum::getCode, t -> t)); - } - - public static TargetSecuritySystemStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - TargetSecuritySystemStateEnum(int code) { - this.code = code; - } - - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/slat/CurrentSlatStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/slat/CurrentSlatStateCharacteristic.java deleted file mode 100644 index 84e5e1daa..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/slat/CurrentSlatStateCharacteristic.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.characteristics.impl.slat; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the current state of the slats. */ -public class CurrentSlatStateCharacteristic extends EnumCharacteristic { - - public CurrentSlatStateCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000AA-0000-1000-8000-0026BB765291", - "current slat state", - CurrentSlatStateEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/slat/CurrentSlatStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/slat/CurrentSlatStateEnum.java deleted file mode 100644 index a94fd4d8e..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/slat/CurrentSlatStateEnum.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.hapjava.characteristics.impl.slat; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Fixed” 1 ”Jammed” 2 ”Swinging” */ -public enum CurrentSlatStateEnum implements CharacteristicEnum { - FIXED(0), - JAMMED(1), - SWINGING(2); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(CurrentSlatStateEnum.values()) - .collect(Collectors.toMap(CurrentSlatStateEnum::getCode, t -> t)); - } - - public static CurrentSlatStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - CurrentSlatStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/slat/CurrentTiltAngleCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/slat/CurrentTiltAngleCharacteristic.java deleted file mode 100644 index 3a4868b2c..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/slat/CurrentTiltAngleCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.slat; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describe current tilt angle (between -90 and 90) */ -public class CurrentTiltAngleCharacteristic extends IntegerCharacteristic - implements EventableCharacteristic { - - public CurrentTiltAngleCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000C1-0000-1000-8000-0026BB765291", - "current tilt angle", - -90, - 90, - "arcdegrees", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/slat/SlatTypeCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/slat/SlatTypeCharacteristic.java deleted file mode 100644 index 0d9f60608..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/slat/SlatTypeCharacteristic.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.github.hapjava.characteristics.impl.slat; - -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Supplier; - -/** - * This characteristic describes the type of the slats. See {@link SlatTypeEnum} for possible values - */ -public class SlatTypeCharacteristic extends EnumCharacteristic { - - public SlatTypeCharacteristic(Supplier> getter) { - super( - "000000C0-0000-1000-8000-0026BB765291", - "slat type", - SlatTypeEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/slat/SlatTypeEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/slat/SlatTypeEnum.java deleted file mode 100644 index 2634b0ef5..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/slat/SlatTypeEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.slat; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Horizontal” 1 ”Vertical” */ -public enum SlatTypeEnum implements CharacteristicEnum { - HORIZONTAL(0), - VERTICAL(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(SlatTypeEnum.values()) - .collect(Collectors.toMap(SlatTypeEnum::getCode, t -> t)); - } - - public static SlatTypeEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - SlatTypeEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/slat/TargetTiltAngleCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/slat/TargetTiltAngleCharacteristic.java deleted file mode 100644 index 2a327522d..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/slat/TargetTiltAngleCharacteristic.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.github.hapjava.characteristics.impl.slat; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the target angle of slats. */ -public class TargetTiltAngleCharacteristic extends IntegerCharacteristic - implements EventableCharacteristic { - - public TargetTiltAngleCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000C2-0000-1000-8000-0026BB765291", - "target tilt angle", - -90, - 90, - "arcdegrees", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/smokesensor/SmokeDetectedCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/smokesensor/SmokeDetectedCharacteristic.java deleted file mode 100644 index 9befabed0..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/smokesensor/SmokeDetectedCharacteristic.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.characteristics.impl.smokesensor; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic indicates if a sensor detects smoke. */ -public class SmokeDetectedCharacteristic extends EnumCharacteristic { - - public SmokeDetectedCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000076-0000-1000-8000-0026BB765291", - "Smoke Detected", - SmokeDetectedStateEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/smokesensor/SmokeDetectedStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/smokesensor/SmokeDetectedStateEnum.java deleted file mode 100644 index c6e3b6d5d..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/smokesensor/SmokeDetectedStateEnum.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.characteristics.impl.smokesensor; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Smoke is not detected” 1 ”Smoke is detected” */ -public enum SmokeDetectedStateEnum implements CharacteristicEnum { - NOT_DETECTED(0), - DETECTED(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(SmokeDetectedStateEnum.values()) - .collect(Collectors.toMap(SmokeDetectedStateEnum::getCode, t -> t)); - } - - public static SmokeDetectedStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - SmokeDetectedStateEnum(int code) { - this.code = code; - } - - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/television/ClosedCaptionsCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/television/ClosedCaptionsCharacteristic.java deleted file mode 100644 index a963ca222..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/television/ClosedCaptionsCharacteristic.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.hapjava.characteristics.impl.television; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * Characteristic indicates whether the service provides closed captions. See {@link - * ClosedCaptionsEnum} for possible values. - */ -public class ClosedCaptionsCharacteristic extends EnumCharacteristic { - - public ClosedCaptionsCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000DD-0000-1000-8000-0026BB765291", - "closed captions", - ClosedCaptionsEnum.values(), - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/television/ClosedCaptionsEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/television/ClosedCaptionsEnum.java deleted file mode 100644 index 2eb994149..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/television/ClosedCaptionsEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.television; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Disabled” 1 ”Enabled” 2-255 ”Reserved” */ -public enum ClosedCaptionsEnum implements CharacteristicEnum { - DISABLED(0), - ENABLED(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(ClosedCaptionsEnum.values()) - .collect(Collectors.toMap(ClosedCaptionsEnum::getCode, t -> t)); - } - - public static ClosedCaptionsEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - ClosedCaptionsEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/television/CurrentMediaStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/television/CurrentMediaStateCharacteristic.java deleted file mode 100644 index ca72c4ee9..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/television/CurrentMediaStateCharacteristic.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.hapjava.characteristics.impl.television; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic indicates current media state. See {@link CurrentMediaStateEnum} for possible - * values. - */ -public class CurrentMediaStateCharacteristic extends EnumCharacteristic { - public CurrentMediaStateCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000E0-0000-1000-8000-0026BB765291", - "current media state", - CurrentMediaStateEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/television/CurrentMediaStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/television/CurrentMediaStateEnum.java deleted file mode 100644 index 83836c4c6..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/television/CurrentMediaStateEnum.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.hapjava.characteristics.impl.television; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Play” 1 ”Pause” 2 "Stop" 3 "Unknown" 4-255 ”Reserved” */ -public enum CurrentMediaStateEnum implements CharacteristicEnum { - PLAY(0), - PAUSE(1), - STOP(2), - UNKNOWN(3); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(CurrentMediaStateEnum.values()) - .collect(Collectors.toMap(CurrentMediaStateEnum::getCode, t -> t)); - } - - public static CurrentMediaStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - CurrentMediaStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/television/PictureModeCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/television/PictureModeCharacteristic.java deleted file mode 100644 index 7efefa23a..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/television/PictureModeCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.television; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic retrieves / sets picture mode. See {@link PictureModeEnum} for possible - * values. - */ -public class PictureModeCharacteristic extends EnumCharacteristic { - public PictureModeCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000E2-0000-1000-8000-0026BB765291", - "picture mode", - PictureModeEnum.values(), - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/television/PictureModeEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/television/PictureModeEnum.java deleted file mode 100644 index ac387cf65..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/television/PictureModeEnum.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.github.hapjava.characteristics.impl.television; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * 0 ”Other” 1 ”Standard” 2 "Calibrated" 3 "CalibratedDark" 4 "Vivid" 5 "Game" 6 "Computer" 7 - * "Custom" 8-255 ”Reserved” - */ -public enum PictureModeEnum implements CharacteristicEnum { - OTHER(0), - STANDARD(1), - CALIBRATED(2), - CALIBRATED_DARK(3), - VIVID(4), - GAME(5), - COMPUTER(6), - CUSTOM(7); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(PictureModeEnum.values()) - .collect(Collectors.toMap(PictureModeEnum::getCode, t -> t)); - } - - public static PictureModeEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - PictureModeEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/television/PowerModeCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/television/PowerModeCharacteristic.java deleted file mode 100644 index cebbe4124..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/television/PowerModeCharacteristic.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.github.hapjava.characteristics.impl.television; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; - -/** characteristic sets power mode. See {@link PowerModeEnum} for possible values. */ -public class PowerModeCharacteristic extends EnumCharacteristic { - - public PowerModeCharacteristic(ExceptionalConsumer setter) { - super( - "000000DF-0000-1000-8000-0026BB765291", - "power mode selection", - PowerModeEnum.values(), - Optional.empty(), - Optional.of(setter), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/television/PowerModeEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/television/PowerModeEnum.java deleted file mode 100644 index a171ba135..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/television/PowerModeEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.television; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Show” 1 ”Hide” 2-255 ”Reserved” */ -public enum PowerModeEnum implements CharacteristicEnum { - SHOW(0), - HIDE(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(PowerModeEnum.values()) - .collect(Collectors.toMap(PowerModeEnum::getCode, t -> t)); - } - - public static PowerModeEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - PowerModeEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/television/RemoteKeyCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/television/RemoteKeyCharacteristic.java deleted file mode 100644 index fe028d10d..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/television/RemoteKeyCharacteristic.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.github.hapjava.characteristics.impl.television; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; - -/** - * This characteristic sends information about pressed key on tv remote. See {@link RemoteKeyEnum} - * for possible values. - */ -public class RemoteKeyCharacteristic extends EnumCharacteristic { - public RemoteKeyCharacteristic(ExceptionalConsumer setter) { - super( - "000000E1-0000-1000-8000-0026BB765291", - "remote key", - RemoteKeyEnum.values(), - Optional.empty(), - Optional.of(setter), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/television/RemoteKeyEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/television/RemoteKeyEnum.java deleted file mode 100644 index d62298b84..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/television/RemoteKeyEnum.java +++ /dev/null @@ -1,45 +0,0 @@ -package io.github.hapjava.characteristics.impl.television; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -public enum RemoteKeyEnum implements CharacteristicEnum { - REWIND(0), - FAST_FORWARD(1), - NEXT_TRACK(2), - PREV_TRACK(3), - ARROW_UP(4), - ARROW_DOWN(5), - ARROW_LEFT(6), - ARROW_RIGHT(7), - SELECT(8), - BACK(9), - EXIT(10), - PLAY_PAUSE(11), - INFO(15); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(RemoteKeyEnum.values()) - .collect(Collectors.toMap(RemoteKeyEnum::getCode, t -> t)); - } - - public static RemoteKeyEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - RemoteKeyEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/television/SleepDiscoveryModeCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/television/SleepDiscoveryModeCharacteristic.java deleted file mode 100644 index 2a7f41829..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/television/SleepDiscoveryModeCharacteristic.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.hapjava.characteristics.impl.television; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic indicates whether the service can be discovered. See {@link - * SleepDiscoveryModeEnum} for possible values. - */ -public class SleepDiscoveryModeCharacteristic extends EnumCharacteristic { - public SleepDiscoveryModeCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000E8-0000-1000-8000-0026BB765291", - "sleep discovery mode", - SleepDiscoveryModeEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/television/SleepDiscoveryModeEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/television/SleepDiscoveryModeEnum.java deleted file mode 100644 index da1377b9a..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/television/SleepDiscoveryModeEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.television; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Not discoverable” 1 ”Always discoverable” 2-255 ”Reserved” */ -public enum SleepDiscoveryModeEnum implements CharacteristicEnum { - NOT_DISCOVERABLE(0), - ALWAYS_DISCOVERABLE(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(SleepDiscoveryModeEnum.values()) - .collect(Collectors.toMap(SleepDiscoveryModeEnum::getCode, t -> t)); - } - - public static SleepDiscoveryModeEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - SleepDiscoveryModeEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/television/TargetMediaStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/television/TargetMediaStateCharacteristic.java deleted file mode 100644 index 8909bb1ea..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/television/TargetMediaStateCharacteristic.java +++ /dev/null @@ -1,27 +0,0 @@ -package io.github.hapjava.characteristics.impl.television; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic sets media state. See {@link TargetMediaStateEnum} for possible values. */ -public class TargetMediaStateCharacteristic extends EnumCharacteristic { - public TargetMediaStateCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000137-0000-1000-8000-0026BB765291", - "current media state", - TargetMediaStateEnum.values(), - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/television/TargetMediaStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/television/TargetMediaStateEnum.java deleted file mode 100644 index b6f6633ff..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/television/TargetMediaStateEnum.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.hapjava.characteristics.impl.television; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Play” 1 ”Pause” 2 "Stop" 3-255 ”Reserved” */ -public enum TargetMediaStateEnum implements CharacteristicEnum { - PLAY(0), - PAUSE(1), - STOP(2); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(TargetMediaStateEnum.values()) - .collect(Collectors.toMap(TargetMediaStateEnum::getCode, t -> t)); - } - - public static TargetMediaStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - TargetMediaStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/televisionspeaker/VolumeControlTypeCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/televisionspeaker/VolumeControlTypeCharacteristic.java deleted file mode 100644 index c6d18a858..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/televisionspeaker/VolumeControlTypeCharacteristic.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.hapjava.characteristics.impl.televisionspeaker; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic indicates volume control type. See {@link VolumeControlTypeEnum} for possible - * values. - */ -public class VolumeControlTypeCharacteristic extends EnumCharacteristic { - public VolumeControlTypeCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000E9-0000-1000-8000-0026BB765291", - "volume control type", - VolumeControlTypeEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/televisionspeaker/VolumeControlTypeEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/televisionspeaker/VolumeControlTypeEnum.java deleted file mode 100644 index dfeb24636..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/televisionspeaker/VolumeControlTypeEnum.java +++ /dev/null @@ -1,36 +0,0 @@ -package io.github.hapjava.characteristics.impl.televisionspeaker; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -public enum VolumeControlTypeEnum implements CharacteristicEnum { - NONE(0), - RELATIVE(1), - RELATIVE_WITH_CURRENT(2), - ABSOLUTE(3); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(VolumeControlTypeEnum.values()) - .collect(Collectors.toMap(VolumeControlTypeEnum::getCode, t -> t)); - } - - public static VolumeControlTypeEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - VolumeControlTypeEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/televisionspeaker/VolumeSelectorCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/televisionspeaker/VolumeSelectorCharacteristic.java deleted file mode 100644 index 8f2f84e7b..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/televisionspeaker/VolumeSelectorCharacteristic.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.github.hapjava.characteristics.impl.televisionspeaker; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; - -/** - * This characteristic sends information about volume changes. See {@link VolumeSelectorEnum} for - * possible values. - */ -public class VolumeSelectorCharacteristic extends EnumCharacteristic { - public VolumeSelectorCharacteristic(ExceptionalConsumer setter) { - super( - "000000EA-0000-1000-8000-0026BB765291", - "volume selector", - VolumeSelectorEnum.values(), - Optional.empty(), - Optional.of(setter), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/televisionspeaker/VolumeSelectorEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/televisionspeaker/VolumeSelectorEnum.java deleted file mode 100644 index 63bc60e50..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/televisionspeaker/VolumeSelectorEnum.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.characteristics.impl.televisionspeaker; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -public enum VolumeSelectorEnum implements CharacteristicEnum { - INCREMENT(0), - DECREMENT(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(VolumeSelectorEnum.values()) - .collect(Collectors.toMap(VolumeSelectorEnum::getCode, t -> t)); - } - - public static VolumeSelectorEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - VolumeSelectorEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/CoolingThresholdTemperatureCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/thermostat/CoolingThresholdTemperatureCharacteristic.java deleted file mode 100644 index d855f70d6..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/CoolingThresholdTemperatureCharacteristic.java +++ /dev/null @@ -1,54 +0,0 @@ -package io.github.hapjava.characteristics.impl.thermostat; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes the cooling threshold on which accessories turns on the cooling. - */ -public class CoolingThresholdTemperatureCharacteristic extends FloatCharacteristic { - public static final double DEFAULT_MIN_VALUE = 10; - public static final double DEFAULT_MAX_VALUE = 35; - public static final double DEFAULT_STEP = 0.1; - - public CoolingThresholdTemperatureCharacteristic( - double minValue, - double maxValue, - double step, - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000000D-0000-1000-8000-0026BB765291", - "cooling threshold", - minValue, - maxValue, - step, - "C", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public CoolingThresholdTemperatureCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - this( - DEFAULT_MIN_VALUE, - DEFAULT_MAX_VALUE, - DEFAULT_STEP, - getter, - setter, - subscriber, - unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/CurrentHeatingCoolingStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/thermostat/CurrentHeatingCoolingStateCharacteristic.java deleted file mode 100644 index 8c2600a69..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/CurrentHeatingCoolingStateCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.thermostat; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes the current mode of an accessory that supports cooling or heating - */ -public class CurrentHeatingCoolingStateCharacteristic - extends EnumCharacteristic { - - public CurrentHeatingCoolingStateCharacteristic( - CurrentHeatingCoolingStateEnum[] validValues, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000000F-0000-1000-8000-0026BB765291", - "Current heating cooling mode", - validValues, - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/CurrentHeatingCoolingStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/thermostat/CurrentHeatingCoolingStateEnum.java deleted file mode 100644 index 487262975..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/CurrentHeatingCoolingStateEnum.java +++ /dev/null @@ -1,35 +0,0 @@ -package io.github.hapjava.characteristics.impl.thermostat; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** 0 ”Off.” 1 ”Heat. The Heater is currently on.” 2 ”Cool. Cooler is currently on.” */ -public enum CurrentHeatingCoolingStateEnum implements CharacteristicEnum { - OFF(0), - HEAT(1), - COOL(2); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(CurrentHeatingCoolingStateEnum.values()) - .collect(Collectors.toMap(CurrentHeatingCoolingStateEnum::getCode, t -> t)); - } - - public static CurrentHeatingCoolingStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - CurrentHeatingCoolingStateEnum(int code) { - this.code = code; - } - - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/CurrentTemperatureCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/thermostat/CurrentTemperatureCharacteristic.java deleted file mode 100644 index f3c2b74ff..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/CurrentTemperatureCharacteristic.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.hapjava.characteristics.impl.thermostat; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** characteristic describes the current temperature of the environment in Celsius */ -public class CurrentTemperatureCharacteristic extends FloatCharacteristic { - public static final double DEFAULT_MIN_VALUE = 0; - public static final double DEFAULT_MAX_VALUE = 100; - public static final double DEFAULT_STEP = 0.1; - - public CurrentTemperatureCharacteristic( - double minValue, - double maxValue, - double minStep, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000011-0000-1000-8000-0026BB765291", - "current temperature", - minValue, - maxValue, - minStep, - "C", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public CurrentTemperatureCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, DEFAULT_STEP, getter, subscriber, unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/HeatingThresholdTemperatureCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/thermostat/HeatingThresholdTemperatureCharacteristic.java deleted file mode 100644 index 8d7624f8f..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/HeatingThresholdTemperatureCharacteristic.java +++ /dev/null @@ -1,52 +0,0 @@ -package io.github.hapjava.characteristics.impl.thermostat; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the heating threshold on which heating get turned on. */ -public class HeatingThresholdTemperatureCharacteristic extends FloatCharacteristic { - public static final double DEFAULT_MIN_VALUE = 0; - public static final double DEFAULT_MAX_VALUE = 25; - public static final double DEFAULT_STEP = 0.1; - - public HeatingThresholdTemperatureCharacteristic( - double minValue, - double maxValue, - double step, - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000012-0000-1000-8000-0026BB765291", - "heating threshold", - minValue, - maxValue, - step, - "C", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public HeatingThresholdTemperatureCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - this( - DEFAULT_MIN_VALUE, - DEFAULT_MAX_VALUE, - DEFAULT_STEP, - getter, - setter, - subscriber, - unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/TargetHeatingCoolingStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/thermostat/TargetHeatingCoolingStateCharacteristic.java deleted file mode 100644 index 844df0c67..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/TargetHeatingCoolingStateCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.thermostat; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the target mode of an accessory that supports heating/cooling, */ -public class TargetHeatingCoolingStateCharacteristic - extends EnumCharacteristic { - - public TargetHeatingCoolingStateCharacteristic( - TargetHeatingCoolingStateEnum[] validValues, - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000033-0000-1000-8000-0026BB765291", - "Target heating cooling mode", - validValues, - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/TargetHeatingCoolingStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/thermostat/TargetHeatingCoolingStateEnum.java deleted file mode 100644 index 6120422e5..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/TargetHeatingCoolingStateEnum.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.github.hapjava.characteristics.impl.thermostat; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * 0 ”Off” 1 ”Heat.” 2 ”Cool." 3 ”Auto. Turn on heating or cooling to maintain depending on the - * temperature” - * - * @author Andy Lintner - */ -public enum TargetHeatingCoolingStateEnum implements CharacteristicEnum { - OFF(0), - HEAT(1), - COOL(2), - AUTO(3); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(TargetHeatingCoolingStateEnum.values()) - .collect(Collectors.toMap(t -> t.getCode(), t -> t)); - } - - public static TargetHeatingCoolingStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - private TargetHeatingCoolingStateEnum(int code) { - this.code = code; - } - - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/TargetTemperatureCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/thermostat/TargetTemperatureCharacteristic.java deleted file mode 100644 index 9a329d383..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/TargetTemperatureCharacteristic.java +++ /dev/null @@ -1,55 +0,0 @@ -package io.github.hapjava.characteristics.impl.thermostat; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.FloatCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes the target temperature in Celsius that the accessory is actively - * attempting to reach. - */ -public class TargetTemperatureCharacteristic extends FloatCharacteristic { - public static final double DEFAULT_MIN_VALUE = 10; - public static final double DEFAULT_MAX_VALUE = 38; - public static final double DEFAULT_STEP = 0.1; - - public TargetTemperatureCharacteristic( - double minValue, - double maxValue, - double minStep, - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000035-0000-1000-8000-0026BB765291", - "target temperature", - minValue, - maxValue, - minStep, - "C", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public TargetTemperatureCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - this( - DEFAULT_MIN_VALUE, - DEFAULT_MAX_VALUE, - DEFAULT_STEP, - getter, - setter, - subscriber, - unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/TemperatureDisplayUnitCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/thermostat/TemperatureDisplayUnitCharacteristic.java deleted file mode 100644 index 02a23553f..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/TemperatureDisplayUnitCharacteristic.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.github.hapjava.characteristics.impl.thermostat; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes units of temperature used for presentation purposes (e.g. the units - * of temperature displayed on the screen). - */ -public class TemperatureDisplayUnitCharacteristic - extends EnumCharacteristic { - - public TemperatureDisplayUnitCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000036-0000-1000-8000-0026BB765291", - "Temperature units", - TemperatureDisplayUnitEnum.values(), - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/TemperatureDisplayUnitEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/thermostat/TemperatureDisplayUnitEnum.java deleted file mode 100644 index dbecc60f0..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/thermostat/TemperatureDisplayUnitEnum.java +++ /dev/null @@ -1,41 +0,0 @@ -package io.github.hapjava.characteristics.impl.thermostat; - -import io.github.hapjava.accessories.TemperatureSensorAccessory; -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * The temperature unit used by a {@link TemperatureSensorAccessory}. - * - *

0 ”Celsius” 1 ”Fahrenheit” - * - * @author Andy Lintner - */ -public enum TemperatureDisplayUnitEnum implements CharacteristicEnum { - CELSIUS(0), - FAHRENHEIT(1); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(TemperatureDisplayUnitEnum.values()) - .collect(Collectors.toMap(t -> t.getCode(), t -> t)); - } - - static TemperatureDisplayUnitEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - private TemperatureDisplayUnitEnum(int code) { - this.code = code; - } - - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/valve/RemainingDurationCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/valve/RemainingDurationCharacteristic.java deleted file mode 100644 index 828fafab1..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/valve/RemainingDurationCharacteristic.java +++ /dev/null @@ -1,45 +0,0 @@ -package io.github.hapjava.characteristics.impl.valve; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * This characteristic describes the remaining duration of the active status of an accessory, e.g. - * {@link io.github.hapjava.accessories.ValveAccessory}. This characteristic should only notify - * about changes if it defers from normal countdown. - */ -public class RemainingDurationCharacteristic extends IntegerCharacteristic - implements EventableCharacteristic { - public static final int DEFAULT_MIN_VALUE = 0; - public static final int DEFAULT_MAX_VALUE = 3600; - - public RemainingDurationCharacteristic( - int minValue, - int maxValue, - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000D4-0000-1000-8000-0026BB765291", - "remaining duration", - minValue, - maxValue, - "s", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public RemainingDurationCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, getter, subscriber, unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/valve/SetDurationCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/valve/SetDurationCharacteristic.java deleted file mode 100644 index 59cef5646..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/valve/SetDurationCharacteristic.java +++ /dev/null @@ -1,44 +0,0 @@ -package io.github.hapjava.characteristics.impl.valve; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the duration, how long an accessory should be set to "InUse". */ -public class SetDurationCharacteristic extends IntegerCharacteristic - implements EventableCharacteristic { - public static final int DEFAULT_MIN_VALUE = 0; - public static final int DEFAULT_MAX_VALUE = 3600; - - public SetDurationCharacteristic( - int minValue, - int maxValue, - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000D3-0000-1000-8000-0026BB765291", - "set duration", - minValue, - maxValue, - "s", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } - - public SetDurationCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - this(DEFAULT_MIN_VALUE, DEFAULT_MAX_VALUE, getter, setter, subscriber, unsubscriber); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/valve/ValveTypeCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/valve/ValveTypeCharacteristic.java deleted file mode 100644 index f98e468f4..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/valve/ValveTypeCharacteristic.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.characteristics.impl.valve; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the type of valve. */ -public class ValveTypeCharacteristic extends EnumCharacteristic { - - public ValveTypeCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "000000D5-0000-1000-8000-0026BB765291", - "Valve type", - ValveTypeEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/valve/ValveTypeEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/valve/ValveTypeEnum.java deleted file mode 100644 index d18d923e2..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/valve/ValveTypeEnum.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.hapjava.characteristics.impl.valve; - -import io.github.hapjava.accessories.ValveAccessory; -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * The mode used by a {@link ValveAccessory} - * - *

0 ”Generic valve” 1 ”Irrigation” 2 ”Shower head” 3 ”Water faucet” 4-255 ”Reserved” - * - * @author Tim Harper - */ -public enum ValveTypeEnum implements CharacteristicEnum { - GENERIC(0), - IRRIGATION(1), - SHOWER(2), - WATER_FAUCET(3); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(ValveTypeEnum.values()).collect(Collectors.toMap(t -> t.getCode(), t -> t)); - } - - public static ValveTypeEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - private ValveTypeEnum(int code) { - this.code = code; - } - - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/CurrentHorizontalTiltAngleCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/CurrentHorizontalTiltAngleCharacteristic.java deleted file mode 100644 index 1255d7eff..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/CurrentHorizontalTiltAngleCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.windowcovering; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the current angle of horizontal slats. */ -public class CurrentHorizontalTiltAngleCharacteristic extends IntegerCharacteristic - implements EventableCharacteristic { - - public CurrentHorizontalTiltAngleCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000006C-0000-1000-8000-0026BB765291", - "current horizontal tilt angle", - -90, - 90, - "arcdegrees", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/CurrentPositionCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/CurrentPositionCharacteristic.java deleted file mode 100644 index d51614615..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/CurrentPositionCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.windowcovering; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the current position of accessories. */ -public class CurrentPositionCharacteristic extends IntegerCharacteristic - implements EventableCharacteristic { - - public CurrentPositionCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000006D-0000-1000-8000-0026BB765291", - "current position", - 0, - 100, - "%", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/CurrentVerticalTiltAngleCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/CurrentVerticalTiltAngleCharacteristic.java deleted file mode 100644 index c6258a2db..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/CurrentVerticalTiltAngleCharacteristic.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.hapjava.characteristics.impl.windowcovering; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the current angle of vertical slats for accessory. */ -public class CurrentVerticalTiltAngleCharacteristic extends IntegerCharacteristic - implements EventableCharacteristic { - - public CurrentVerticalTiltAngleCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000006E-0000-1000-8000-0026BB765291", - "current vertical tilt angle", - -90, - 90, - "arcdegrees", - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/HoldPositionCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/HoldPositionCharacteristic.java deleted file mode 100644 index 7a6455919..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/HoldPositionCharacteristic.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.github.hapjava.characteristics.impl.windowcovering; - -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.impl.base.BooleanCharacteristic; -import java.util.Optional; - -/** This characteristic causes the accessories like window covering to stop at its current */ -public class HoldPositionCharacteristic extends BooleanCharacteristic { - - public HoldPositionCharacteristic(ExceptionalConsumer setter) { - super( - "0000006F-0000-1000-8000-0026BB765291", - "Hold Position", - Optional.empty(), - Optional.of(setter), - Optional.empty(), - Optional.empty()); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/PositionStateCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/PositionStateCharacteristic.java deleted file mode 100644 index 5b2488f52..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/PositionStateCharacteristic.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.characteristics.impl.windowcovering; - -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.EnumCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the state of the position of accessories. */ -public class PositionStateCharacteristic extends EnumCharacteristic { - - public PositionStateCharacteristic( - Supplier> getter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "00000072-0000-1000-8000-0026BB765291", - "Position state", - PositionStateEnum.values(), - Optional.of(getter), - Optional.empty(), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/PositionStateEnum.java b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/PositionStateEnum.java deleted file mode 100644 index 86b9174c8..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/PositionStateEnum.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.github.hapjava.characteristics.impl.windowcovering; - -import io.github.hapjava.characteristics.CharacteristicEnum; -import java.util.Arrays; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * 0 ”Going to the minimum value specified in metadata” 1 ”Going to the maximum value specified in - * metadata” 2 ”Stopped” - */ -public enum PositionStateEnum implements CharacteristicEnum { - DECREASING(0), - INCREASING(1), - STOPPED(2); - - private static final Map reverse; - - static { - reverse = - Arrays.stream(PositionStateEnum.values()) - .collect(Collectors.toMap(PositionStateEnum::getCode, t -> t)); - } - - public static PositionStateEnum fromCode(Integer code) { - return reverse.get(code); - } - - private final int code; - - PositionStateEnum(int code) { - this.code = code; - } - - @Override - public int getCode() { - return code; - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetHorizontalTiltAngleCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetHorizontalTiltAngleCharacteristic.java deleted file mode 100644 index 38c075760..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetHorizontalTiltAngleCharacteristic.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.github.hapjava.characteristics.impl.windowcovering; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the target angle of horizontal slats for accessories. */ -public class TargetHorizontalTiltAngleCharacteristic extends IntegerCharacteristic - implements EventableCharacteristic { - - public TargetHorizontalTiltAngleCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000007B-0000-1000-8000-0026BB765291", - "target horizontal tilt angle", - -90, - 90, - "arcdegrees", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetPositionCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetPositionCharacteristic.java deleted file mode 100644 index 6398a0b37..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetPositionCharacteristic.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.github.hapjava.characteristics.impl.windowcovering; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the target position of accessories like door, window, blinds. */ -public class TargetPositionCharacteristic extends IntegerCharacteristic - implements EventableCharacteristic { - - public TargetPositionCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000007C-0000-1000-8000-0026BB765291", - "target position", - 0, - 100, - "%", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetVerticalTiltAngleCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetVerticalTiltAngleCharacteristic.java deleted file mode 100644 index 4d7c3ad71..000000000 --- a/src/main/java/io/github/hapjava/characteristics/impl/windowcovering/TargetVerticalTiltAngleCharacteristic.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.github.hapjava.characteristics.impl.windowcovering; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.characteristics.ExceptionalConsumer; -import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback; -import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic; -import java.util.Optional; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** This characteristic describes the target angle of vertical slats. */ -public class TargetVerticalTiltAngleCharacteristic extends IntegerCharacteristic - implements EventableCharacteristic { - - public TargetVerticalTiltAngleCharacteristic( - Supplier> getter, - ExceptionalConsumer setter, - Consumer subscriber, - Runnable unsubscriber) { - super( - "0000007D-0000-1000-8000-0026BB765291", - "target vertical tilt angle", - -90, - 90, - "arcdegrees", - Optional.of(getter), - Optional.of(setter), - Optional.of(subscriber), - Optional.of(unsubscriber)); - } -} diff --git a/src/main/java/io/github/hapjava/characteristics/package-info.java b/src/main/java/io/github/hapjava/characteristics/package-info.java deleted file mode 100644 index 955ab73a7..000000000 --- a/src/main/java/io/github/hapjava/characteristics/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Contains the basic characteristic types that can be supplied over the HomeKit Accessory Protocol. - */ -package io.github.hapjava.characteristics; diff --git a/src/main/java/io/github/hapjava/server/HomekitAccessoryCategories.java b/src/main/java/io/github/hapjava/server/HomekitAccessoryCategories.java deleted file mode 100644 index 05768a947..000000000 --- a/src/main/java/io/github/hapjava/server/HomekitAccessoryCategories.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.github.hapjava.server; - -public final class HomekitAccessoryCategories { - public static final int OTHER = 1; - public static final int BRIDGES = 2; - public static final int FANS = 3; - public static final int GARAGE_DOOR_OPENERS = 4; - public static final int LIGHTING = 5; - public static final int LOCKS = 6; - public static final int OUTLETS = 7; - public static final int SWITCHES = 8; - public static final int THERMOSTATS = 9; - public static final int SENSORS = 10; - public static final int SECURITY_SYSTEMS = 11; - public static final int DOORS = 12; - public static final int WINDOWS = 13; - public static final int WINDOW_COVERINGS = 14; - public static final int PROGRAMMABLE_SWITCHES = 15; - public static final int RANGE_EXTENDER = 16; - public static final int IP_CAMERAS = 17; - public static final int VIDEO_DOORBELLS = 18; - public static final int AIR_PURIFIERS = 19; - public static final int HEATERS = 20; - public static final int AIR_CONDITIONERS = 21; - public static final int HUMIDIFIERS = 22; - public static final int DEHUMIDIFIERS = 23; - public static final int APPLE_TV = 24; - public static final int HOMEPOD = 25; - public static final int SPEAKER = 26; - public static final int AIRPORT = 27; - public static final int SPRINKLERS = 28; - public static final int FAUCETS = 29; - public static final int SHOWER_SYSTEMS = 30; - public static final int TELEVISION = 31; - public static final int REMOTES = 32; - public static final int ROUTER = 33; - public static final int AUDIO_RECEIVER = 34; - public static final int TV_SET_TOP_BOX = 35; - public static final int TV_STREAMING_STICK = 36; -} diff --git a/src/main/java/io/github/hapjava/server/HomekitAuthInfo.java b/src/main/java/io/github/hapjava/server/HomekitAuthInfo.java deleted file mode 100644 index 6441962d7..000000000 --- a/src/main/java/io/github/hapjava/server/HomekitAuthInfo.java +++ /dev/null @@ -1,136 +0,0 @@ -package io.github.hapjava.server; - -import io.github.hapjava.server.impl.HomekitServer; -import io.github.hapjava.server.impl.crypto.HAPSetupCodeUtils; -import java.math.BigInteger; -import java.util.Collection; -import java.util.List; - -/** - * Authentication info that must be provided when constructing a new {@link HomekitServer}. You will - * need to implement this interface yourself to provide the necessary callbacks to a persistent - * storage mechanism. All values provided must be constant across invocations or the accessories - * will require re-pairing within iOS. - * - * @author Andy Lintner - */ -public interface HomekitAuthInfo { - - /** - * A pin code used for pairing the device. This pin will be required within iOS in order to - * complete pairing. The numbers cannot be sequential and should not have a repeating pattern. - * - * @return the pin code, in the form ###-##-### - */ - String getPin(); - - /** - * A setup Id used for pairing the device using QR Code. It can be any alphanumeric combination of - * the length of 4. - * - * @return setup id - */ - default String getSetupId() { - return HAPSetupCodeUtils.generateSetupId(); - } - - /** - * A unique MAC address to be advertised with the HomeKit information. This does not have to be - * the MAC address of the network interface. You can generate this using {@link - * HomekitServer#generateMac()}. - * - * @return the unique MAC address. - */ - String getMac(); - - /** - * The Salt that will be used when hashing the pin code to send to the client. You should generate - * this using {@link HomekitServer#generateSalt()}. - * - * @return the Salt. - */ - BigInteger getSalt(); - - /** - * The private key used by the server during pairing and message encryption. You should generate - * this using {@link HomekitServer#generateKey()} - * - * @return the private key. - */ - byte[] getPrivateKey(); - - /** - * Called during the pairing process, you should store the user and public key in a manner that - * the public key can later be retrieved using {@link #getUserPublicKey(String)}. This must be - * stored in a persistent store as pairing will need to be reset if the information is lost. - * - * @param username the iOS device's username. The value will not be meaningful to anything but - * iOS. - * @param publicKey the iOS device's public key. - * @param isAdmin if the user is an admin, authorized to and/remove other users - */ - default void createUser(String username, byte[] publicKey, boolean isAdmin) { - createUser(username, publicKey); - } - - /** - * Deprecated method to add a user, assuming all users are admins. - * - *

At least one of the createUser methods must be implemented. - * - * @param username the iOS device's username. - * @param publicKey the iOS device's public key. - */ - default void createUser(String username, byte[] publicKey) { - createUser(username, publicKey, true); - } - - /** - * Called when an iOS device needs to remove an existing pairing. Subsequent calls to {@link - * #getUserPublicKey(String)} for this username return null. - * - * @param username the username to delete from the persistent store. - */ - void removeUser(String username); - - /** - * List all users which have been authenticated. - * - * @return the previously stored list of users. - */ - default Collection listUsers() { - return List.of(); - } - - /** - * Called when an already paired iOS device is re-connecting. The public key returned by this - * method will be compared with the signature of the pair verification request to validate the - * device. - * - * @param username the username of the iOS device to retrieve the public key for. - * @return the previously stored public key for this user. - */ - byte[] getUserPublicKey(String username); - - /** - * Determine if the specified user is an admin. - * - * @param username the username of the iOS device to retrieve permissions for. - * @return the previously stored permissions. - */ - default boolean userIsAdmin(String username) { - return true; - } - - /** - * Called to check if a user has been created. The homekit accessory advertises whether the - * accessory has already been paired. At this time, it's unclear whether multiple users can be - * created, however it is known that advertising as unpaired will break in iOS 9. The default - * value has been provided to maintain API compatibility for implementations targeting iOS 8. - * - * @return whether a user has been created and stored - */ - default boolean hasUser() { - return false; - }; -} diff --git a/src/main/java/io/github/hapjava/server/HomekitWebHandler.java b/src/main/java/io/github/hapjava/server/HomekitWebHandler.java deleted file mode 100644 index d66a843c4..000000000 --- a/src/main/java/io/github/hapjava/server/HomekitWebHandler.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.github.hapjava.server; - -import io.github.hapjava.server.impl.http.HomekitClientConnectionFactory; -import java.util.concurrent.CompletableFuture; - -public interface HomekitWebHandler { - - CompletableFuture start(HomekitClientConnectionFactory clientConnectionFactory); - - void stop(); - - void resetConnections(); -} diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitBridge.java b/src/main/java/io/github/hapjava/server/impl/HomekitBridge.java deleted file mode 100644 index 11efb0d37..000000000 --- a/src/main/java/io/github/hapjava/server/impl/HomekitBridge.java +++ /dev/null @@ -1,67 +0,0 @@ -package io.github.hapjava.server.impl; - -import io.github.hapjava.accessories.Bridge; -import io.github.hapjava.services.Service; -import java.util.Collection; -import java.util.Collections; -import java.util.concurrent.CompletableFuture; - -public class HomekitBridge implements Bridge { - - private final String label; - private final String serialNumber; - private final String model; - private final String manufacturer; - private final String firmwareRevision; - private final String hardwareRevision; - - public HomekitBridge( - String label, - String serialNumber, - String model, - String manufacturer, - String firmwareRevision, - String hardwareRevision) { - this.label = label; - this.serialNumber = serialNumber; - this.model = model; - this.manufacturer = manufacturer; - this.firmwareRevision = firmwareRevision; - this.hardwareRevision = hardwareRevision; - } - - @Override - public CompletableFuture getName() { - return CompletableFuture.completedFuture(label); - } - - @Override - public CompletableFuture getSerialNumber() { - return CompletableFuture.completedFuture(serialNumber); - } - - @Override - public CompletableFuture getModel() { - return CompletableFuture.completedFuture(model); - } - - @Override - public CompletableFuture getManufacturer() { - return CompletableFuture.completedFuture(manufacturer); - } - - @Override - public CompletableFuture getFirmwareRevision() { - return CompletableFuture.completedFuture(firmwareRevision); - } - - @Override - public Collection getServices() { - return Collections.emptyList(); - } - - @Override - public int getId() { - return 1; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java b/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java deleted file mode 100644 index 3c70cfb9e..000000000 --- a/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java +++ /dev/null @@ -1,109 +0,0 @@ -package io.github.hapjava.server.impl; - -import io.github.hapjava.accessories.HomekitAccessory; -import io.github.hapjava.characteristics.Characteristic; -import io.github.hapjava.server.impl.connections.SubscriptionManager; -import io.github.hapjava.services.Service; -import io.github.hapjava.services.impl.AccessoryInformationService; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class HomekitRegistry { - - private static final Logger logger = LoggerFactory.getLogger(HomekitRegistry.class); - - private final String label; - private final SubscriptionManager subscriptions; - private final Map accessories; - private final Map> services = new HashMap<>(); - private final Map> characteristics = - new HashMap<>(); - private boolean isAllowUnauthenticatedRequests = false; - - public HomekitRegistry(String label, SubscriptionManager subscriptions) { - this.label = label; - this.subscriptions = subscriptions; - this.accessories = new ConcurrentHashMap<>(); - reset(); - } - - public synchronized void reset() { - characteristics.clear(); - services.clear(); - for (HomekitAccessory accessory : accessories.values()) { - int iid = 0; - List newServices; - try { - newServices = new ArrayList<>(2); - Collection services = accessory.getServices(); - if (!services.stream() - .anyMatch(s -> s.getType().equals(AccessoryInformationService.TYPE))) { - newServices.add(new AccessoryInformationService(accessory)); - } - for (Service service : services) { - newServices.add(service); - newServices.addAll(service.getLinkedServices()); - } - } catch (Exception e) { - logger.warn("Could not instantiate services for accessory " + accessory.getName(), e); - services.put(accessory, Collections.emptyMap()); - continue; - } - - Map newCharacteristicsByInterfaceId = new HashMap<>(); - Map newServicesByInterfaceId = new HashMap<>(); - for (Service service : newServices) { - newServicesByInterfaceId.put(++iid, service); - for (Characteristic characteristic : service.getCharacteristics()) { - newCharacteristicsByInterfaceId.put(++iid, characteristic); - } - } - services.put(accessory, newServicesByInterfaceId); - characteristics.put(accessory, newCharacteristicsByInterfaceId); - } - subscriptions.resync(this); - } - - public String getLabel() { - return label; - } - - public Collection getAccessories() { - return accessories.values(); - } - - public Map getServices(Integer aid) { - return Collections.unmodifiableMap(services.get(accessories.get(aid))); - } - - public Map getCharacteristics(Integer aid) { - Map characteristics = this.characteristics.get(accessories.get(aid)); - if (characteristics == null) { - return Collections.emptyMap(); - } - return Collections.unmodifiableMap(characteristics); - } - - public void add(HomekitAccessory accessory) { - accessories.put(accessory.getId(), accessory); - } - - public boolean remove(HomekitAccessory accessory) { - return accessories.remove(accessory.getId()) != null; - } - - public boolean isAllowUnauthenticatedRequests() { - return isAllowUnauthenticatedRequests; - } - - public void setAllowUnauthenticatedRequests(boolean allow) { - this.isAllowUnauthenticatedRequests = allow; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitRoot.java b/src/main/java/io/github/hapjava/server/impl/HomekitRoot.java deleted file mode 100644 index 36bfeefa2..000000000 --- a/src/main/java/io/github/hapjava/server/impl/HomekitRoot.java +++ /dev/null @@ -1,238 +0,0 @@ -package io.github.hapjava.server.impl; - -import io.github.hapjava.accessories.Bridge; -import io.github.hapjava.accessories.HomekitAccessory; -import io.github.hapjava.server.HomekitAccessoryCategories; -import io.github.hapjava.server.HomekitAuthInfo; -import io.github.hapjava.server.HomekitWebHandler; -import io.github.hapjava.server.impl.connections.HomekitClientConnectionFactoryImpl; -import io.github.hapjava.server.impl.connections.SubscriptionManager; -import io.github.hapjava.server.impl.jmdns.JmdnsHomekitAdvertiser; -import java.io.IOException; -import java.net.InetAddress; -import javax.jmdns.JmDNS; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Provides advertising and handling for HomeKit accessories. This class handles the advertising of - * HomeKit accessories and contains one or more accessories. When implementing a bridge accessory, - * you will interact with this class directly. Instantiate it via {@link - * HomekitServer#createBridge(HomekitAuthInfo, String, String, String, String, String, String)}. For - * single accessories, this is composed by {@link HomekitStandaloneAccessoryServer}. - * - * @author Andy Lintner - */ -public class HomekitRoot { - - private static final Logger logger = LoggerFactory.getLogger(HomekitRoot.class); - private static final int DEFAULT_ACCESSORY_CATEGORY = HomekitAccessoryCategories.OTHER; - private final JmdnsHomekitAdvertiser advertiser; - private final HomekitWebHandler webHandler; - private final HomekitAuthInfo authInfo; - private final String label; - private final int category; - private final HomekitRegistry registry; - private final SubscriptionManager subscriptions = new SubscriptionManager(); - private boolean started = false; - private int configurationIndex = 1; - private int nestedBatches = 0; - private boolean madeChanges = false; - - HomekitRoot( - String label, HomekitWebHandler webHandler, InetAddress host, HomekitAuthInfo authInfo) - throws IOException { - this(label, DEFAULT_ACCESSORY_CATEGORY, webHandler, authInfo, new JmdnsHomekitAdvertiser(host)); - } - - HomekitRoot( - String label, - int category, - HomekitWebHandler webHandler, - InetAddress host, - HomekitAuthInfo authInfo) - throws IOException { - this(label, category, webHandler, authInfo, new JmdnsHomekitAdvertiser(host)); - } - - HomekitRoot( - String label, - int category, - HomekitWebHandler webHandler, - HomekitAuthInfo authInfo, - JmdnsHomekitAdvertiser advertiser) - throws IOException { - this.advertiser = advertiser; - this.webHandler = webHandler; - this.authInfo = authInfo; - this.label = label; - this.category = category; - this.registry = new HomekitRegistry(label, subscriptions); - } - - HomekitRoot( - String label, - int category, - HomekitWebHandler webHandler, - JmDNS jmdns, - HomekitAuthInfo authInfo) - throws IOException { - this(label, category, webHandler, authInfo, new JmdnsHomekitAdvertiser(jmdns)); - } - - HomekitRoot(String label, HomekitWebHandler webHandler, JmDNS jmdns, HomekitAuthInfo authInfo) - throws IOException { - this( - label, DEFAULT_ACCESSORY_CATEGORY, webHandler, authInfo, new JmdnsHomekitAdvertiser(jmdns)); - } - - /** - * Begin a batch update of accessories. - * - *

After calling this, you can call addAccessory() and removeAccessory() multiple times without - * causing HAP-Java to re-publishing the metadata to HomeKit. You'll need to call - * completeUpdateBatch in order to publish all accumulated changes. - */ - public synchronized void batchUpdate() { - if (this.nestedBatches == 0) madeChanges = false; - ++this.nestedBatches; - } - - /** Publish accumulated accessory changes since batchUpdate() was called. */ - public synchronized void completeUpdateBatch() { - if (--this.nestedBatches == 0 && madeChanges) registry.reset(); - } - - /** - * Add an accessory to be handled and advertised by this root. When using this for a bridge, the - * ID of the accessory must be greater than 1, as that ID is reserved for the Bridge itself. - * - * @param accessory to advertise and handle. - */ - public void addAccessory(HomekitAccessory accessory) { - if (accessory.getId() <= 1 && !(accessory instanceof Bridge)) { - throw new IndexOutOfBoundsException( - "The ID of an accessory used in a bridge must be greater than 1"); - } - addAccessorySkipRangeCheck(accessory); - } - - /** - * Skips the range check. Used by {@link HomekitStandaloneAccessoryServer} as well as {@link - * #addAccessory(HomekitAccessory)}; - * - * @param accessory to advertise and handle. - */ - void addAccessorySkipRangeCheck(HomekitAccessory accessory) { - this.registry.add(accessory); - if (logger.isTraceEnabled()) { - accessory.getName().thenAccept(name -> logger.trace("Added accessory {}", name)); - } - madeChanges = true; - if (started && nestedBatches == 0) { - registry.reset(); - } - } - - /** - * Removes an accessory from being handled or advertised by this root. - * - * @param accessory accessory to cease advertising and handling - */ - public void removeAccessory(HomekitAccessory accessory) { - if (this.registry.remove(accessory)) { - if (logger.isTraceEnabled()) { - accessory.getName().thenAccept(name -> logger.trace("Removed accessory {}", name)); - } - madeChanges = true; - if (started && nestedBatches == 0) { - registry.reset(); - } - } else { - accessory.getName().thenAccept(name -> logger.warn("Could not remove accessory {}", name)); - } - } - - /** - * Starts advertising and handling the previously added HomeKit accessories. You should try to - * call this after you have used the {@link #addAccessory(HomekitAccessory)} method to add all the - * initial accessories you plan on advertising, as any later additions will cause the HomeKit - * clients to reconnect. - */ - public void start() { - started = true; - madeChanges = false; - registry.reset(); - webHandler - .start( - new HomekitClientConnectionFactoryImpl(authInfo, registry, subscriptions, advertiser)) - .thenAccept( - port -> { - try { - refreshAuthInfo(); - advertiser.advertise( - label, - category, - authInfo.getMac(), - port, - configurationIndex, - authInfo.getSetupId()); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); - } - - /** Stops advertising and handling the HomeKit accessories. */ - public void stop() { - advertiser.stop(); - webHandler.stop(); - subscriptions.removeAll(); - started = false; - } - - /** - * Refreshes auth info after it has been changed outside this library - * - * @throws IOException if there is an error in the underlying protocol, such as a TCP error - */ - public void refreshAuthInfo() throws IOException { - advertiser.setMac(authInfo.getMac()); - advertiser.setDiscoverable(!authInfo.hasUser()); - } - - /** - * By default, most homekit requests require that the client be paired. Allowing unauthenticated - * requests can be useful for debugging, but should not be used in production. - * - * @param allow whether to allow unauthenticated requests - */ - public void allowUnauthenticatedRequests(boolean allow) { - registry.setAllowUnauthenticatedRequests(allow); - } - - /** - * By default, the bridge advertises itself at revision 1. If you make changes to the accessories - * you're including in the bridge after your first call to {@link start()}, you should increment - * this number. The behavior of the client if the configuration index were to decrement is - * undefined, so this implementation will not manage the configuration index by automatically - * incrementing - preserving this state across invocations should be handled externally. - * - * @param revision an integer, greater than or equal to one, indicating the revision of the - * accessory information - * @throws IOException if there is an error in the underlying protocol, such as a TCP error - */ - public void setConfigurationIndex(int revision) throws IOException { - if (revision < 1) { - throw new IllegalArgumentException("revision must be greater than or equal to 1"); - } - this.configurationIndex = revision; - if (this.started) { - advertiser.setConfigurationIndex(revision); - } - } - - HomekitRegistry getRegistry() { - return registry; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitServer.java b/src/main/java/io/github/hapjava/server/impl/HomekitServer.java deleted file mode 100644 index 7728896a2..000000000 --- a/src/main/java/io/github/hapjava/server/impl/HomekitServer.java +++ /dev/null @@ -1,218 +0,0 @@ -package io.github.hapjava.server.impl; - -import io.github.hapjava.accessories.HomekitAccessory; -import io.github.hapjava.server.HomekitAuthInfo; -import io.github.hapjava.server.impl.http.impl.HomekitHttpServer; -import java.io.IOException; -import java.math.BigInteger; -import java.net.InetAddress; -import java.security.InvalidAlgorithmParameterException; -import java.util.concurrent.ExecutionException; -import javax.jmdns.JmDNS; - -/** - * The main entry point for hap-java. Creating an instance of this class will listen for HomeKit - * connections on the supplied port. Only a single root accessory can be added for each unique - * instance and port, however, that accessory may be a {@link #createBridge(HomekitAuthInfo, String, - * String, String, String, String, String) bridge accessory} containing child accessories. - * - *

The {@link HomekitAuthInfo HomekitAuthInfo} argument when creating accessories should be an - * implementation supplied by your application. Several of the values needed for your implementation - * are provided by this class, specifically {@link #generateKey() generateKey}, {@link - * #generateMac() generateMac}, and {@link #generateSalt()}. It is important that you provide these - * same values on each start of your application or HomeKit will fail to recognize your device as - * being the same. - * - * @author Andy Lintner - */ -public class HomekitServer { - - private final HomekitHttpServer http; - private final InetAddress localAddress; - private final JmDNS jmdns; - - /** - * Constructor. Contains an argument indicating the number of threads to use in the http server. - * The other constructors default this to the number of available processors, however you may - * increase this in an environment with many users and/or blocking accessory implementations. - * - * @param localAddress local address to bind to. - * @param port local port to bind to. - * @param nThreads number of threads to use in the http server - * @throws IOException when the server cannot bind to the supplied port - */ - public HomekitServer(InetAddress localAddress, int port, int nThreads) throws IOException { - this.localAddress = localAddress; - this.jmdns = null; - http = new HomekitHttpServer(localAddress, port, nThreads); - } - - /** - * Constructor - * - * @param jmdns mdns service to register with - * @param port local port to bind to - * @param nThreads number of threads to use in the http server - * @throws IOException when the server cannot bind to the supplied port - */ - public HomekitServer(JmDNS jmdns, int port, int nThreads) throws IOException { - this.jmdns = jmdns; - this.localAddress = null; - http = new HomekitHttpServer(jmdns.getInetAddress(), port, nThreads); - } - - /** - * Constructor - * - * @param localAddress local address to bind to - * @param port local port to bind to - * @throws IOException when the server cannot bind to the supplied port - */ - public HomekitServer(InetAddress localAddress, int port) throws IOException { - this(localAddress, port, Runtime.getRuntime().availableProcessors()); - } - - /** - * Constructor - * - * @param jmdns mdns service to register with - * @param port local port to bind to - * @throws IOException when the server cannot bind to the supplied port - */ - public HomekitServer(JmDNS jmdns, int port) throws IOException { - this(jmdns, port, Runtime.getRuntime().availableProcessors()); - } - /** - * Constructor - * - * @param port local port to bind to. - * @throws IOException when the server cannot bind to the supplied port - */ - public HomekitServer(int port) throws IOException { - this(InetAddress.getLocalHost(), port); - } - - /** Stops the service, closing down existing connections and preventing new ones. */ - public void stop() { - http.stop(); - } - - /** - * Creates a single (non-bridge) accessory - * - * @param authInfo authentication information for this accessory. These values should be persisted - * and re-supplied on re-start of your application. - * @param accessory accessory implementation. This will usually be an implementation of an - * interface in {#link io.github.hapjava.accessories io.github.hapjava.accessories}. - * @return the newly created server. Call {@link HomekitStandaloneAccessoryServer#start start} on - * this to begin. - * @throws IOException when mDNS cannot connect to the network - */ - public HomekitStandaloneAccessoryServer createStandaloneAccessory( - HomekitAuthInfo authInfo, HomekitAccessory accessory) - throws IOException, ExecutionException, InterruptedException { - if (jmdns != null) { - return new HomekitStandaloneAccessoryServer(accessory, http, jmdns, authInfo); - } else { - return new HomekitStandaloneAccessoryServer(accessory, http, localAddress, authInfo); - } - } - - public HomekitStandaloneAccessoryServer createStandaloneAccessory( - HomekitAuthInfo authInfo, HomekitAccessory accessory, int category) - throws IOException, ExecutionException, InterruptedException { - if (jmdns != null) { - return new HomekitStandaloneAccessoryServer(accessory, http, jmdns, authInfo, category); - } else { - return new HomekitStandaloneAccessoryServer( - accessory, http, localAddress, authInfo, category); - } - } - - /** - * Creates a bridge accessory, capable of holding multiple child accessories. This has the - * advantage over multiple standalone accessories of only requiring a single pairing from iOS for - * the bridge. - * - * @param authInfo authentication information for this accessory. These values should be persisted - * and re-supplied on re-start of your application. - * @param label label for the bridge. This will show in iOS during pairing. - * @param manufacturer manufacturer of the bridge. This information is exposed to iOS for unknown - * purposes. - * @param model model of the bridge. This is also exposed to iOS for unknown purposes. - * @param serialNumber serial number of the bridge. Also exposed. Purposes also unknown. - * @param firmwareRevision firmware revision of the bridge. - * @param hardwareRevision hardware revision of the brigde. - * @return the bridge, from which you can {@link HomekitRoot#addAccessory add accessories} and - * then {@link HomekitRoot#start start} handling requests. - * @throws IOException when mDNS cannot connect to the network - */ - public HomekitRoot createBridge( - HomekitAuthInfo authInfo, - String label, - int category, - String manufacturer, - String model, - String serialNumber, - String firmwareRevision, - String hardwareRevision) - throws IOException { - HomekitRoot root; - if (jmdns != null) { - root = new HomekitRoot(label, category, http, jmdns, authInfo); - } else { - root = new HomekitRoot(label, category, http, localAddress, authInfo); - } - root.addAccessory( - new HomekitBridge( - label, serialNumber, model, manufacturer, firmwareRevision, hardwareRevision)); - return root; - } - - /** - * Generates a value to supply in {@link HomekitAuthInfo#getSalt() HomekitAuthInfo.getSalt()}. - * This is used to salt the pin-code. You don't need to worry about that though - the salting is - * done on the plaintext pin. (Yes, plaintext passwords are bad. Please don't secure your nuclear - * storage facility with this implementation) - * - * @return the generated salt - */ - public static BigInteger generateSalt() { - return HomekitUtils.generateSalt(); - } - - /** - * Generates a value to supply in {@link HomekitAuthInfo#getPrivateKey() - * HomekitAuthInfo.getPrivKey()}. This is used as the private key during pairing and connection - * setup. - * - * @return the generated key - * @throws InvalidAlgorithmParameterException if the JVM does not contain the necessary encryption - * algorithms. - */ - public static byte[] generateKey() throws InvalidAlgorithmParameterException { - return HomekitUtils.generateKey(); - } - - /** - * Generates a value to supply in {@link HomekitAuthInfo#getMac() HomekitAuthInfo.getMac()}. This - * is used as the unique identifier of the accessory during mDNS advertising. It is a valid MAC - * address generated in the locally administered range so as not to conflict with any commercial - * devices. - * - * @return the generated MAC - */ - public static String generateMac() { - return HomekitUtils.generateMac(); - } - - /** - * Generates a value to supply in {@link HomekitAuthInfo#getPin() HomekitAuthInfo.getPin()}. This - * is used as the Pin a user enters into their HomeKit device in order to confirm pairing. - * - * @return the generated Pin - */ - public static String generatePin() { - return HomekitUtils.generatePin(); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitStandaloneAccessoryServer.java b/src/main/java/io/github/hapjava/server/impl/HomekitStandaloneAccessoryServer.java deleted file mode 100644 index 4a5dbabee..000000000 --- a/src/main/java/io/github/hapjava/server/impl/HomekitStandaloneAccessoryServer.java +++ /dev/null @@ -1,70 +0,0 @@ -package io.github.hapjava.server.impl; - -import io.github.hapjava.accessories.HomekitAccessory; -import io.github.hapjava.server.HomekitAuthInfo; -import io.github.hapjava.server.HomekitWebHandler; -import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.concurrent.ExecutionException; -import javax.jmdns.JmDNS; - -/** - * A server for exposing standalone HomeKit accessory (as opposed to a Bridge accessory which - * contains multiple accessories). Each standalone accessory will have its own pairing information, - * port, and pin. Instantiate this class via {@link - * HomekitServer#createStandaloneAccessory(HomekitAuthInfo, HomekitAccessory)}. - * - * @author Andy Lintner - */ -public class HomekitStandaloneAccessoryServer { - - private final HomekitRoot root; - - HomekitStandaloneAccessoryServer( - HomekitAccessory accessory, - HomekitWebHandler webHandler, - InetAddress localhost, - HomekitAuthInfo authInfo) - throws UnknownHostException, IOException, ExecutionException, InterruptedException { - root = new HomekitRoot(accessory.getName().get(), webHandler, localhost, authInfo); - root.addAccessory(accessory); - } - - HomekitStandaloneAccessoryServer( - HomekitAccessory accessory, - HomekitWebHandler webHandler, - JmDNS jmdns, - HomekitAuthInfo authInfo) - throws UnknownHostException, IOException, ExecutionException, InterruptedException { - root = new HomekitRoot(accessory.getName().get(), webHandler, jmdns, authInfo); - root.addAccessory(accessory); - } - - HomekitStandaloneAccessoryServer( - HomekitAccessory accessory, - HomekitWebHandler webHandler, - InetAddress localhost, - HomekitAuthInfo authInfo, - int category) - throws UnknownHostException, IOException, ExecutionException, InterruptedException { - root = new HomekitRoot(accessory.getName().get(), category, webHandler, localhost, authInfo); - root.addAccessory(accessory); - } - - HomekitStandaloneAccessoryServer( - HomekitAccessory accessory, - HomekitWebHandler webHandler, - JmDNS jmdns, - HomekitAuthInfo authInfo, - int category) - throws UnknownHostException, IOException, ExecutionException, InterruptedException { - root = new HomekitRoot(accessory.getName().get(), category, webHandler, jmdns, authInfo); - root.addAccessory(accessory); - } - - /** Begins advertising and handling requests for this accessory. */ - public void start() { - root.start(); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitUtils.java b/src/main/java/io/github/hapjava/server/impl/HomekitUtils.java deleted file mode 100644 index 9b5b2b8ee..000000000 --- a/src/main/java/io/github/hapjava/server/impl/HomekitUtils.java +++ /dev/null @@ -1,75 +0,0 @@ -package io.github.hapjava.server.impl; - -import com.nimbusds.srp6.SRP6Routines; -import java.math.BigInteger; -import java.security.InvalidAlgorithmParameterException; -import java.security.SecureRandom; -import java.util.stream.Collectors; -import java.util.stream.Stream; -import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable; -import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec; - -public class HomekitUtils { - - private static volatile SecureRandom secureRandom; - - public static BigInteger generateSalt() { - return new BigInteger(SRP6Routines.generateRandomSalt(16)); - } - - public static byte[] generateKey() throws InvalidAlgorithmParameterException { - EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName("ed25519-sha-512"); - byte[] seed = new byte[spec.getCurve().getField().getb() / 8]; - getSecureRandom().nextBytes(seed); - return seed; - } - - public static String generateMac() { - int byte1 = - ((getSecureRandom().nextInt(255) + 1) | 2) & 0xFE; // Unicast locally administered MAC; - return Integer.toHexString(byte1) - + ":" - + Stream.generate(() -> getSecureRandom().nextInt(255) + 1) - .limit(5) - .map(i -> Integer.toHexString(i)) - .collect(Collectors.joining(":")); - } - - public static String generatePin() { - String pin = - String.format( - "%03d-%02d-%03d", - getSecureRandom().nextInt(1000), - getSecureRandom().nextInt(100), - getSecureRandom().nextInt(1000)); - - if (pin == "000-00-000" - || pin == "111-11-111" - || pin == "222-22-222" - || pin == "333-33-333" - || pin == "444-44-444" - || pin == "555-55-555" - || pin == "666-66-666" - || pin == "777-77-777" - || pin == "888-88-888" - || pin == "999-99-999" - || pin == "123-45-678" - || pin == "876-54-321") { - // disallowed Pin; just recurse and generate a new one - return generatePin(); - } - - return pin; - } - - private static SecureRandom getSecureRandom() { - if (secureRandom == null) { - synchronized (HomekitUtils.class) { - if (secureRandom == null) { - secureRandom = new SecureRandom(); - } - } - } - return secureRandom; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/connections/ConnectionImpl.java b/src/main/java/io/github/hapjava/server/impl/connections/ConnectionImpl.java deleted file mode 100644 index 759506722..000000000 --- a/src/main/java/io/github/hapjava/server/impl/connections/ConnectionImpl.java +++ /dev/null @@ -1,155 +0,0 @@ -package io.github.hapjava.server.impl.connections; - -import io.github.hapjava.server.HomekitAuthInfo; -import io.github.hapjava.server.impl.HomekitRegistry; -import io.github.hapjava.server.impl.crypto.ChachaDecoder; -import io.github.hapjava.server.impl.crypto.ChachaEncoder; -import io.github.hapjava.server.impl.http.HomekitClientConnection; -import io.github.hapjava.server.impl.http.HttpRequest; -import io.github.hapjava.server.impl.http.HttpResponse; -import io.github.hapjava.server.impl.jmdns.JmdnsHomekitAdvertiser; -import io.github.hapjava.server.impl.pairing.UpgradeResponse; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.util.Collection; -import java.util.function.Consumer; -import org.bouncycastle.util.Pack; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -class ConnectionImpl implements HomekitClientConnection { - - private final HttpSession httpSession; - private LengthPrefixedByteArrayProcessor binaryProcessor; - private int inboundBinaryMessageCount = 0; - private int outboundBinaryMessageCount = 0; - private byte[] readKey; - private byte[] writeKey; - private String username; - private boolean isUpgraded = false; - private final Consumer outOfBandMessageCallback; - private final SubscriptionManager subscriptions; - - private static final Logger LOGGER = LoggerFactory.getLogger(HomekitClientConnection.class); - - public ConnectionImpl( - HomekitAuthInfo authInfo, - HomekitRegistry registry, - Consumer outOfBandMessageCallback, - SubscriptionManager subscriptions, - JmdnsHomekitAdvertiser advertiser) { - httpSession = new HttpSession(authInfo, registry, subscriptions, this, advertiser); - this.outOfBandMessageCallback = outOfBandMessageCallback; - this.subscriptions = subscriptions; - } - - @Override - public synchronized HttpResponse handleRequest(HttpRequest request) throws IOException { - return doHandleRequest(request); - } - - private HttpResponse doHandleRequest(HttpRequest request) throws IOException { - HttpResponse response = - isUpgraded - ? httpSession.handleAuthenticatedRequest(request) - : httpSession.handleRequest(request); - if (response instanceof UpgradeResponse) { - isUpgraded = true; - readKey = ((UpgradeResponse) response).getReadKey().array(); - writeKey = ((UpgradeResponse) response).getWriteKey().array(); - username = ((UpgradeResponse) response).getUsername(); - } - LOGGER.trace("{} {} {}", response.getStatusCode(), request.getMethod(), request.getUri()); - return response; - } - - @Override - public byte[] decryptRequest(byte[] ciphertext) { - if (!isUpgraded) { - throw new RuntimeException("Cannot handle binary before connection is upgraded"); - } - if (binaryProcessor == null) { - binaryProcessor = new LengthPrefixedByteArrayProcessor(); - } - Collection res = binaryProcessor.handle(ciphertext); - if (res.isEmpty()) { - return new byte[0]; - } else { - try (ByteArrayOutputStream decrypted = new ByteArrayOutputStream()) { - res.stream() - .map(msg -> decrypt(msg)) - .forEach( - bytes -> { - try { - decrypted.write(bytes); - } catch (Exception e) { - throw new RuntimeException(e); - } - }); - return decrypted.toByteArray(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - } - - @Override - public byte[] encryptResponse(byte[] response) throws IOException { - int offset = 0; - try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { - while (offset < response.length) { - short length = (short) Math.min(response.length - offset, 0x400); - byte[] lengthBytes = - ByteBuffer.allocate(2).order(ByteOrder.LITTLE_ENDIAN).putShort(length).array(); - baos.write(lengthBytes); - - byte[] nonce = Pack.longToLittleEndian(outboundBinaryMessageCount++); - byte[] plaintext; - if (response.length == length) { - plaintext = response; - } else { - plaintext = new byte[length]; - System.arraycopy(response, offset, plaintext, 0, length); - } - offset += length; - baos.write(new ChachaEncoder(writeKey, nonce).encodeCiphertext(plaintext, lengthBytes)); - } - return baos.toByteArray(); - } - } - - private byte[] decrypt(byte[] msg) { - byte[] mac = new byte[16]; - byte[] ciphertext = new byte[msg.length - 16]; - System.arraycopy(msg, 0, ciphertext, 0, msg.length - 16); - System.arraycopy(msg, msg.length - 16, mac, 0, 16); - byte[] additionalData = - ByteBuffer.allocate(2) - .order(ByteOrder.LITTLE_ENDIAN) - .putShort((short) (msg.length - 16)) - .array(); - try { - byte[] nonce = Pack.longToLittleEndian(inboundBinaryMessageCount++); - return new ChachaDecoder(readKey, nonce).decodeCiphertext(mac, additionalData, ciphertext); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - @Override - public void close() { - subscriptions.removeConnection(this); - } - - @Override - public void outOfBand(HttpResponse message) { - outOfBandMessageCallback.accept(message); - } - - @Override - public String getUsername() { - return username; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/connections/HomekitClientConnectionFactoryImpl.java b/src/main/java/io/github/hapjava/server/impl/connections/HomekitClientConnectionFactoryImpl.java deleted file mode 100644 index 9c8ad9fc0..000000000 --- a/src/main/java/io/github/hapjava/server/impl/connections/HomekitClientConnectionFactoryImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.server.impl.connections; - -import io.github.hapjava.server.HomekitAuthInfo; -import io.github.hapjava.server.impl.HomekitRegistry; -import io.github.hapjava.server.impl.http.HomekitClientConnection; -import io.github.hapjava.server.impl.http.HomekitClientConnectionFactory; -import io.github.hapjava.server.impl.http.HttpResponse; -import io.github.hapjava.server.impl.jmdns.JmdnsHomekitAdvertiser; -import java.util.function.Consumer; - -public class HomekitClientConnectionFactoryImpl implements HomekitClientConnectionFactory { - - private final HomekitAuthInfo authInfo; - private final HomekitRegistry registry; - private final SubscriptionManager subscriptions; - private final JmdnsHomekitAdvertiser advertiser; - - public HomekitClientConnectionFactoryImpl( - HomekitAuthInfo authInfo, - HomekitRegistry registry, - SubscriptionManager subscriptions, - JmdnsHomekitAdvertiser advertiser) { - this.registry = registry; - this.authInfo = authInfo; - this.subscriptions = subscriptions; - this.advertiser = advertiser; - } - - @Override - public HomekitClientConnection createConnection(Consumer outOfBandMessageCallback) { - return new ConnectionImpl( - authInfo, registry, outOfBandMessageCallback, subscriptions, advertiser); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/connections/HttpSession.java b/src/main/java/io/github/hapjava/server/impl/connections/HttpSession.java deleted file mode 100644 index f1c97c62c..000000000 --- a/src/main/java/io/github/hapjava/server/impl/connections/HttpSession.java +++ /dev/null @@ -1,175 +0,0 @@ -package io.github.hapjava.server.impl.connections; - -import io.github.hapjava.accessories.HomekitAccessory; -import io.github.hapjava.server.HomekitAuthInfo; -import io.github.hapjava.server.impl.HomekitRegistry; -import io.github.hapjava.server.impl.http.HomekitClientConnection; -import io.github.hapjava.server.impl.http.HttpRequest; -import io.github.hapjava.server.impl.http.HttpResponse; -import io.github.hapjava.server.impl.jmdns.JmdnsHomekitAdvertiser; -import io.github.hapjava.server.impl.json.AccessoryController; -import io.github.hapjava.server.impl.json.CharacteristicsController; -import io.github.hapjava.server.impl.pairing.PairSetupManager; -import io.github.hapjava.server.impl.pairing.PairVerifyManager; -import io.github.hapjava.server.impl.pairing.PairingsManager; -import io.github.hapjava.server.impl.responses.InternalServerErrorResponse; -import io.github.hapjava.server.impl.responses.NotFoundResponse; -import java.io.IOException; -import java.net.InetAddress; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -class HttpSession { - - private volatile PairSetupManager pairSetupManager; - private volatile PairVerifyManager pairVerifyManager; - private volatile AccessoryController accessoryController; - private volatile CharacteristicsController characteristicsController; - - private final HomekitAuthInfo authInfo; - private final HomekitRegistry registry; - private final SubscriptionManager subscriptions; - private final HomekitClientConnection connection; - private final JmdnsHomekitAdvertiser advertiser; - - private static final Logger logger = LoggerFactory.getLogger(HttpSession.class); - - public HttpSession( - HomekitAuthInfo authInfo, - HomekitRegistry registry, - SubscriptionManager subscriptions, - HomekitClientConnection connection, - JmdnsHomekitAdvertiser advertiser) { - this.authInfo = authInfo; - this.registry = registry; - this.subscriptions = subscriptions; - this.connection = connection; - this.advertiser = advertiser; - } - - public HttpResponse handleRequest(HttpRequest request) throws IOException { - switch (request.getUri()) { - case "/pair-setup": - return handlePairSetup(request); - - case "/pair-verify": - return handlePairVerify(request); - - default: - if (registry.isAllowUnauthenticatedRequests()) { - return handleAuthenticatedRequest(request); - } else { - logger.warn("Unrecognized request for " + request.getUri()); - return new NotFoundResponse(); - } - } - } - - public HttpResponse handleAuthenticatedRequest(HttpRequest request) throws IOException { - advertiser.setDiscoverable( - false); // bridge is already bound and should not be discoverable anymore - try { - switch (request.getUri()) { - case "/accessories": - return getAccessoryController().listing(); - - case "/characteristics": - switch (request.getMethod()) { - case PUT: - return getCharacteristicsController().put(request, connection); - - default: - logger.warn("Unrecognized method for " + request.getUri()); - return new NotFoundResponse(); - } - - case "/pairings": - return new PairingsManager(authInfo, advertiser).handle(request); - - default: - if (request.getUri().startsWith("/characteristics?")) { - return getCharacteristicsController().get(request); - } - logger.warn("Unrecognized request for " + request.getUri()); - return new NotFoundResponse(); - } - } catch (Exception e) { - logger.warn("Could not handle request", e); - return new InternalServerErrorResponse(e); - } - } - - private HttpResponse handlePairSetup(HttpRequest request) { - if (pairSetupManager == null) { - synchronized (HttpSession.class) { - if (pairSetupManager == null) { - pairSetupManager = new PairSetupManager(authInfo, registry); - } - } - } - try { - return pairSetupManager.handle(request); - } catch (Exception e) { - logger.warn("Exception encountered during pairing", e); - return new InternalServerErrorResponse(e); - } - } - - private HttpResponse handlePairVerify(HttpRequest request) { - if (pairVerifyManager == null) { - synchronized (HttpSession.class) { - if (pairVerifyManager == null) { - pairVerifyManager = new PairVerifyManager(authInfo, registry); - } - } - } - try { - return pairVerifyManager.handle(request); - } catch (Exception e) { - logger.warn("Exception encountered while verifying pairing", e); - return new InternalServerErrorResponse(e); - } - } - - private synchronized AccessoryController getAccessoryController() { - if (accessoryController == null) { - accessoryController = new AccessoryController(registry); - } - return accessoryController; - } - - private synchronized CharacteristicsController getCharacteristicsController() { - if (characteristicsController == null) { - characteristicsController = new CharacteristicsController(registry, subscriptions); - } - return characteristicsController; - } - - public static class SessionKey { - private final InetAddress address; - private final HomekitAccessory accessory; - - public SessionKey(InetAddress address, HomekitAccessory accessory) { - this.address = address; - this.accessory = accessory; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof SessionKey) { - return address.equals(((SessionKey) obj).address) - && accessory.equals(((SessionKey) obj).accessory); - } else { - return false; - } - } - - @Override - public int hashCode() { - int hash = 1; - hash = hash * 31 + address.hashCode(); - hash = hash * 31 + accessory.hashCode(); - return hash; - } - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/connections/LengthPrefixedByteArrayProcessor.java b/src/main/java/io/github/hapjava/server/impl/connections/LengthPrefixedByteArrayProcessor.java deleted file mode 100644 index 124acbb51..000000000 --- a/src/main/java/io/github/hapjava/server/impl/connections/LengthPrefixedByteArrayProcessor.java +++ /dev/null @@ -1,88 +0,0 @@ -package io.github.hapjava.server.impl.connections; - -import java.io.ByteArrayOutputStream; -import java.util.Collection; -import java.util.LinkedList; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -class LengthPrefixedByteArrayProcessor { - - private final ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - private Byte - firstLengthByteBuffer; // Only used if we've received a single byte at the start of a message - private int targetLength = 0; - - private static final Logger LOGGER = - LoggerFactory.getLogger(LengthPrefixedByteArrayProcessor.class); - - public synchronized Collection handle(byte[] data) { - Collection results = new LinkedList<>(); - int pos = 0; - LOGGER.trace( - "Received message of length {}. Existing buffer is {}", data.length, buffer.size()); - if (buffer.size() == 0) { - while (data.length - pos > 18) { - int targetLength = (data[0] & 0xFF) + (data[1] & 0xFF) * 256 + 16 + 2; - LOGGER.trace("Attempting to read message of length {}", targetLength); - if (data.length >= pos + targetLength) { - byte[] b = new byte[targetLength - 2]; - System.arraycopy(data, pos + 2, b, 0, targetLength - 2); - results.add(b); - LOGGER.trace("Read complete message"); - pos = pos + targetLength; - } else { - LOGGER.trace("Not enough data available"); - break; - } - } - } - if (data.length > pos) { - LOGGER.trace("Remaining data available"); - step(data, pos, results); - } - LOGGER.trace("Returning {} results", results.size()); - return results; - } - - private void step(byte[] data, int pos, Collection results) { - LOGGER.trace("Performing step operation on buffer of length {} with pos {}", data.length, pos); - if (targetLength == 0 && data.length == 1 + pos) { - firstLengthByteBuffer = data[pos]; - LOGGER.trace( - "Received a single byte message, storing byte {} for later", firstLengthByteBuffer); - return; - } - if (targetLength == 0) { - if (firstLengthByteBuffer != null) { - targetLength = (firstLengthByteBuffer & 0xFF) + (data[pos] & 0xFF) * 256 + 16; - pos += 1; - LOGGER.trace( - "Received the second byte after storing the first byte. New length is {}", - targetLength); - } else { - targetLength = (data[pos] & 0xFF) + (data[pos + 1] & 0xFF) * 256 + 16; - pos += 2; - LOGGER.trace("targetLength is {}", targetLength); - } - } - int toWrite = targetLength - buffer.size(); - if (toWrite <= data.length - pos) { - // We have a complete message - LOGGER.trace("Received a complete message"); - buffer.write(data, pos, toWrite); - results.add(buffer.toByteArray()); - buffer.reset(); - targetLength = 0; - if (pos + toWrite < data.length) { - step(data, pos + toWrite, results); - } - } else { - LOGGER.trace( - "Storing {} bytes in buffer until we receive the complete {}", - data.length - pos, - targetLength); - buffer.write(data, pos, data.length - pos); - } - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/connections/PendingNotification.java b/src/main/java/io/github/hapjava/server/impl/connections/PendingNotification.java deleted file mode 100644 index ea9c69305..000000000 --- a/src/main/java/io/github/hapjava/server/impl/connections/PendingNotification.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.github.hapjava.server.impl.connections; - -import io.github.hapjava.characteristics.EventableCharacteristic; - -public class PendingNotification { - public int aid; - public int iid; - public EventableCharacteristic characteristic; - - public PendingNotification(int aid, int iid, EventableCharacteristic characteristic) { - this.aid = aid; - this.iid = iid; - this.characteristic = characteristic; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/connections/SubscriptionManager.java b/src/main/java/io/github/hapjava/server/impl/connections/SubscriptionManager.java deleted file mode 100644 index 9399295fb..000000000 --- a/src/main/java/io/github/hapjava/server/impl/connections/SubscriptionManager.java +++ /dev/null @@ -1,257 +0,0 @@ -package io.github.hapjava.server.impl.connections; - -import io.github.hapjava.characteristics.Characteristic; -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.server.impl.HomekitRegistry; -import io.github.hapjava.server.impl.http.HomekitClientConnection; -import io.github.hapjava.server.impl.http.HttpResponse; -import io.github.hapjava.server.impl.json.EventController; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SubscriptionManager { - - private static final Logger LOGGER = LoggerFactory.getLogger(SubscriptionManager.class); - - private static class ConnectionsWithIds { - Set connections; - int aid, iid; - - ConnectionsWithIds(int aid, int iid) { - this.aid = aid; - this.iid = iid; - this.connections = new HashSet<>(); - } - } - - private final Map subscriptions = new HashMap<>(); - private final Map> reverse = - new HashMap<>(); - private final Map> pendingNotifications = - new HashMap<>(); - private int nestedBatches = 0; - - public synchronized void addSubscription( - int aid, - int iid, - EventableCharacteristic characteristic, - HomekitClientConnection connection) { - synchronized (this) { - ConnectionsWithIds subscribers; - if (subscriptions.containsKey(characteristic)) { - subscribers = subscriptions.get(characteristic); - } else { - subscribers = new ConnectionsWithIds(aid, iid); - subscriptions.put(characteristic, subscribers); - subscribe(aid, iid, characteristic); - } - subscribers.connections.add(connection); - - if (!reverse.containsKey(connection)) { - reverse.put(connection, new HashSet<>()); - } - reverse.get(connection).add(characteristic); - LOGGER.trace( - "Added subscription to {}:{} ({}) for {}", - aid, - iid, - characteristic.getClass().getSimpleName(), - connection.hashCode()); - } - } - - public synchronized void removeSubscription( - EventableCharacteristic characteristic, HomekitClientConnection connection) { - ConnectionsWithIds subscribers = subscriptions.get(characteristic); - if (subscribers != null) { - subscribers.connections.remove(connection); - if (subscribers.connections.isEmpty()) { - LOGGER.trace("Unsubscribing from characteristic as all subscriptions are closed"); - characteristic.unsubscribe(); - subscriptions.remove(characteristic); - } - - // Remove pending notifications for this no-longer-subscribed characteristic - List connectionNotifications = pendingNotifications.get(connection); - if (connectionNotifications != null) { - connectionNotifications.removeIf(n -> n.aid == subscribers.aid && n.iid == subscribers.iid); - if (connectionNotifications.isEmpty()) pendingNotifications.remove(connection); - } - - LOGGER.trace( - "Removed subscription from {}:{} ({}) for {}", - subscribers.aid, - subscribers.iid, - characteristic.getClass().getSimpleName(), - connection.hashCode()); - } - - Set reverse = this.reverse.get(connection); - if (reverse != null) { - reverse.remove(characteristic); - if (reverse.isEmpty()) this.reverse.remove(connection); - } - } - - public synchronized void removeConnection(HomekitClientConnection connection) { - removeConnection(connection, reverse.remove(connection)); - } - - private void removeConnection( - HomekitClientConnection connection, Set characteristics) { - pendingNotifications.remove(connection); - if (characteristics != null) { - for (EventableCharacteristic characteristic : characteristics) { - removeSubscription(characteristic, connection); - } - } - LOGGER.trace("Removed connection {}", connection.hashCode()); - } - - public synchronized void batchUpdate() { - ++this.nestedBatches; - } - - public synchronized void completeUpdateBatch() { - if (--this.nestedBatches == 0) flushUpdateBatch(); - } - - private void flushUpdateBatch() { - if (pendingNotifications.isEmpty()) return; - - LOGGER.trace("Publishing batched changes"); - for (Map.Entry> entry : - pendingNotifications.entrySet()) { - try { - HttpResponse message = new EventController().getMessage(entry.getValue()); - entry.getKey().outOfBand(message); - } catch (Exception e) { - LOGGER.warn("Failed to create new event message", e); - } - } - pendingNotifications.clear(); - } - - public synchronized void publish(int accessoryId, int iid, EventableCharacteristic changed) { - final ConnectionsWithIds subscribers = subscriptions.get(changed); - if (subscribers == null || subscribers.connections.isEmpty()) { - LOGGER.trace("No subscribers to characteristic {} at accessory {} ", changed, accessoryId); - return; // no subscribers - } - if (nestedBatches != 0) { - LOGGER.trace("Batching change for accessory {} and characteristic {} " + accessoryId, iid); - PendingNotification notification = new PendingNotification(accessoryId, iid, changed); - for (HomekitClientConnection connection : subscribers.connections) { - if (!pendingNotifications.containsKey(connection)) { - pendingNotifications.put(connection, new ArrayList()); - } - pendingNotifications.get(connection).add(notification); - } - return; - } - - try { - HttpResponse message = new EventController().getMessage(accessoryId, iid, changed); - LOGGER.trace("Publishing change for " + accessoryId); - for (HomekitClientConnection connection : subscribers.connections) { - connection.outOfBand(message); - } - } catch (Exception e) { - LOGGER.warn("Failed to create new event message", e); - } - } - - /** - * The accessory registry has changed; go through all subscriptions and link to any new/changed - * characteristics - */ - public synchronized void resync(HomekitRegistry registry) { - LOGGER.trace("Resyncing subscriptions"); - flushUpdateBatch(); - - Map newSubscriptions = new HashMap<>(); - Iterator> i = - subscriptions.entrySet().iterator(); - while (i.hasNext()) { - Map.Entry entry = i.next(); - EventableCharacteristic oldCharacteristic = entry.getKey(); - ConnectionsWithIds subscribers = entry.getValue(); - Characteristic newCharacteristic = - registry.getCharacteristics(subscribers.aid).get(subscribers.iid); - if (newCharacteristic == null || newCharacteristic.getType() != oldCharacteristic.getType()) { - // characteristic is gone or has completely changed; drop all subscriptions for it - LOGGER.trace( - "{}:{} ({}) has gone missing; dropping subscriptions.", - subscribers.aid, - subscribers.iid, - oldCharacteristic.getClass().getSimpleName()); - i.remove(); - for (HomekitClientConnection conn : subscribers.connections) { - removeSubscription(oldCharacteristic, conn); - } - } else if (newCharacteristic != oldCharacteristic) { - EventableCharacteristic newEventableCharacteristic = - (EventableCharacteristic) newCharacteristic; - LOGGER.trace( - "{}:{} has been replaced by a compatible characteristic; re-connecting subscriptions", - subscribers.aid, - subscribers.iid); - // characteristic has been replaced by another instance of the same thing; - // re-connect subscriptions - i.remove(); - oldCharacteristic.unsubscribe(); - subscribe(subscribers.aid, subscribers.iid, newEventableCharacteristic); - // we can't replace the key, and we can't add to the map while we're iterating, - // so save it off to a temporary map that we'll add them all at the end - newSubscriptions.put(newEventableCharacteristic, subscribers); - - for (HomekitClientConnection conn : subscribers.connections) { - Set subscribedCharacteristics = reverse.get(conn); - subscribedCharacteristics.remove(oldCharacteristic); - subscribedCharacteristics.add(newEventableCharacteristic); - - // and also update references for any pending notifications, so they'll get the proper - // value - List connectionPendingNotifications = pendingNotifications.get(conn); - if (connectionPendingNotifications != null) { - for (PendingNotification notification : connectionPendingNotifications) { - if (notification.characteristic == oldCharacteristic) { - notification.characteristic = newEventableCharacteristic; - } - } - } - } - } - } - subscriptions.putAll(newSubscriptions); - } - - private void subscribe(int aid, int iid, EventableCharacteristic characteristic) { - characteristic.subscribe( - () -> { - publish(aid, iid, characteristic); - }); - } - - /** Remove all existing subscriptions */ - public synchronized void removeAll() { - LOGGER.trace("Removing {} reverse connections from subscription manager", reverse.size()); - Iterator>> i = - reverse.entrySet().iterator(); - while (i.hasNext()) { - Map.Entry> entry = i.next(); - HomekitClientConnection connection = entry.getKey(); - LOGGER.trace("Removing connection {}", connection.hashCode()); - i.remove(); - removeConnection(connection, entry.getValue()); - } - LOGGER.trace("Subscription sizes are {} and {}", reverse.size(), subscriptions.size()); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/crypto/ChachaDecoder.java b/src/main/java/io/github/hapjava/server/impl/crypto/ChachaDecoder.java deleted file mode 100755 index 014f4b500..000000000 --- a/src/main/java/io/github/hapjava/server/impl/crypto/ChachaDecoder.java +++ /dev/null @@ -1,98 +0,0 @@ -package io.github.hapjava.server.impl.crypto; - -import java.io.IOException; -import org.bouncycastle.crypto.InvalidCipherTextException; -import org.bouncycastle.crypto.modes.ChaCha20Poly1305; -import org.bouncycastle.crypto.params.AEADParameters; -import org.bouncycastle.crypto.params.KeyParameter; -import org.bouncycastle.tls.AlertDescription; -import org.bouncycastle.tls.TlsFatalAlert; - -public class ChachaDecoder { - - private final ChaCha20Poly1305 cipher; - private final byte[] key; - private final byte[] nonce; - - public ChachaDecoder(byte[] key, byte[] nonce) throws IOException { - this.key = key; - // ChaCha20-Poly1305 requires exactly 12 bytes (96 bits) for nonce - this.nonce = ensureNonceSize(nonce); - this.cipher = new ChaCha20Poly1305(); - } - - private byte[] ensureNonceSize(byte[] nonce) { - if (nonce == null) { - return new byte[12]; // Default to zero nonce if null - } - - // For HomeKit pairing messages, handle Apple's string-based nonces - if (nonce.length == 8) { - // Apple's HomeKit implementation uses a specific nonce format - // Based on RFC 7539 and Apple's implementation, the nonce should be: - // - 4 bytes constant (0x00000000) - // - 8 bytes nonce string - // This matches ChaCha20's 96-bit nonce requirement - byte[] adjustedNonce = new byte[12]; - // Put the 8-byte nonce at the END (bytes 4-11), not at the beginning - System.arraycopy(nonce, 0, adjustedNonce, 4, 8); - // First 4 bytes remain zero (counter initialization) - return adjustedNonce; - } - - if (nonce.length == 12) { - return nonce; // Already correct size - } - - // For other nonce lengths, pad or truncate to 12 bytes - byte[] adjustedNonce = new byte[12]; - if (nonce.length < 12) { - // Pad with zeros if too short - put nonce at beginning - System.arraycopy(nonce, 0, adjustedNonce, 0, nonce.length); - // Remaining bytes are already zero - } else { - // Truncate if too long - take first 12 bytes - System.arraycopy(nonce, 0, adjustedNonce, 0, 12); - } - - return adjustedNonce; - } - - public byte[] decodeCiphertext(byte[] receivedMAC, byte[] additionalData, byte[] ciphertext) - throws IOException { - - try { - byte[] ciphertextWithTag = new byte[ciphertext.length + receivedMAC.length]; - System.arraycopy(ciphertext, 0, ciphertextWithTag, 0, ciphertext.length); - System.arraycopy(receivedMAC, 0, ciphertextWithTag, ciphertext.length, receivedMAC.length); - - ChaCha20Poly1305 cipher1 = new ChaCha20Poly1305(); - AEADParameters params = new AEADParameters(new KeyParameter(key), 128, nonce, additionalData); - cipher1.init(false, params); - - byte[] output = new byte[cipher1.getOutputSize(ciphertextWithTag.length)]; - int len = cipher1.processBytes(ciphertextWithTag, 0, ciphertextWithTag.length, output, 0); - len += cipher1.doFinal(output, len); - - byte[] result = new byte[len]; - System.arraycopy(output, 0, result, 0, len); - - return result; - - } catch (InvalidCipherTextException e) { - throw new TlsFatalAlert(AlertDescription.bad_record_mac); - } - } - - private static String bytesToHex(byte[] bytes) { - StringBuilder result = new StringBuilder(); - for (byte b : bytes) { - result.append(String.format("%02x", b)); - } - return result.toString(); - } - - public byte[] decodeCiphertext(byte[] receivedMAC, byte[] ciphertext) throws IOException { - return decodeCiphertext(receivedMAC, null, ciphertext); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/crypto/ChachaEncoder.java b/src/main/java/io/github/hapjava/server/impl/crypto/ChachaEncoder.java deleted file mode 100755 index 889c9ca86..000000000 --- a/src/main/java/io/github/hapjava/server/impl/crypto/ChachaEncoder.java +++ /dev/null @@ -1,93 +0,0 @@ -package io.github.hapjava.server.impl.crypto; - -import java.io.IOException; -import org.bouncycastle.crypto.InvalidCipherTextException; -import org.bouncycastle.crypto.modes.ChaCha20Poly1305; -import org.bouncycastle.crypto.params.AEADParameters; -import org.bouncycastle.crypto.params.KeyParameter; - -public class ChachaEncoder { - - private final ChaCha20Poly1305 cipher; - private final byte[] key; - private final byte[] nonce; - - public ChachaEncoder(byte[] key, byte[] nonce) throws IOException { - this.key = key; - // ChaCha20-Poly1305 requires exactly 12 bytes (96 bits) for nonce - this.nonce = ensureNonceSize(nonce); - this.cipher = new ChaCha20Poly1305(); - } - - private byte[] ensureNonceSize(byte[] nonce) { - if (nonce == null) { - return new byte[12]; // Default to zero nonce if null - } - - // For HomeKit pairing messages, handle Apple's string-based nonces - if (nonce.length == 8) { - // Apple's HomeKit implementation uses a specific nonce format - // Based on RFC 7539 and Apple's implementation, the nonce should be: - // - 4 bytes constant (0x00000000) - // - 8 bytes nonce string - // This matches ChaCha20's 96-bit nonce requirement and ChachaDecoder format - byte[] adjustedNonce = new byte[12]; - // Put the 8-byte nonce at the END (bytes 4-11), not at the beginning - System.arraycopy(nonce, 0, adjustedNonce, 4, 8); - // First 4 bytes remain zero (counter initialization) - return adjustedNonce; - } - - if (nonce.length == 12) { - return nonce; // Already correct size - } - - byte[] adjustedNonce = new byte[12]; - if (nonce.length < 12) { - // Pad with zeros if too short - System.arraycopy(nonce, 0, adjustedNonce, 0, nonce.length); - } else { - // Truncate if too long - System.arraycopy(nonce, 0, adjustedNonce, 0, 12); - } - return adjustedNonce; - } - - private static String bytesToHex(byte[] bytes) { - StringBuilder result = new StringBuilder(); - for (byte b : bytes) { - result.append(String.format("%02x", b)); - } - return result.toString(); - } - - public byte[] encodeCiphertext(byte[] plaintext) throws IOException { - return encodeCiphertext(plaintext, null); - } - - public byte[] encodeCiphertext(byte[] plaintext, byte[] additionalData) throws IOException { - try { - // Use the nonce provided during construction - AEADParameters params = new AEADParameters(new KeyParameter(key), 128, nonce, additionalData); - cipher.init(true, params); - - byte[] output = new byte[cipher.getOutputSize(plaintext.length)]; - int len = cipher.processBytes(plaintext, 0, plaintext.length, output, 0); - len += cipher.doFinal(output, len); - - // Split the result into ciphertext and MAC - byte[] ciphertext = new byte[plaintext.length]; - byte[] mac = new byte[16]; - System.arraycopy(output, 0, ciphertext, 0, plaintext.length); - System.arraycopy(output, plaintext.length, mac, 0, 16); - - // Return combined ciphertext + MAC as expected by the original interface - byte[] ret = new byte[ciphertext.length + 16]; - System.arraycopy(ciphertext, 0, ret, 0, ciphertext.length); - System.arraycopy(mac, 0, ret, ciphertext.length, 16); - return ret; - } catch (InvalidCipherTextException e) { - throw new IOException("Encryption failed", e); - } - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/crypto/EdsaSigner.java b/src/main/java/io/github/hapjava/server/impl/crypto/EdsaSigner.java deleted file mode 100644 index a1985d186..000000000 --- a/src/main/java/io/github/hapjava/server/impl/crypto/EdsaSigner.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.github.hapjava.server.impl.crypto; - -import java.security.InvalidKeyException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.Signature; -import java.security.SignatureException; -import net.i2p.crypto.eddsa.EdDSAEngine; -import net.i2p.crypto.eddsa.EdDSAPrivateKey; -import net.i2p.crypto.eddsa.EdDSAPublicKey; -import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable; -import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec; -import net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec; -import net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec; - -public class EdsaSigner { - - private final EdDSAPublicKey publicKey; - private final EdDSAPrivateKey privateKey; - - public EdsaSigner(byte[] privateKeyBytes) { - EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName("ed25519-sha-512"); - EdDSAPrivateKeySpec privateKeySpec = new EdDSAPrivateKeySpec(privateKeyBytes, spec); - EdDSAPublicKeySpec pubKeySpec = new EdDSAPublicKeySpec(privateKeySpec.getA(), spec); - publicKey = new EdDSAPublicKey(pubKeySpec); - privateKey = new EdDSAPrivateKey(privateKeySpec); - } - - public byte[] getPublicKey() { - return publicKey.getAbyte(); - } - - public byte[] sign(byte[] material) - throws NoSuchAlgorithmException, InvalidKeyException, SignatureException { - Signature sgr = new EdDSAEngine(MessageDigest.getInstance("SHA-512")); - sgr.initSign(privateKey); - sgr.update(material); - return sgr.sign(); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/crypto/EdsaVerifier.java b/src/main/java/io/github/hapjava/server/impl/crypto/EdsaVerifier.java deleted file mode 100644 index e5ca8e90a..000000000 --- a/src/main/java/io/github/hapjava/server/impl/crypto/EdsaVerifier.java +++ /dev/null @@ -1,29 +0,0 @@ -package io.github.hapjava.server.impl.crypto; - -import java.security.MessageDigest; -import java.security.PublicKey; -import java.security.Signature; -import net.i2p.crypto.eddsa.EdDSAEngine; -import net.i2p.crypto.eddsa.EdDSAPublicKey; -import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable; -import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec; -import net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec; - -public class EdsaVerifier { - - private final PublicKey publicKey; - - public EdsaVerifier(byte[] publicKey) { - EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName("ed25519-sha-512"); - EdDSAPublicKeySpec pubKey = new EdDSAPublicKeySpec(publicKey, spec); - this.publicKey = new EdDSAPublicKey(pubKey); - } - - public boolean verify(byte[] data, byte[] signature) throws Exception { - Signature sgr = new EdDSAEngine(MessageDigest.getInstance("SHA-512")); - sgr.initVerify(publicKey); - sgr.update(data); - - return sgr.verify(signature); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/crypto/HAPSetupCodeUtils.java b/src/main/java/io/github/hapjava/server/impl/crypto/HAPSetupCodeUtils.java deleted file mode 100644 index ecf4d61de..000000000 --- a/src/main/java/io/github/hapjava/server/impl/crypto/HAPSetupCodeUtils.java +++ /dev/null @@ -1,68 +0,0 @@ -package io.github.hapjava.server.impl.crypto; - -import java.util.Base64; -import org.bouncycastle.crypto.Digest; -import org.bouncycastle.crypto.digests.SHA512Digest; - -public class HAPSetupCodeUtils { - private static final String ALPHA_NUMERIC_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; - - public static String randomAlphaNumeric(int count) { - StringBuilder builder = new StringBuilder(); - while (count-- != 0) { - int character = (int) (Math.random() * ALPHA_NUMERIC_STRING.length()); - builder.append(ALPHA_NUMERIC_STRING.charAt(character)); - } - return builder.toString(); - } - - public static String generateSetupId() { - return randomAlphaNumeric(4); - } - - private static byte[] calculateHash(final String input, final Digest digest) { - byte[] inputAsBytes = input.getBytes(); - byte[] retValue = new byte[digest.getDigestSize()]; - digest.update(inputAsBytes, 0, inputAsBytes.length); - digest.doFinal(retValue, 0); - return retValue; - } - - /** - * generate SHA52 Hash for given string. The hash is used for mDNS advertisement. - * - * @param value value - * @return hash - */ - public static String generateSHA512Hash(final String value) { - final byte[] hash = calculateHash(value.toUpperCase(), new SHA512Digest()); - final byte[] hashTuncate = new byte[4]; - System.arraycopy(hash, 0, hashTuncate, 0, 4); - String hashStr = Base64.getEncoder().encodeToString(hashTuncate); - return hashStr; - } - - /** - * generate Setup URI which can be used fo QR Code generation. - * - * @param pin PIN number without "-" - * @param setupId alphanumeric string of the length 4 - * @param category accessory category - * @return setup UID - */ - public static String getSetupURI(final String pin, final String setupId, final int category) { - long code = - 0 << 43 // Version - | 0 << 39 // Reserved - | ((long) category) << 31 // Category - | 0 << 29 // BLE support - | 1 << 28 // IP support - | 0 << 27 // Paired / NFC - | Integer.valueOf(pin); // PIN - String payload = Long.toString(code, 36) + setupId; - while (payload.length() < 13) { - payload = '0' + payload; - } - return "X-HM://" + payload.toUpperCase(); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/crypto/PolyKeyCreator.java b/src/main/java/io/github/hapjava/server/impl/crypto/PolyKeyCreator.java deleted file mode 100644 index ed66342c8..000000000 --- a/src/main/java/io/github/hapjava/server/impl/crypto/PolyKeyCreator.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.hapjava.server.impl.crypto; - -import org.bouncycastle.crypto.macs.Poly1305; -import org.bouncycastle.crypto.params.KeyParameter; -import org.bouncycastle.util.Pack; - -class PolyKeyCreator { - - public static byte[] create(KeyParameter macKey, byte[] additionalData, byte[] ciphertext) { - Poly1305 poly = new Poly1305(); - poly.init(macKey); - - if (additionalData != null) { - poly.update(additionalData, 0, additionalData.length); - if (additionalData.length % 16 != 0) { - int round = 16 - (additionalData.length % 16); - poly.update(new byte[round], 0, round); - } - } - - poly.update(ciphertext, 0, ciphertext.length); - if (ciphertext.length % 16 != 0) { - int round = 16 - (ciphertext.length % 16); - poly.update(new byte[round], 0, round); - } - - // additional data length - byte[] additionalDataLength; - if (additionalData != null) { - additionalDataLength = Pack.longToLittleEndian(additionalData.length); - } else { - additionalDataLength = new byte[8]; - } - poly.update(additionalDataLength, 0, 8); - byte[] ciphertextLength = Pack.longToLittleEndian(ciphertext.length); - poly.update(ciphertextLength, 0, 8); - - byte[] calculatedMAC = new byte[poly.getMacSize()]; - poly.doFinal(calculatedMAC, 0); - return calculatedMAC; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/http/HomekitClientConnection.java b/src/main/java/io/github/hapjava/server/impl/http/HomekitClientConnection.java deleted file mode 100644 index 2648808bb..000000000 --- a/src/main/java/io/github/hapjava/server/impl/http/HomekitClientConnection.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.github.hapjava.server.impl.http; - -import java.io.IOException; - -public interface HomekitClientConnection { - - HttpResponse handleRequest(HttpRequest request) throws IOException; - - byte[] decryptRequest(byte[] ciphertext); - - byte[] encryptResponse(byte[] plaintext) throws IOException; - - void close(); - - void outOfBand(HttpResponse message); - - default String getUsername() { - return null; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/http/HomekitClientConnectionFactory.java b/src/main/java/io/github/hapjava/server/impl/http/HomekitClientConnectionFactory.java deleted file mode 100644 index 18c814306..000000000 --- a/src/main/java/io/github/hapjava/server/impl/http/HomekitClientConnectionFactory.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.github.hapjava.server.impl.http; - -import java.util.function.Consumer; - -public interface HomekitClientConnectionFactory { - - HomekitClientConnection createConnection(Consumer outOfBandMessageCallback); -} diff --git a/src/main/java/io/github/hapjava/server/impl/http/HttpMethod.java b/src/main/java/io/github/hapjava/server/impl/http/HttpMethod.java deleted file mode 100644 index f4844b667..000000000 --- a/src/main/java/io/github/hapjava/server/impl/http/HttpMethod.java +++ /dev/null @@ -1,7 +0,0 @@ -package io.github.hapjava.server.impl.http; - -public enum HttpMethod { - GET, - POST, - PUT -} diff --git a/src/main/java/io/github/hapjava/server/impl/http/HttpRequest.java b/src/main/java/io/github/hapjava/server/impl/http/HttpRequest.java deleted file mode 100644 index 9921af341..000000000 --- a/src/main/java/io/github/hapjava/server/impl/http/HttpRequest.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.github.hapjava.server.impl.http; - -public interface HttpRequest { - - String getUri(); - - byte[] getBody(); - - HttpMethod getMethod(); -} diff --git a/src/main/java/io/github/hapjava/server/impl/http/HttpResponse.java b/src/main/java/io/github/hapjava/server/impl/http/HttpResponse.java deleted file mode 100644 index 4871dba99..000000000 --- a/src/main/java/io/github/hapjava/server/impl/http/HttpResponse.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.hapjava.server.impl.http; - -import java.nio.ByteBuffer; -import java.util.Collections; -import java.util.Map; - -public interface HttpResponse { - - int getStatusCode(); - - default ByteBuffer getBody() { - return ByteBuffer.allocate(0); - } - - default HttpVersion getVersion() { - return HttpVersion.HTTP_1_1; - } - - default Map getHeaders() { - return Collections.emptyMap(); - } - - default boolean doUpgrade() { - return false; - } - - public enum HttpVersion { - HTTP_1_1, - EVENT_1_0 - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/http/impl/AccessoryHandler.java b/src/main/java/io/github/hapjava/server/impl/http/impl/AccessoryHandler.java deleted file mode 100644 index 6b840c713..000000000 --- a/src/main/java/io/github/hapjava/server/impl/http/impl/AccessoryHandler.java +++ /dev/null @@ -1,104 +0,0 @@ -package io.github.hapjava.server.impl.http.impl; - -import io.github.hapjava.server.impl.http.HomekitClientConnection; -import io.github.hapjava.server.impl.http.HomekitClientConnectionFactory; -import io.github.hapjava.server.impl.http.HttpResponse; -import io.netty.buffer.Unpooled; -import io.netty.channel.Channel; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.http.*; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -class AccessoryHandler extends SimpleChannelInboundHandler { - - private static final Logger LOGGER = LoggerFactory.getLogger(AccessoryHandler.class); - - private HomekitClientConnection connection; - private final HomekitClientConnectionFactory homekitClientConnectionFactory; - - public AccessoryHandler(HomekitClientConnectionFactory homekitClientConnectionFactory) { - this.homekitClientConnectionFactory = homekitClientConnectionFactory; - } - - @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { - final Channel channel = ctx.pipeline().channel(); - this.connection = - homekitClientConnectionFactory.createConnection( - response -> { - if (!channel.isActive()) { - return; - } - channel.writeAndFlush(NettyResponseUtil.createResponse(response)); - }); - LOGGER.trace("New HomeKit connection from " + ctx.channel().remoteAddress().toString()); - super.channelActive(ctx); - } - - @Override - public void channelInactive(ChannelHandlerContext ctx) throws Exception { - LOGGER.trace("Terminated HomeKit connection from " + ctx.channel().remoteAddress().toString()); - super.channelInactive(ctx); - } - - @Override - public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest req) throws Exception { - try { - HttpResponse response = connection.handleRequest(new FullRequestHttpRequestImpl(req)); - if (response.doUpgrade()) { - ChannelPipeline pipeline = ctx.channel().pipeline(); - pipeline.addBefore( - ServerInitializer.HTTP_HANDLER_NAME, "binary", new BinaryHandler(connection)); - } - sendResponse(response, ctx); - } catch (Exception e) { - LOGGER.warn("Error handling homekit http request", e); - sendResponse(HttpResponseStatus.INTERNAL_SERVER_ERROR, "Error: " + e.getMessage(), ctx); - } - } - - private void sendResponse( - HttpResponseStatus status, String responseBody, ChannelHandlerContext ctx) { - if (responseBody == null) { - responseBody = ""; - } - FullHttpResponse response = - new DefaultFullHttpResponse( - HttpVersion.HTTP_1_1, - status, - Unpooled.copiedBuffer(responseBody.getBytes(StandardCharsets.UTF_8))); - response.headers().set(HttpHeaderNames.CONTENT_TYPE, "text/plain"); - response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes()); - response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); - ctx.write(response); - ctx.flush(); - } - - private void sendResponse(HttpResponse homekitResponse, ChannelHandlerContext ctx) { - FullHttpResponse response = NettyResponseUtil.createResponse(homekitResponse); - ctx.write(response); - ctx.flush(); - } - - @Override - public void channelReadComplete(ChannelHandlerContext ctx) throws Exception { - ctx.flush(); - super.channelReadComplete(ctx); - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - boolean errorLevel = !(cause instanceof IOException); - if (errorLevel) { - LOGGER.warn("Exception caught in web handler", cause); - } else { - LOGGER.debug("Exception caught in web handler", cause); - } - ctx.close(); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/http/impl/BinaryHandler.java b/src/main/java/io/github/hapjava/server/impl/http/impl/BinaryHandler.java deleted file mode 100644 index 4f4c80788..000000000 --- a/src/main/java/io/github/hapjava/server/impl/http/impl/BinaryHandler.java +++ /dev/null @@ -1,67 +0,0 @@ -package io.github.hapjava.server.impl.http.impl; - -import io.github.hapjava.server.impl.http.HomekitClientConnection; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageCodec; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class BinaryHandler extends ByteToMessageCodec { - - private static final Logger logger = LoggerFactory.getLogger(BinaryHandler.class); - - private final HomekitClientConnection connection; - private boolean started = false; - - public BinaryHandler(HomekitClientConnection connection) { - this.connection = connection; - } - - @Override - protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception { - if (started) { - debugData("Sending data", msg, ctx); - byte[] b = new byte[msg.readableBytes()]; - msg.readBytes(b); - out.writeBytes(connection.encryptResponse(b)); - } else { - out.writeBytes(msg); - } - } - - @Override - protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) throws Exception { - byte[] b = new byte[in.readableBytes()]; - in.readBytes(b); - byte[] decrypted = connection.decryptRequest(b); - ByteBuf outBuf = Unpooled.copiedBuffer(decrypted); - debugData("Received data", outBuf, ctx); - out.add(outBuf); - started = true; - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - boolean errorLevel = !(cause instanceof IOException); - if (errorLevel) { - logger.warn("Exception in binary handler", cause); - } else { - logger.debug("Exception in binary handler", cause); - } - super.exceptionCaught(ctx, cause); - } - - private void debugData(String msg, ByteBuf b, ChannelHandlerContext ctx) throws Exception { - if (logger.isDebugEnabled()) { - logger.debug( - String.format( - "%s [%s]:%n%s", - msg, ctx.channel().remoteAddress().toString(), b.toString(StandardCharsets.UTF_8))); - } - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/http/impl/DefaultHttpRequestImpl.java b/src/main/java/io/github/hapjava/server/impl/http/impl/DefaultHttpRequestImpl.java deleted file mode 100644 index a124705f1..000000000 --- a/src/main/java/io/github/hapjava/server/impl/http/impl/DefaultHttpRequestImpl.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.hapjava.server.impl.http.impl; - -import io.github.hapjava.server.impl.http.HttpMethod; -import io.github.hapjava.server.impl.http.HttpRequest; - -class DefaultHttpRequestImpl implements HttpRequest { - - private final io.netty.handler.codec.http.HttpRequest request; - - public DefaultHttpRequestImpl(io.netty.handler.codec.http.HttpRequest request) { - this.request = request; - } - - @Override - public String getUri() { - return request.uri(); - } - - @Override - public byte[] getBody() { - return new byte[0]; - } - - @Override - public HttpMethod getMethod() { - io.netty.handler.codec.http.HttpMethod method = request.method(); - if (method.equals(io.netty.handler.codec.http.HttpMethod.GET)) { - return HttpMethod.GET; - } else if (method.equals(io.netty.handler.codec.http.HttpMethod.POST)) { - return HttpMethod.POST; - } else if (method.equals(io.netty.handler.codec.http.HttpMethod.PUT)) { - return HttpMethod.PUT; - } else { - throw new RuntimeException("Unrecognized method: " + method.toString()); - } - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/http/impl/FullRequestHttpRequestImpl.java b/src/main/java/io/github/hapjava/server/impl/http/impl/FullRequestHttpRequestImpl.java deleted file mode 100644 index 088ec9832..000000000 --- a/src/main/java/io/github/hapjava/server/impl/http/impl/FullRequestHttpRequestImpl.java +++ /dev/null @@ -1,20 +0,0 @@ -package io.github.hapjava.server.impl.http.impl; - -import io.netty.handler.codec.http.FullHttpRequest; - -class FullRequestHttpRequestImpl extends DefaultHttpRequestImpl { - - private final FullHttpRequest nettyRequest; - - public FullRequestHttpRequestImpl(FullHttpRequest nettyRequest) { - super(nettyRequest); - this.nettyRequest = nettyRequest; - } - - @Override - public byte[] getBody() { - byte[] ret = new byte[nettyRequest.content().readableBytes()]; - nettyRequest.content().readBytes(ret); - return ret; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/http/impl/HomekitHttpServer.java b/src/main/java/io/github/hapjava/server/impl/http/impl/HomekitHttpServer.java deleted file mode 100644 index 085d632cf..000000000 --- a/src/main/java/io/github/hapjava/server/impl/http/impl/HomekitHttpServer.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.hapjava.server.impl.http.impl; - -import io.github.hapjava.server.HomekitWebHandler; -import io.github.hapjava.server.impl.http.HomekitClientConnectionFactory; -import java.net.InetAddress; -import java.util.concurrent.CompletableFuture; - -public class HomekitHttpServer implements HomekitWebHandler { - - private NettyHomekitHttpService service = null; - private final InetAddress localAddress; - private final int port; - private final int nThreads; - - @Override - public void stop() { - if (this.service != null) { - this.service.shutdown(); - } - } - - public HomekitHttpServer(InetAddress localAddress, int port, int nThreads) { - this.localAddress = localAddress; - this.port = port; - this.nThreads = nThreads; - } - - @Override - public CompletableFuture start(HomekitClientConnectionFactory clientConnectionFactory) { - if (service == null) { - this.service = NettyHomekitHttpService.create(localAddress, port, nThreads); - return this.service.create(clientConnectionFactory); - } else { - throw new RuntimeException("HomekitHttpServer can only be started once"); - } - } - - @Override - public void resetConnections() { - service.resetConnections(); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/http/impl/HttpResponseEncoderAggregate.java b/src/main/java/io/github/hapjava/server/impl/http/impl/HttpResponseEncoderAggregate.java deleted file mode 100644 index 96aee2fe7..000000000 --- a/src/main/java/io/github/hapjava/server/impl/http/impl/HttpResponseEncoderAggregate.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.github.hapjava.server.impl.http.impl; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.http.HttpResponseEncoder; -import java.util.Iterator; -import java.util.List; - -public class HttpResponseEncoderAggregate extends HttpResponseEncoder { - - @Override - protected void encode(ChannelHandlerContext ctx, Object msg, List out) throws Exception { - super.encode(ctx, msg, out); - if (out.size() > 0) { - Iterator i = out.iterator(); - ByteBuf b = (ByteBuf) i.next(); - while (i.hasNext()) { - b.writeBytes((ByteBuf) i.next()); - i.remove(); - } - } - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/http/impl/LoggingHandler.java b/src/main/java/io/github/hapjava/server/impl/http/impl/LoggingHandler.java deleted file mode 100644 index 5b271dc24..000000000 --- a/src/main/java/io/github/hapjava/server/impl/http/impl/LoggingHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -package io.github.hapjava.server.impl.http.impl; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.*; -import java.io.IOException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class LoggingHandler extends ChannelDuplexHandler { - - private static final Logger logger = LoggerFactory.getLogger(LoggingHandler.class); - private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray(); - - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - if (logger.isTraceEnabled() && msg instanceof ByteBuf) { - logBytes("READ", (ByteBuf) msg, ctx); - } - super.channelRead(ctx, msg); - } - - @Override - public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) - throws Exception { - if (logger.isTraceEnabled() && msg instanceof ByteBuf) { - logBytes("WRITE", (ByteBuf) msg, ctx); - } - super.write(ctx, msg, promise); - } - - private void logBytes(String type, ByteBuf buf, ChannelHandlerContext ctx) throws IOException { - if (buf.readableBytes() > 0) { - byte[] bytes = new byte[buf.readableBytes()]; - buf.getBytes(0, bytes, 0, bytes.length); - logger.trace( - String.format( - "%s %s [%s]:%n%s%n", - type, buf, ctx.channel().remoteAddress().toString(), bytesToHex(bytes))); - } - } - - /* - This method is licensed under CC-BY-SA and published on Stackoverflow - https://stackoverflow.com/questions/9655181/how-to-convert-a-byte-array-to-a-hex-string-in-java - from the answer by Melquiades https://stackoverflow.com/users/2964945/melquiades - */ - private String bytesToHex(byte[] bytes) { - char[] hexChars = new char[bytes.length * 2]; - for (int j = 0; j < bytes.length; j++) { - int v = bytes[j] & 0xFF; - hexChars[j * 2] = HEX_ARRAY[v >>> 4]; - hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F]; - } - return new String(hexChars); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/http/impl/NettyHomekitHttpService.java b/src/main/java/io/github/hapjava/server/impl/http/impl/NettyHomekitHttpService.java deleted file mode 100644 index aad5d5a13..000000000 --- a/src/main/java/io/github/hapjava/server/impl/http/impl/NettyHomekitHttpService.java +++ /dev/null @@ -1,85 +0,0 @@ -package io.github.hapjava.server.impl.http.impl; - -import io.github.hapjava.server.impl.http.HomekitClientConnectionFactory; -import io.netty.bootstrap.ServerBootstrap; -import io.netty.channel.*; -import io.netty.channel.group.ChannelGroup; -import io.netty.channel.group.DefaultChannelGroup; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.nio.NioServerSocketChannel; -import io.netty.handler.logging.LogLevel; -import io.netty.handler.logging.LoggingHandler; -import io.netty.util.concurrent.*; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.concurrent.CompletableFuture; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -class NettyHomekitHttpService { - - private final EventLoopGroup bossGroup; - private final EventLoopGroup workerGroup; - - private static final Logger logger = LoggerFactory.getLogger(NettyHomekitHttpService.class); - private final ChannelGroup allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); - private final InetAddress localAddress; - private final int port; - private final int nThreads; - - public static NettyHomekitHttpService create(InetAddress localAddress, int port, int nThreads) { - return new NettyHomekitHttpService(localAddress, port, nThreads); - } - - private NettyHomekitHttpService(InetAddress localAddress, int port, int nThreads) { - bossGroup = new NioEventLoopGroup(); - workerGroup = new NioEventLoopGroup(); - this.localAddress = localAddress; - this.port = port; - this.nThreads = nThreads; - } - - public CompletableFuture create(HomekitClientConnectionFactory connectionFactory) { - final CompletableFuture portFuture = new CompletableFuture(); - ServerBootstrap b = new ServerBootstrap(); - b.group(bossGroup, workerGroup) - .channel(NioServerSocketChannel.class) - .handler(new LoggingHandler(LogLevel.INFO)) - .childHandler(new ServerInitializer(connectionFactory, allChannels, nThreads)) - .option(ChannelOption.SO_BACKLOG, 128) - .childOption(ChannelOption.SO_KEEPALIVE, true); - final ChannelFuture bindFuture = b.bind(localAddress, port); - bindFuture.addListener( - new GenericFutureListener>() { - - @Override - public void operationComplete(Future future) throws Exception { - try { - future.get(); - SocketAddress socketAddress = bindFuture.channel().localAddress(); - if (socketAddress instanceof InetSocketAddress) { - logger.trace("Bound homekit listener to " + socketAddress.toString()); - portFuture.complete(((InetSocketAddress) socketAddress).getPort()); - } else { - throw new RuntimeException( - "Unknown socket address type: " + socketAddress.getClass().getName()); - } - } catch (Exception e) { - portFuture.completeExceptionally(e); - } - } - }); - return portFuture; - } - - public void shutdown() { - workerGroup.shutdownGracefully(); - bossGroup.shutdownGracefully(); - } - - public void resetConnections() { - logger.trace("Resetting connections"); - allChannels.close(); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/http/impl/NettyResponseUtil.java b/src/main/java/io/github/hapjava/server/impl/http/impl/NettyResponseUtil.java deleted file mode 100644 index 9e7963fb3..000000000 --- a/src/main/java/io/github/hapjava/server/impl/http/impl/NettyResponseUtil.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.github.hapjava.server.impl.http.impl; - -import io.github.hapjava.server.impl.http.HttpResponse; -import io.netty.buffer.Unpooled; -import io.netty.handler.codec.http.DefaultFullHttpResponse; -import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http.HttpHeaderNames; -import io.netty.handler.codec.http.HttpHeaderValues; -import io.netty.handler.codec.http.HttpResponseStatus; -import io.netty.handler.codec.http.HttpVersion; -import java.util.Map.Entry; - -class NettyResponseUtil { - - private static final HttpVersion EVENT_VERSION = new HttpVersion("EVENT", 1, 0, true); - - public static FullHttpResponse createResponse(HttpResponse homekitResponse) { - - FullHttpResponse response = - new DefaultFullHttpResponse( - homekitResponse.getVersion() == HttpResponse.HttpVersion.EVENT_1_0 - ? EVENT_VERSION - : HttpVersion.HTTP_1_1, - HttpResponseStatus.valueOf(homekitResponse.getStatusCode()), - Unpooled.copiedBuffer(homekitResponse.getBody())); - for (Entry header : homekitResponse.getHeaders().entrySet()) { - response.headers().add(header.getKey(), header.getValue()); - } - response.headers().set(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes()); - response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); - return response; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/http/impl/ServerInitializer.java b/src/main/java/io/github/hapjava/server/impl/http/impl/ServerInitializer.java deleted file mode 100644 index 3c914ffe7..000000000 --- a/src/main/java/io/github/hapjava/server/impl/http/impl/ServerInitializer.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.github.hapjava.server.impl.http.impl; - -import io.github.hapjava.server.impl.http.HomekitClientConnectionFactory; -import io.netty.channel.ChannelInitializer; -import io.netty.channel.ChannelPipeline; -import io.netty.channel.group.ChannelGroup; -import io.netty.channel.socket.SocketChannel; -import io.netty.handler.codec.http.HttpObjectAggregator; -import io.netty.handler.codec.http.HttpRequestDecoder; -import io.netty.util.concurrent.DefaultEventExecutorGroup; -import io.netty.util.concurrent.EventExecutorGroup; - -class ServerInitializer extends ChannelInitializer { - - private static final int MAX_POST = 1000000; - - public static final String HTTP_HANDLER_NAME = "http"; - - private final HomekitClientConnectionFactory homekit; - private final ChannelGroup allChannels; - private final EventExecutorGroup blockingExecutorGroup; - - public ServerInitializer( - HomekitClientConnectionFactory homekit, ChannelGroup allChannels, int nThreads) { - this.homekit = homekit; - this.allChannels = allChannels; - this.blockingExecutorGroup = new DefaultEventExecutorGroup(nThreads); - } - - @Override - protected void initChannel(SocketChannel ch) throws Exception { - ChannelPipeline pipeline = ch.pipeline(); - pipeline.addLast(new LoggingHandler()); - pipeline.addLast(HTTP_HANDLER_NAME, new HttpResponseEncoderAggregate()); - pipeline.addLast(new HttpRequestDecoder()); - pipeline.addLast(new HttpObjectAggregator(MAX_POST)); - pipeline.addLast(blockingExecutorGroup, new AccessoryHandler(homekit)); - allChannels.add(ch); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java b/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java deleted file mode 100644 index 9086acb3e..000000000 --- a/src/main/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiser.java +++ /dev/null @@ -1,136 +0,0 @@ -package io.github.hapjava.server.impl.jmdns; - -import static io.github.hapjava.server.impl.crypto.HAPSetupCodeUtils.generateSHA512Hash; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.UnknownHostException; -import java.util.HashMap; -import java.util.Map; -import javax.jmdns.JmDNS; -import javax.jmdns.ServiceInfo; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class JmdnsHomekitAdvertiser { - - private static final String SERVICE_TYPE = "_hap._tcp.local."; - - private final JmDNS jmdns; - private boolean discoverable = true; - private static final Logger logger = LoggerFactory.getLogger(JmdnsHomekitAdvertiser.class); - private boolean isAdvertising = false; - - private String label; - private String mac; - private String setupId; - private int port; - private int configurationIndex; - private ServiceInfo serviceInfo; - private int category; - - public JmdnsHomekitAdvertiser(JmDNS jmdns) { - this.jmdns = jmdns; - } - - public JmdnsHomekitAdvertiser(InetAddress localAddress) throws UnknownHostException, IOException { - jmdns = JmDNS.create(localAddress); - } - - public synchronized void advertise( - String label, int category, String mac, int port, int configurationIndex, String setupId) - throws Exception { - if (isAdvertising) { - throw new IllegalStateException("HomeKit advertiser is already running"); - } - this.label = label; - this.mac = mac; - this.port = port; - this.setupId = setupId; - this.category = category; - this.configurationIndex = configurationIndex; - - logger.trace("Advertising accessory " + label); - - registerService(); - - Runtime.getRuntime() - .addShutdownHook( - new Thread( - () -> { - logger.trace("Stopping advertising in response to shutdown."); - jmdns.unregisterAllServices(); - })); - isAdvertising = true; - } - - public synchronized void stop() { - unregisterService(); - } - - public synchronized void setDiscoverable(boolean discoverable) throws IOException { - if (this.discoverable != discoverable) { - this.discoverable = discoverable; - if (isAdvertising) { - logger.trace("Re-creating service due to change in discoverability to " + discoverable); - unregisterService(); - registerService(); - } - } - } - - public synchronized void setMac(String mac) throws IOException { - if (this.mac != mac) { - this.mac = mac; - if (isAdvertising) { - logger.trace("Re-creating service due to change in mac to " + mac); - unregisterService(); - registerService(); - } - } - } - - public synchronized void setConfigurationIndex(int revision) throws IOException { - if (this.configurationIndex != revision) { - this.configurationIndex = revision; - if (isAdvertising) { - logger.trace("Re-creating service due to change in configuration index to " + revision); - unregisterService(); - registerService(); - } - } - } - - private void unregisterService() { - if (serviceInfo != null) { - jmdns.unregisterService(serviceInfo); - serviceInfo = null; - } - } - - private void registerService() throws IOException { - logger.info("Registering " + SERVICE_TYPE + " on port " + port); - if (this.serviceInfo != null) { - throw new AssertionError( - "Registering an already registered service without unregistering first is not allowed"); - } - serviceInfo = buildServiceInfo(); - jmdns.registerService(serviceInfo); - } - - private ServiceInfo buildServiceInfo() { - logger.trace("MAC:" + mac + " Setup Id:" + setupId); - Map props = new HashMap<>(); - props.put("sf", discoverable ? "1" : "0"); - props.put("id", mac); - props.put("md", label); - props.put("sh", generateSHA512Hash(setupId + mac)); - props.put("c#", Integer.toString(configurationIndex)); - props.put("s#", "1"); - props.put("ff", "0"); - props.put("ci", Integer.toString(category)); - props.put("pv", "1.1"); - - return ServiceInfo.create(SERVICE_TYPE, label, port, 1, 1, props); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/json/AccessoryController.java b/src/main/java/io/github/hapjava/server/impl/json/AccessoryController.java deleted file mode 100644 index fdd223ec3..000000000 --- a/src/main/java/io/github/hapjava/server/impl/json/AccessoryController.java +++ /dev/null @@ -1,114 +0,0 @@ -package io.github.hapjava.server.impl.json; - -import io.github.hapjava.accessories.HomekitAccessory; -import io.github.hapjava.characteristics.Characteristic; -import io.github.hapjava.server.impl.HomekitRegistry; -import io.github.hapjava.server.impl.http.HttpResponse; -import io.github.hapjava.services.Service; -import java.io.ByteArrayOutputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.concurrent.CompletableFuture; -import java.util.stream.Collectors; -import javax.json.Json; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import javax.json.JsonWriter; - -public class AccessoryController { - - private final HomekitRegistry registry; - - public AccessoryController(HomekitRegistry registry) { - this.registry = registry; - } - - public HttpResponse listing() throws Exception { - JsonArrayBuilder accessories = Json.createArrayBuilder(); - - Map>> accessoryServiceFutures = new HashMap<>(); - for (HomekitAccessory accessory : registry.getAccessories()) { - List> serviceFutures = new ArrayList<>(); - - Map servicesByInterfaceId = registry.getServices(accessory.getId()); - - Map iidLookup = new HashMap<>(); - iidLookup.putAll(swapKeyAndValue(servicesByInterfaceId)); - iidLookup.putAll(swapKeyAndValue(registry.getCharacteristics(accessory.getId()))); - - for (Service service : servicesByInterfaceId.values()) { - serviceFutures.add(toJson(service, iidLookup, accessory.getPrimaryService() == service)); - } - - accessoryServiceFutures.put(accessory.getId(), serviceFutures); - } - - Map serviceArrayBuilders = new HashMap<>(); - for (Entry>> entry : - accessoryServiceFutures.entrySet()) { - JsonArrayBuilder arr = Json.createArrayBuilder(); - for (CompletableFuture future : entry.getValue()) { - arr.add(future.join()); - } - serviceArrayBuilders.put(entry.getKey(), arr); - } - - for (HomekitAccessory accessory : registry.getAccessories()) { - accessories.add( - Json.createObjectBuilder() - .add("aid", accessory.getId()) - .add("services", serviceArrayBuilders.get(accessory.getId()))); - } - - try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); - JsonWriter jsonWriter = Json.createWriter(baos)) { - jsonWriter.write(Json.createObjectBuilder().add("accessories", accessories).build()); - return new HapJsonResponse(baos.toByteArray()); - } - } - - private CompletableFuture toJson( - Service service, Map iidLookup, boolean isPrimary) throws Exception { - String shortType = - service.getType().replaceAll("^0*([0-9a-fA-F]+)-0000-1000-8000-0026BB765291$", "$1"); - JsonObjectBuilder builder = - Json.createObjectBuilder().add("iid", iidLookup.get(service)).add("type", shortType); - List characteristics = service.getCharacteristics(); - Collection> characteristicFutures = - new ArrayList<>(characteristics.size()); - for (Characteristic characteristic : characteristics) { - Integer iid = iidLookup.get(characteristic); - characteristicFutures.add(characteristic.toJson(iid)); - } - - return CompletableFuture.allOf( - characteristicFutures.toArray(new CompletableFuture[characteristicFutures.size()])) - .thenApply( - v -> { - JsonArrayBuilder jsonCharacteristics = Json.createArrayBuilder(); - characteristicFutures.stream() - .map(future -> future.join()) - .forEach(c -> jsonCharacteristics.add(c)); - builder.add("characteristics", jsonCharacteristics); - - if (!service.getLinkedServices().isEmpty()) { - JsonArrayBuilder jsonLinkedServices = Json.createArrayBuilder(); - service.getLinkedServices().stream() - .map(iidLookup::get) - .forEach(jsonLinkedServices::add); - builder.add("linked", jsonLinkedServices); - } - builder.add("primary", isPrimary); - return builder.build(); - }); - } - - private Map swapKeyAndValue(Map map) { - return map.entrySet().stream().collect(Collectors.toMap(Entry::getValue, Entry::getKey)); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/json/CharacteristicsController.java b/src/main/java/io/github/hapjava/server/impl/json/CharacteristicsController.java deleted file mode 100644 index f5f8bb87c..000000000 --- a/src/main/java/io/github/hapjava/server/impl/json/CharacteristicsController.java +++ /dev/null @@ -1,111 +0,0 @@ -package io.github.hapjava.server.impl.json; - -import io.github.hapjava.characteristics.Characteristic; -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.server.impl.HomekitRegistry; -import io.github.hapjava.server.impl.connections.SubscriptionManager; -import io.github.hapjava.server.impl.http.HomekitClientConnection; -import io.github.hapjava.server.impl.http.HttpRequest; -import io.github.hapjava.server.impl.http.HttpResponse; -import io.github.hapjava.server.impl.responses.NotFoundResponse; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.util.Map; -import javax.json.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class CharacteristicsController { - - Logger logger = LoggerFactory.getLogger(CharacteristicsController.class); - - private final HomekitRegistry registry; - private final SubscriptionManager subscriptions; - - public CharacteristicsController(HomekitRegistry registry, SubscriptionManager subscriptions) { - this.registry = registry; - this.subscriptions = subscriptions; - } - - public HttpResponse get(HttpRequest request) throws Exception { - String uri = request.getUri(); - // Characteristics are requested with /characteristics?id=1.1,2.1,3.1 - String query = uri.substring("/characteristics?id=".length()); - String[] ids = query.split(","); - JsonArrayBuilder characteristics = Json.createArrayBuilder(); - for (String id : ids) { - String[] parts = id.split("\\."); - if (parts.length != 2) { - logger.warn("Unexpected characteristics request: " + uri); - return new NotFoundResponse(); - } - int aid = Integer.parseInt(parts[0]); - int iid = Integer.parseInt(parts[1]); - JsonObjectBuilder characteristic = Json.createObjectBuilder(); - Map characteristicMap = registry.getCharacteristics(aid); - if (!characteristicMap.isEmpty()) { - Characteristic targetCharacteristic = characteristicMap.get(iid); - if (targetCharacteristic != null) { - targetCharacteristic.supplyValue(characteristic); - - characteristics.add(characteristic.add("aid", aid).add("iid", iid).build()); - } else { - logger.warn( - "Accessory " + aid + " does not have characteristic " + iid + ". Request: " + uri); - } - } else { - logger.warn( - "Accessory " + aid + " has no characteristics or does not exist. Request: " + uri); - } - } - try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); - JsonWriter jsonWriter = Json.createWriter(baos)) { - jsonWriter.write( - Json.createObjectBuilder().add("characteristics", characteristics.build()).build()); - return new HapJsonResponse(baos.toByteArray()); - } - } - - public HttpResponse put(HttpRequest request, HomekitClientConnection connection) - throws Exception { - subscriptions.batchUpdate(); - try { - try (ByteArrayInputStream bais = new ByteArrayInputStream(request.getBody())) { - JsonArray jsonCharacteristics = - Json.createReader(bais).readObject().getJsonArray("characteristics"); - for (JsonValue value : jsonCharacteristics) { - JsonObject jsonCharacteristic = (JsonObject) value; - int aid = jsonCharacteristic.getInt("aid"); - int iid = jsonCharacteristic.getInt("iid"); - Map accessory = registry.getCharacteristics(aid); - if (accessory.isEmpty()) { - logger.warn("Accessory {} has no characteristics or does not exist.", aid); - return new HapJsonNoContentResponse(); - } - Characteristic characteristic = accessory.get(iid); - if (characteristic == null) { - logger.warn("Accessory {} does not have characteristic {}.", aid, iid); - return new HapJsonNoContentResponse(); - } - - if (jsonCharacteristic.containsKey("value")) { - characteristic.setValue(jsonCharacteristic.get("value"), connection.getUsername()); - } - if (jsonCharacteristic.containsKey("ev") - && characteristic instanceof EventableCharacteristic) { - if (jsonCharacteristic.getBoolean("ev")) { - subscriptions.addSubscription( - aid, iid, (EventableCharacteristic) characteristic, connection); - } else { - subscriptions.removeSubscription( - (EventableCharacteristic) characteristic, connection); - } - } - } - } - } finally { - subscriptions.completeUpdateBatch(); - } - return new HapJsonNoContentResponse(); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/json/EventController.java b/src/main/java/io/github/hapjava/server/impl/json/EventController.java deleted file mode 100644 index 0c7c2bc7c..000000000 --- a/src/main/java/io/github/hapjava/server/impl/json/EventController.java +++ /dev/null @@ -1,57 +0,0 @@ -package io.github.hapjava.server.impl.json; - -import io.github.hapjava.characteristics.EventableCharacteristic; -import io.github.hapjava.server.impl.connections.PendingNotification; -import io.github.hapjava.server.impl.http.HttpResponse; -import java.io.ByteArrayOutputStream; -import java.util.List; -import javax.json.Json; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; -import javax.json.JsonWriter; - -public class EventController { - - public HttpResponse getMessage(int accessoryId, int iid, EventableCharacteristic changed) - throws Exception { - JsonArrayBuilder characteristics = Json.createArrayBuilder(); - - JsonObjectBuilder characteristicBuilder = Json.createObjectBuilder(); - characteristicBuilder.add("aid", accessoryId); - characteristicBuilder.add("iid", iid); - changed.supplyValue(characteristicBuilder); - characteristics.add(characteristicBuilder.build()); - - JsonObject data = Json.createObjectBuilder().add("characteristics", characteristics).build(); - - try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); - JsonWriter jsonWriter = Json.createWriter(baos)) { - jsonWriter.write(data); - byte[] dataBytes = baos.toByteArray(); - - return new EventResponse(dataBytes); - } - } - - public HttpResponse getMessage(List notifications) throws Exception { - JsonArrayBuilder characteristics = Json.createArrayBuilder(); - - for (PendingNotification notification : notifications) { - JsonObjectBuilder characteristicBuilder = Json.createObjectBuilder(); - characteristicBuilder.add("aid", notification.aid); - characteristicBuilder.add("iid", notification.iid); - notification.characteristic.supplyValue(characteristicBuilder); - characteristics.add(characteristicBuilder.build()); - } - - JsonObject data = Json.createObjectBuilder().add("characteristics", characteristics).build(); - try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); - JsonWriter jsonWriter = Json.createWriter(baos)) { - jsonWriter.write(data); - byte[] dataBytes = baos.toByteArray(); - - return new EventResponse(dataBytes); - } - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/json/EventResponse.java b/src/main/java/io/github/hapjava/server/impl/json/EventResponse.java deleted file mode 100644 index 113582c5b..000000000 --- a/src/main/java/io/github/hapjava/server/impl/json/EventResponse.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.github.hapjava.server.impl.json; - -public class EventResponse extends HapJsonResponse { - - public EventResponse(byte[] body) { - super(body); - } - - @Override - public HttpVersion getVersion() { - return HttpVersion.EVENT_1_0; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/json/HapJsonNoContentResponse.java b/src/main/java/io/github/hapjava/server/impl/json/HapJsonNoContentResponse.java deleted file mode 100644 index be01ebbe3..000000000 --- a/src/main/java/io/github/hapjava/server/impl/json/HapJsonNoContentResponse.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.github.hapjava.server.impl.json; - -class HapJsonNoContentResponse extends HapJsonResponse { - - public HapJsonNoContentResponse() { - super(new byte[0]); - } - - @Override - public int getStatusCode() { - return 204; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/json/HapJsonResponse.java b/src/main/java/io/github/hapjava/server/impl/json/HapJsonResponse.java deleted file mode 100644 index dbbe7cada..000000000 --- a/src/main/java/io/github/hapjava/server/impl/json/HapJsonResponse.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.hapjava.server.impl.json; - -import io.github.hapjava.server.impl.responses.OkResponse; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -class HapJsonResponse extends OkResponse { - - private static final Map headers = - Collections.unmodifiableMap( - new HashMap() { - private static final long serialVersionUID = 1L; - - { - put("Content-type", "application/hap+json"); - } - }); - - public HapJsonResponse(byte[] body) { - super(body); - } - - @Override - public Map getHeaders() { - return headers; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/ByteUtils.java b/src/main/java/io/github/hapjava/server/impl/pairing/ByteUtils.java deleted file mode 100644 index 6516e2e29..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/ByteUtils.java +++ /dev/null @@ -1,43 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.math.BigInteger; -import java.util.Arrays; - -class ByteUtils { - - public static byte[] joinBytes(byte[]... piece) { - int pos = 0; - int length = 0; - for (int i = 0; i < piece.length; i++) { - length += piece[i].length; - } - byte[] ret = new byte[length]; - for (int i = 0; i < piece.length; i++) { - System.arraycopy(piece[i], 0, ret, pos, piece[i].length); - pos += piece[i].length; - } - return ret; - } - - public static byte[] toByteArray(BigInteger i) { - byte[] array = i.toByteArray(); - if (array[0] == 0) { - array = Arrays.copyOfRange(array, 1, array.length); - } - return array; - } - - public static void copyStream(InputStream input, OutputStream output, int length) - throws IOException { - byte[] buffer = new byte[length]; - int remaining = length; - int bytesRead; - while ((bytesRead = input.read(buffer, 0, remaining)) != -1 && remaining > 0) { - output.write(buffer, 0, bytesRead); - remaining -= bytesRead; - } - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/ClientEvidenceRoutineImpl.java b/src/main/java/io/github/hapjava/server/impl/pairing/ClientEvidenceRoutineImpl.java deleted file mode 100644 index 16c514707..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/ClientEvidenceRoutineImpl.java +++ /dev/null @@ -1,61 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -import com.nimbusds.srp6.*; -import java.math.BigInteger; -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -class ClientEvidenceRoutineImpl implements ClientEvidenceRoutine { - - public ClientEvidenceRoutineImpl() { - // TODO Auto-generated constructor stub - } - - /** - * Calculates M1 according to the following formula: - * - *

M1 = H(H(N) xor H(g) || H(username) || s || A || B || H(S)) - */ - @Override - public BigInteger computeClientEvidence( - SRP6CryptoParams cryptoParams, SRP6ClientEvidenceContext ctx) { - - MessageDigest digest; - try { - digest = MessageDigest.getInstance(cryptoParams.H); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("Could not locate requested algorithm", e); - } - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(cryptoParams.N)); - byte[] hN = digest.digest(); - - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(cryptoParams.g)); - byte[] hg = digest.digest(); - - byte[] hNhg = xor(hN, hg); - - digest.update(ctx.userID.getBytes(StandardCharsets.UTF_8)); - byte[] hu = digest.digest(); - - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(ctx.S)); - byte[] hS = digest.digest(); - - digest.update(hNhg); - digest.update(hu); - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(ctx.s)); - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(ctx.A)); - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(ctx.B)); - digest.update(hS); - BigInteger ret = new BigInteger(1, digest.digest()); - return ret; - } - - private static byte[] xor(byte[] b1, byte[] b2) { - byte[] result = new byte[b1.length]; - for (int i = 0; i < b1.length; i++) { - result[i] = (byte) (b1[i] ^ b2[i]); - } - return result; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/ErrorCode.java b/src/main/java/io/github/hapjava/server/impl/pairing/ErrorCode.java deleted file mode 100644 index 90112fc46..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/ErrorCode.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -public enum ErrorCode { - OK(0), - UNKNOWN(1), - AUTHENTICATION(2), - BACKOFF(3), - MAX_PEERS(4), - MAX_TRIES(5), - UNAVAILABLE(6), - BUSY(7); - - private final short key; - - ErrorCode(short key) { - this.key = key; - } - - ErrorCode(int key) { - this.key = (short) key; - } - - public short getKey() { - return key; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/ExchangeHandler.java b/src/main/java/io/github/hapjava/server/impl/pairing/ExchangeHandler.java deleted file mode 100755 index 4b7c3eb11..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/ExchangeHandler.java +++ /dev/null @@ -1,136 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -import io.github.hapjava.server.HomekitAuthInfo; -import io.github.hapjava.server.impl.crypto.ChachaDecoder; -import io.github.hapjava.server.impl.crypto.ChachaEncoder; -import io.github.hapjava.server.impl.crypto.EdsaSigner; -import io.github.hapjava.server.impl.crypto.EdsaVerifier; -import io.github.hapjava.server.impl.http.HttpResponse; -import io.github.hapjava.server.impl.pairing.PairSetupRequest.ExchangeRequest; -import io.github.hapjava.server.impl.pairing.TypeLengthValueUtils.DecodeResult; -import io.github.hapjava.server.impl.pairing.TypeLengthValueUtils.Encoder; -import java.nio.charset.StandardCharsets; -import org.bouncycastle.crypto.digests.SHA512Digest; -import org.bouncycastle.crypto.generators.HKDFBytesGenerator; -import org.bouncycastle.crypto.params.HKDFParameters; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -class ExchangeHandler { - - private final byte[] k; - private final HomekitAuthInfo authInfo; - - private byte[] hkdf_enc_key; - - private static final Logger LOGGER = LoggerFactory.getLogger(ExchangeHandler.class); - - public ExchangeHandler(byte[] k, HomekitAuthInfo authInfo) { - this.k = k; - this.authInfo = authInfo; - } - - public HttpResponse handle(PairSetupRequest req) throws Exception { - LOGGER.debug("ExchangeHandler: Starting M5 exchange with shared secret K: {}", bytesToHex(k)); - - HKDFBytesGenerator hkdf = new HKDFBytesGenerator(new SHA512Digest()); - hkdf.init( - new HKDFParameters( - k, - "Pair-Setup-Encrypt-Salt".getBytes(StandardCharsets.UTF_8), - "Pair-Setup-Encrypt-Info".getBytes(StandardCharsets.UTF_8))); - byte[] okm = hkdf_enc_key = new byte[32]; - hkdf.generateBytes(okm, 0, 32); - - LOGGER.debug("ExchangeHandler: HKDF encryption key: {}", bytesToHex(okm)); - - return decrypt((ExchangeRequest) req, okm); - } - - private HttpResponse decrypt(ExchangeRequest req, byte[] key) throws Exception { - LOGGER.debug("ExchangeHandler: Received AuthTag: {}", bytesToHex(req.getAuthTagData())); - LOGGER.debug("ExchangeHandler: Received MessageData: {}", bytesToHex(req.getMessageData())); - - try { - ChachaDecoder chacha = new ChachaDecoder(key, "PS-Msg05".getBytes(StandardCharsets.UTF_8)); - byte[] plaintext = chacha.decodeCiphertext(req.getAuthTagData(), req.getMessageData()); - return processDecryptedData(plaintext); - } catch (Exception e) { - LOGGER.error("ExchangeHandler: M5 decryption failed: {}", e.getMessage()); - throw new RuntimeException("HomeKit M5 message decryption failed", e); - } - } - - private HttpResponse processDecryptedData(byte[] plaintext) throws Exception { - - DecodeResult d = TypeLengthValueUtils.decode(plaintext); - byte[] username = d.getBytes(MessageType.USERNAME); - byte[] ltpk = d.getBytes(MessageType.PUBLIC_KEY); - byte[] proof = d.getBytes(MessageType.SIGNATURE); - return createUser(username, ltpk, proof); - } - - private static String bytesToHex(byte[] bytes) { - StringBuilder result = new StringBuilder(); - for (byte b : bytes) { - result.append(String.format("%02x", b)); - } - return result.toString(); - } - - private HttpResponse createUser(byte[] username, byte[] ltpk, byte[] proof) throws Exception { - HKDFBytesGenerator hkdf = new HKDFBytesGenerator(new SHA512Digest()); - hkdf.init( - new HKDFParameters( - k, - "Pair-Setup-Controller-Sign-Salt".getBytes(StandardCharsets.UTF_8), - "Pair-Setup-Controller-Sign-Info".getBytes(StandardCharsets.UTF_8))); - byte[] okm = new byte[32]; - hkdf.generateBytes(okm, 0, 32); - - byte[] completeData = ByteUtils.joinBytes(okm, username, ltpk); - - if (!new EdsaVerifier(ltpk).verify(completeData, proof)) { - return new PairingResponse(6, ErrorCode.AUTHENTICATION); - } - String stringUsername = new String(username, StandardCharsets.UTF_8); - LOGGER.trace("Creating initial user {}", stringUsername); - authInfo.createUser(authInfo.getMac() + stringUsername, ltpk, true); - return createResponse(); - } - - private HttpResponse createResponse() throws Exception { - HKDFBytesGenerator hkdf = new HKDFBytesGenerator(new SHA512Digest()); - hkdf.init( - new HKDFParameters( - k, - "Pair-Setup-Accessory-Sign-Salt".getBytes(StandardCharsets.UTF_8), - "Pair-Setup-Accessory-Sign-Info".getBytes(StandardCharsets.UTF_8))); - byte[] okm = new byte[32]; - hkdf.generateBytes(okm, 0, 32); - - EdsaSigner signer = new EdsaSigner(authInfo.getPrivateKey()); - - byte[] material = - ByteUtils.joinBytes( - okm, authInfo.getMac().getBytes(StandardCharsets.UTF_8), signer.getPublicKey()); - - byte[] proof = signer.sign(material); - - Encoder encoder = TypeLengthValueUtils.getEncoder(); - encoder.add(MessageType.USERNAME, authInfo.getMac().getBytes(StandardCharsets.UTF_8)); - encoder.add(MessageType.PUBLIC_KEY, signer.getPublicKey()); - encoder.add(MessageType.SIGNATURE, proof); - byte[] plaintext = encoder.toByteArray(); - - ChachaEncoder chacha = - new ChachaEncoder(hkdf_enc_key, "PS-Msg06".getBytes(StandardCharsets.UTF_8)); - byte[] ciphertext = chacha.encodeCiphertext(plaintext); - - encoder = TypeLengthValueUtils.getEncoder(); - encoder.add(MessageType.STATE, (short) 6); - encoder.add(MessageType.ENCRYPTED_DATA, ciphertext); - - return new PairingResponse(encoder.toByteArray()); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/HomekitSRP6Routines.java b/src/main/java/io/github/hapjava/server/impl/pairing/HomekitSRP6Routines.java deleted file mode 100644 index 44417a91f..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/HomekitSRP6Routines.java +++ /dev/null @@ -1,58 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -import java.math.BigInteger; -import java.security.SecureRandom; - -/** - * This class is modified from the nimbus SRP library to provide methods that are compatible with - * some pecularities of HomeKit. Namely, the need for a 3072 bit private value - * - * @author Vladimir Dzhuvinov - */ -public class HomekitSRP6Routines { - - public static BigInteger generatePrivateValue(BigInteger N, SecureRandom random) { - final int minBits = Math.min(3072, N.bitLength() / 2); - - BigInteger min = BigInteger.ONE.shiftLeft(minBits - 1); - BigInteger max = N.subtract(BigInteger.ONE); - - return createRandomBigIntegerInRange(min, max, random); - } - - /** - * Returns a random big integer in the specified range [min, max]. - * - * @param min The least value that may be generated. Must not be {@code null}. - * @param max The greatest value that may be generated. Must not be {@code null}. - * @param random Source of randomness. Must not be {@code null}. - * @return A random big integer in the range [min, max]. - */ - protected static BigInteger createRandomBigIntegerInRange( - final BigInteger min, final BigInteger max, final SecureRandom random) { - - final int cmp = min.compareTo(max); - - if (cmp >= 0) { - - if (cmp > 0) throw new IllegalArgumentException("'min' may not be greater than 'max'"); - - return min; - } - - if (min.bitLength() > max.bitLength() / 2) - return createRandomBigIntegerInRange(BigInteger.ZERO, max.subtract(min), random).add(min); - - final int MAX_ITERATIONS = 1000; - - for (int i = 0; i < MAX_ITERATIONS; ++i) { - - BigInteger x = new BigInteger(max.bitLength(), random); - - if (x.compareTo(min) >= 0 && x.compareTo(max) <= 0) return x; - } - - // fall back to a faster (restricted) method - return new BigInteger(max.subtract(min).bitLength() - 1, random).add(min); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/HomekitSRP6ServerSession.java b/src/main/java/io/github/hapjava/server/impl/pairing/HomekitSRP6ServerSession.java deleted file mode 100644 index 3841d9fb7..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/HomekitSRP6ServerSession.java +++ /dev/null @@ -1,296 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -import com.nimbusds.srp6.SRP6ClientEvidenceContext; -import com.nimbusds.srp6.SRP6CryptoParams; -import com.nimbusds.srp6.SRP6Exception; -import com.nimbusds.srp6.SRP6Routines; -import com.nimbusds.srp6.SRP6ServerEvidenceContext; -import com.nimbusds.srp6.SRP6Session; -import com.nimbusds.srp6.URoutineContext; -import java.math.BigInteger; - -/** - * This is a slightly modified version of the SRP6ServerSession class included with nimbus. The only - * change made for homekit compatability is a change to the size of the b key. HomeKit pairing fails - * if b is not 3072 bytes. - * - *

Stateful server-side Secure Remote Password (SRP-6a) authentication session. Handles the - * computing and storing of SRP-6a variables between the protocol steps as well as timeouts. - * - *

Usage: - * - *

    - *
  • Create a new SRP-6a server session for each client authentication attempt. - *
  • If you wish to use custom routines for the server evidence message 'M1' and / or the client - * evidence message 'M2' specify them at this point. - *
  • Proceed to {@link #step1 step one} on receiving a valid user identity 'I' from the - * authenticating client. Respond with the server public value 'B' and password salt 's'. If - * the SRP-6a crypto parameters 'N', 'g' and 'H' were not agreed in advance between server and - * client append them to the response. - *
  • Proceed to {@link #step2 step two} on receiving the public client value 'A' and evidence - * message 'M1'. If the client credentials are valid signal success and return the server - * evidence message 'M2'. The established session key 'S' may be {@link #getSessionKey - * retrieved} to encrypt further communication with the client. Else signal an authentication - * failure to the client. - *
- * - * @author Vladimir Dzhuvinov - */ -public class HomekitSRP6ServerSession extends SRP6Session { - - /** Enumerates the states of a server-side SRP-6a authentication session. */ - public static enum State { - - /** - * The session is initialised and ready to begin authentication, by proceeding to {@link - * #STEP_1}. - */ - INIT, - - /** - * The user identity 'I' is received from the client and the server has returned its public - * value 'B' based on the matching password verifier 'v'. The session is ready to proceed to - * {@link #STEP_2}. - */ - STEP_1, - - /** - * The client public key 'A' and evidence message 'M1' are received and the server has replied - * with its own evidence message 'M2'. The session is finished (authentication was successful or - * failed). - */ - STEP_2 - } - - /** Indicates a non-existing use identity and implies mock salt 's' and verifier 'v' values. */ - private boolean noSuchUserIdentity = false; - - /** The password verifier 'v'. */ - private BigInteger v = null; - - /** The server private value 'b'. */ - private BigInteger b = null; - - /** The current SRP-6a auth state. */ - private State state; - - /** - * Creates a new server-side SRP-6a authentication session and sets its state to {@link - * State#INIT}. - * - * @param config The SRP-6a crypto parameters configuration. Must not be {@code null}. - * @param timeout The SRP-6a authentication session timeout in seconds. If the authenticating - * counterparty (server or client) fails to respond within the specified time the session will - * be closed. If zero timeouts are disabled. - */ - public HomekitSRP6ServerSession(final SRP6CryptoParams config, final int timeout) { - - super(timeout); - - if (config == null) - throw new IllegalArgumentException("The SRP-6a crypto parameters must not be null"); - - this.config = config; - - digest = config.getMessageDigestInstance(); - - if (digest == null) - throw new IllegalArgumentException("Unsupported hash algorithm 'H': " + config.H); - - state = State.INIT; - - updateLastActivityTime(); - } - - /** - * Creates a new server-side SRP-6a authentication session and sets its state to {@link - * State#INIT}. Session timeouts are disabled. - * - * @param config The SRP-6a crypto parameters configuration. Must not be {@code null}. - */ - public HomekitSRP6ServerSession(final SRP6CryptoParams config) { - - this(config, 0); - } - - /** - * Increments this SRP-6a authentication session to {@link State#STEP_1}. - * - *

Argument origin: - * - *

    - *
  • From client: user identity 'I'. - *
  • From server database: matching salt 's' and password verifier 'v' values. - *
- * - * @param userID The identity 'I' of the authenticating user. Must not be {@code null} or empty. - * @param s The password salt 's'. Must not be {@code null}. - * @param v The password verifier 'v'. Must not be {@code null}. - * @return The server public value 'B'. - * @throws IllegalStateException If the mehod is invoked in a state other than {@link State#INIT}. - */ - public BigInteger step1(final String userID, final BigInteger s, final BigInteger v) { - - // Check arguments - - if (userID == null || userID.trim().isEmpty()) - throw new IllegalArgumentException("The user identity 'I' must not be null or empty"); - - this.userID = userID; - - if (s == null) throw new IllegalArgumentException("The salt 's' must not be null"); - - this.s = s; - - if (v == null) throw new IllegalArgumentException("The verifier 'v' must not be null"); - - this.v = v; - - // Check current state - if (state != State.INIT) - throw new IllegalStateException("State violation: Session must be in INIT state"); - - // Generate server private and public values - k = SRP6Routines.computeK(digest, config.N, config.g); - digest.reset(); - - b = HomekitSRP6Routines.generatePrivateValue(config.N, random); - digest.reset(); - - B = SRP6Routines.computePublicServerValue(config.N, config.g, k, v, b); - - state = State.STEP_1; - - updateLastActivityTime(); - - return B; - } - - /** - * Increments this SRP-6a authentication session to {@link State#STEP_1} indicating a non-existing - * user identity 'I' with mock (simulated) salt 's' and password verifier 'v' values. - * - *

This method can be used to avoid informing the client at step one that the user identity is - * bad and throw instead a guaranteed general "bad credentials" SRP-6a exception at step two. - * - *

Argument origin: - * - *

    - *
  • From client: user identity 'I'. - *
  • Simulated by server, preferably consistently for the specified identity 'I': salt 's' and - * password verifier 'v' values. - *
- * - * @param userID The identity 'I' of the authenticating user. Must not be {@code null} or empty. - * @param s The password salt 's'. Must not be {@code null}. - * @param v The password verifier 'v'. Must not be {@code null}. - * @return The server public value 'B'. - * @throws IllegalStateException If the method is invoked in a state other than {@link - * State#INIT}. - */ - public BigInteger mockStep1(final String userID, final BigInteger s, final BigInteger v) { - - noSuchUserIdentity = true; - - return step1(userID, s, v); - } - - /** - * Increments this SRP-6a authentication session to {@link State#STEP_2}. - * - *

Argument origin: - * - *

    - *
  • From client: public value 'A' and evidence message 'M1'. - *
- * - * @param A The client public value. Must not be {@code null}. - * @param M1 The client evidence message. Must not be {@code null}. - * @return The server evidence message 'M2'. - * @throws SRP6Exception If the session has timed out, the client public value 'A' is invalid or - * the user credentials are invalid. - * @throws IllegalStateException If the method is invoked in a state other than {@link - * State#STEP_1}. - */ - public BigInteger step2(final BigInteger A, final BigInteger M1) throws SRP6Exception { - - // Check arguments - - if (A == null) - throw new IllegalArgumentException("The client public value 'A' must not be null"); - - this.A = A; - - if (M1 == null) - throw new IllegalArgumentException("The client evidence message 'M1' must not be null"); - - this.M1 = M1; - - // Check current state - if (state != State.STEP_1) - throw new IllegalStateException("State violation: Session must be in STEP_1 state"); - - // Check timeout - if (hasTimedOut()) throw new SRP6Exception("Session timeout", SRP6Exception.CauseType.TIMEOUT); - - // Check A validity - if (!SRP6Routines.isValidPublicValue(config.N, A)) - throw new SRP6Exception( - "Bad client public value 'A'", SRP6Exception.CauseType.BAD_PUBLIC_VALUE); - - // Check for previous mock step 1 - if (noSuchUserIdentity) - throw new SRP6Exception("Bad client credentials", SRP6Exception.CauseType.BAD_CREDENTIALS); - - if (hashedKeysRoutine != null) { - URoutineContext hashedKeysContext = new URoutineContext(A, B); - u = hashedKeysRoutine.computeU(config, hashedKeysContext); - } else { - u = SRP6Routines.computeU(digest, config.N, A, B); - digest.reset(); - } - - S = SRP6Routines.computeSessionKey(config.N, v, u, A, b); - - // Compute the own client evidence message 'M1' - BigInteger computedM1; - - if (clientEvidenceRoutine != null) { - - // With custom routine - SRP6ClientEvidenceContext ctx = new SRP6ClientEvidenceContext(userID, s, A, B, S); - computedM1 = clientEvidenceRoutine.computeClientEvidence(config, ctx); - } else { - // With default routine - computedM1 = SRP6Routines.computeClientEvidence(digest, A, B, S); - digest.reset(); - } - - if (!computedM1.equals(M1)) - throw new SRP6Exception("Bad client credentials", SRP6Exception.CauseType.BAD_CREDENTIALS); - - state = State.STEP_2; - - if (serverEvidenceRoutine != null) { - - // With custom routine - SRP6ServerEvidenceContext ctx = new SRP6ServerEvidenceContext(A, M1, S); - - M2 = serverEvidenceRoutine.computeServerEvidence(config, ctx); - } - - updateLastActivityTime(); - - return M2; - } - - /** - * Returns the current state of this SRP-6a authentication session. - * - * @return The current state. - */ - public State getState() { - - return state; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/MessageType.java b/src/main/java/io/github/hapjava/server/impl/pairing/MessageType.java deleted file mode 100644 index 84991d130..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/MessageType.java +++ /dev/null @@ -1,32 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -public enum MessageType { - METHOD(0), - USERNAME(1), - SALT(2), - PUBLIC_KEY(3), - PROOF(4), - ENCRYPTED_DATA(5), - STATE(6), - ERROR(7), - SIGNATURE(0x0a), - PERMISSIONS(0x0b), - FRAGMENT_DATA(0x0c), - FRAGMENT_LAST(0x0d), - FLAGS(0x13), - SEPARATOR(0xff); - - private final short key; - - MessageType(short key) { - this.key = key; - } - - MessageType(int key) { - this.key = (short) key; - } - - public short getKey() { - return key; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/PairSetupManager.java b/src/main/java/io/github/hapjava/server/impl/pairing/PairSetupManager.java deleted file mode 100644 index 05b37b8ab..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/PairSetupManager.java +++ /dev/null @@ -1,66 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -import io.github.hapjava.server.HomekitAuthInfo; -import io.github.hapjava.server.impl.HomekitRegistry; -import io.github.hapjava.server.impl.http.HttpRequest; -import io.github.hapjava.server.impl.http.HttpResponse; -import io.github.hapjava.server.impl.responses.NotFoundResponse; -import io.github.hapjava.server.impl.responses.UnauthorizedResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PairSetupManager { - - private static final Logger logger = LoggerFactory.getLogger(PairSetupManager.class); - - private final HomekitAuthInfo authInfo; - private final HomekitRegistry registry; - - private SrpHandler srpHandler; - - public PairSetupManager(HomekitAuthInfo authInfo, HomekitRegistry registry) { - this.authInfo = authInfo; - this.registry = registry; - } - - public HttpResponse handle(HttpRequest httpRequest) throws Exception { - PairSetupRequest req = PairSetupRequest.of(httpRequest.getBody()); - logger.trace("Handling pair-setup request {}", req); - - if (req.getState() == 1) { - logger.trace("Received SRP Start Request " + registry.getLabel()); - srpHandler = new SrpHandler(authInfo.getPin(), authInfo.getSalt()); - return srpHandler.handle(req); - } else if (req.getState() == 3) { - logger.trace("Receive SRP Verify Request for " + registry.getLabel()); - if (srpHandler == null) { - logger.warn("Received unexpected SRP Verify Request for " + registry.getLabel()); - return new UnauthorizedResponse(); - } else { - try { - return srpHandler.handle(req); - } catch (Exception e) { - srpHandler = null; // You don't get to try again - need a new key - logger.warn("Exception encountered while processing SRP Verify Request", e); - return new UnauthorizedResponse(); - } - } - } else if (req.getState() == 5) { - logger.trace("Received Exchange Request for " + registry.getLabel()); - if (srpHandler == null) { - logger.warn("Received unexpected Exchanged Request for " + registry.getLabel()); - return new UnauthorizedResponse(); - } else { - ExchangeHandler handler = new ExchangeHandler(srpHandler.getK(), authInfo); - try { - return handler.handle(req); - } catch (Exception e) { - logger.warn("Exception while finalizing pairing", e); - return new UnauthorizedResponse(); - } - } - } - - return new NotFoundResponse(); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/PairSetupRequest.java b/src/main/java/io/github/hapjava/server/impl/pairing/PairSetupRequest.java deleted file mode 100755 index 6fa099be4..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/PairSetupRequest.java +++ /dev/null @@ -1,139 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -import io.github.hapjava.server.impl.pairing.TypeLengthValueUtils.DecodeResult; -import java.math.BigInteger; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -abstract class PairSetupRequest { - private static final Logger logger = LoggerFactory.getLogger(PairSetupRequest.class); - - public static PairSetupRequest of(byte[] content) throws Exception { - DecodeResult d = TypeLengthValueUtils.decode(content); - logger.trace("Decoded pair setup request: {}", d); - short stage = d.getByte(MessageType.STATE); - switch (stage) { - case 1: - return new SRPStartRequest(d); - - case 3: - return new SRPVerifyRequest(d); - - case 5: - return new ExchangeRequest(d); - - default: - throw new Exception("Unknown pair process stage: " + stage); - } - } - - // Raw integer. - // State of the pairing process. 1=M1, 2=M2, etc. - public abstract int getState(); - - public static class SRPStartRequest extends PairSetupRequest { - int flags; - - public SRPStartRequest(DecodeResult d) { - flags = 0; - if (d.hasMessage(MessageType.FLAGS)) { - flags = d.getInt(MessageType.FLAGS); - } - } - - @Override - public int getState() { - return 1; - } - - public String toString() { - return ""; - } - } - - public static class SRPVerifyRequest extends PairSetupRequest { - - private final BigInteger a; - private final BigInteger m1; - - public SRPVerifyRequest(DecodeResult d) { - a = d.getBigInt(MessageType.PUBLIC_KEY); - m1 = d.getBigInt(MessageType.PROOF); - } - - public BigInteger getA() { - return a; - } - - public BigInteger getM1() { - return m1; - } - - @Override - public int getState() { - return 3; - } - - public String toString() { - return ""; - } - } - - static class ExchangeRequest extends PairSetupRequest { - - private final byte[] messageData; - private final byte[] authTagData; - - public ExchangeRequest(DecodeResult d) { - // Get the complete encrypted data field - byte[] encryptedData = d.getBytes(MessageType.ENCRYPTED_DATA); - logger.debug("ExchangeRequest: Total encrypted data length: {}", encryptedData.length); - logger.debug("ExchangeRequest: Raw encrypted data: {}", bytesToHex(encryptedData)); - - // For HomeKit M5, the encrypted data contains ciphertext + 16-byte auth tag - // The auth tag is the LAST 16 bytes - if (encryptedData.length < 16) { - throw new RuntimeException( - "Encrypted data too short, expected at least 16 bytes for auth tag"); - } - - int ciphertextLength = encryptedData.length - 16; - messageData = new byte[ciphertextLength]; - authTagData = new byte[16]; - - // Copy ciphertext (everything except last 16 bytes) - System.arraycopy(encryptedData, 0, messageData, 0, ciphertextLength); - // Copy auth tag (last 16 bytes) - System.arraycopy(encryptedData, ciphertextLength, authTagData, 0, 16); - - logger.debug("ExchangeRequest: Parsed ciphertext length: {}", messageData.length); - logger.debug("ExchangeRequest: Parsed ciphertext: {}", bytesToHex(messageData)); - logger.debug("ExchangeRequest: Parsed auth tag: {}", bytesToHex(authTagData)); - } - - private static String bytesToHex(byte[] bytes) { - StringBuilder result = new StringBuilder(); - for (byte b : bytes) { - result.append(String.format("%02x", b)); - } - return result.toString(); - } - - public byte[] getMessageData() { - return messageData; - } - - public byte[] getAuthTagData() { - return authTagData; - } - - @Override - public int getState() { - return 5; - } - - public String toString() { - return ""; - } - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/PairVerifyManager.java b/src/main/java/io/github/hapjava/server/impl/pairing/PairVerifyManager.java deleted file mode 100644 index 4960c6f6a..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/PairVerifyManager.java +++ /dev/null @@ -1,152 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -import djb.Curve25519; -import io.github.hapjava.server.HomekitAuthInfo; -import io.github.hapjava.server.impl.HomekitRegistry; -import io.github.hapjava.server.impl.crypto.ChachaDecoder; -import io.github.hapjava.server.impl.crypto.ChachaEncoder; -import io.github.hapjava.server.impl.crypto.EdsaSigner; -import io.github.hapjava.server.impl.crypto.EdsaVerifier; -import io.github.hapjava.server.impl.http.HttpRequest; -import io.github.hapjava.server.impl.http.HttpResponse; -import io.github.hapjava.server.impl.pairing.PairVerifyRequest.VerifyFinishRequest; -import io.github.hapjava.server.impl.pairing.PairVerifyRequest.VerifyStartRequest; -import io.github.hapjava.server.impl.pairing.TypeLengthValueUtils.DecodeResult; -import io.github.hapjava.server.impl.pairing.TypeLengthValueUtils.Encoder; -import io.github.hapjava.server.impl.responses.NotFoundResponse; -import java.nio.charset.StandardCharsets; -import java.security.SecureRandom; -import org.bouncycastle.crypto.digests.SHA512Digest; -import org.bouncycastle.crypto.generators.HKDFBytesGenerator; -import org.bouncycastle.crypto.params.HKDFParameters; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PairVerifyManager { - - private static final Logger logger = LoggerFactory.getLogger(PairVerifyManager.class); - private static volatile SecureRandom secureRandom; - - private final HomekitAuthInfo authInfo; - private final HomekitRegistry registry; - - private byte[] hkdfKey; - private byte[] clientPublicKey; - private byte[] publicKey; - private byte[] sharedSecret; - - public PairVerifyManager(HomekitAuthInfo authInfo, HomekitRegistry registry) { - this.authInfo = authInfo; - this.registry = registry; - } - - public HttpResponse handle(HttpRequest rawRequest) throws Exception { - PairVerifyRequest request = PairVerifyRequest.of(rawRequest.getBody()); - switch (request.getState()) { - case 1: - return handleVerifyStartRequest((VerifyStartRequest) request); - - case 3: - return handleVerifyFinishRequest((VerifyFinishRequest) request); - - default: - return new NotFoundResponse(); - } - } - - private HttpResponse handleVerifyStartRequest(VerifyStartRequest request) throws Exception { - logger.trace("Starting pair verification for " + registry.getLabel()); - clientPublicKey = request.getClientPublicKey(); - publicKey = new byte[32]; - byte[] privateKey = new byte[32]; - getSecureRandom().nextBytes(privateKey); - Curve25519.keygen(publicKey, null, privateKey); - - sharedSecret = new byte[32]; - Curve25519.curve(sharedSecret, privateKey, clientPublicKey); - - byte[] material = - ByteUtils.joinBytes( - publicKey, authInfo.getMac().getBytes(StandardCharsets.UTF_8), clientPublicKey); - - byte[] proof = new EdsaSigner(authInfo.getPrivateKey()).sign(material); - - HKDFBytesGenerator hkdf = new HKDFBytesGenerator(new SHA512Digest()); - hkdf.init( - new HKDFParameters( - sharedSecret, - "Pair-Verify-Encrypt-Salt".getBytes(StandardCharsets.UTF_8), - "Pair-Verify-Encrypt-Info".getBytes(StandardCharsets.UTF_8))); - hkdfKey = new byte[32]; - hkdf.generateBytes(hkdfKey, 0, 32); - - Encoder encoder = TypeLengthValueUtils.getEncoder(); - encoder.add(MessageType.USERNAME, authInfo.getMac().getBytes(StandardCharsets.UTF_8)); - encoder.add(MessageType.SIGNATURE, proof); - byte[] plaintext = encoder.toByteArray(); - - ChachaEncoder chacha = new ChachaEncoder(hkdfKey, "PV-Msg02".getBytes(StandardCharsets.UTF_8)); - byte[] ciphertext = chacha.encodeCiphertext(plaintext); - - encoder = TypeLengthValueUtils.getEncoder(); - encoder.add(MessageType.STATE, (short) 2); - encoder.add(MessageType.ENCRYPTED_DATA, ciphertext); - encoder.add(MessageType.PUBLIC_KEY, publicKey); - return new PairingResponse(encoder.toByteArray()); - } - - private HttpResponse handleVerifyFinishRequest(VerifyFinishRequest request) throws Exception { - ChachaDecoder chacha = new ChachaDecoder(hkdfKey, "PV-Msg03".getBytes(StandardCharsets.UTF_8)); - byte[] plaintext = chacha.decodeCiphertext(request.getAuthTagData(), request.getMessageData()); - - DecodeResult d = TypeLengthValueUtils.decode(plaintext); - byte[] clientUsername = d.getBytes(MessageType.USERNAME); - byte[] clientSignature = d.getBytes(MessageType.SIGNATURE); - - byte[] material = ByteUtils.joinBytes(clientPublicKey, clientUsername, publicKey); - - String username = new String(clientUsername, StandardCharsets.UTF_8); - byte[] clientLtpk = authInfo.getUserPublicKey(authInfo.getMac() + username); - if (clientLtpk == null) { - logger.warn("Unknown user: {}", username); - return new PairingResponse(4, ErrorCode.AUTHENTICATION); - } - - Encoder encoder = TypeLengthValueUtils.getEncoder(); - if (new EdsaVerifier(clientLtpk).verify(material, clientSignature)) { - encoder.add(MessageType.STATE, (short) 4); - logger.trace("Completed pair verification for " + registry.getLabel()); - return new UpgradeResponse( - encoder.toByteArray(), - createKey("Control-Write-Encryption-Key"), - createKey("Control-Read-Encryption-Key"), - username); - } else { - logger.warn("Invalid signature. Could not pair " + registry.getLabel()); - return new PairingResponse(4, ErrorCode.AUTHENTICATION); - } - } - - private byte[] createKey(String info) { - HKDFBytesGenerator hkdf = new HKDFBytesGenerator(new SHA512Digest()); - hkdf.init( - new HKDFParameters( - sharedSecret, - "Control-Salt".getBytes(StandardCharsets.UTF_8), - info.getBytes(StandardCharsets.UTF_8))); - byte[] key = new byte[32]; - hkdf.generateBytes(key, 0, 32); - return key; - } - - private static SecureRandom getSecureRandom() { - if (secureRandom == null) { - synchronized (PairVerifyManager.class) { - if (secureRandom == null) { - secureRandom = new SecureRandom(); - } - } - } - return secureRandom; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/PairVerifyRequest.java b/src/main/java/io/github/hapjava/server/impl/pairing/PairVerifyRequest.java deleted file mode 100644 index 7cf31585b..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/PairVerifyRequest.java +++ /dev/null @@ -1,69 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -import io.github.hapjava.server.impl.pairing.TypeLengthValueUtils.DecodeResult; - -abstract class PairVerifyRequest { - - static PairVerifyRequest of(byte[] content) throws Exception { - DecodeResult d = TypeLengthValueUtils.decode(content); - short stage = d.getByte(MessageType.STATE); - switch (stage) { - case 1: - return new VerifyStartRequest(d); - - case 3: - return new VerifyFinishRequest(d); - - default: - throw new Exception("Unknown pair process stage: " + stage); - } - } - - // Raw integer. - // State of the pairing process. 1=M1, 2=M2, etc. - abstract int getState(); - - static class VerifyStartRequest extends PairVerifyRequest { - - private final byte[] clientPublicKey; - - public VerifyStartRequest(DecodeResult d) { - clientPublicKey = d.getBytes(MessageType.PUBLIC_KEY); - } - - public byte[] getClientPublicKey() { - return clientPublicKey; - } - - @Override - int getState() { - return 1; - } - } - - static class VerifyFinishRequest extends PairVerifyRequest { - - private final byte[] messageData; - private final byte[] authTagData; - - public VerifyFinishRequest(DecodeResult d) { - messageData = new byte[d.getLength(MessageType.ENCRYPTED_DATA) - 16]; - authTagData = new byte[16]; - d.getBytes(MessageType.ENCRYPTED_DATA, messageData, 0); - d.getBytes(MessageType.ENCRYPTED_DATA, authTagData, messageData.length); - } - - public byte[] getMessageData() { - return messageData; - } - - public byte[] getAuthTagData() { - return authTagData; - } - - @Override - public int getState() { - return 3; - } - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/PairingMethod.java b/src/main/java/io/github/hapjava/server/impl/pairing/PairingMethod.java deleted file mode 100644 index 07decf02d..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/PairingMethod.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -public enum PairingMethod { - PAIR_SETUP(0), - PAIR_SETUP_WITH_AUTH(1), - PAIR_VERIFY(2), - ADD_PAIRING(3), - REMOVE_PAIRING(4), - LIST_PAIRINGS(5); - - private final byte value; - - PairingMethod(byte value) { - this.value = value; - } - - PairingMethod(int value) { - this.value = (byte) value; - } - - public byte getValue() { - return value; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/PairingResponse.java b/src/main/java/io/github/hapjava/server/impl/pairing/PairingResponse.java deleted file mode 100644 index defc5798f..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/PairingResponse.java +++ /dev/null @@ -1,49 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -import io.github.hapjava.server.impl.responses.OkResponse; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -class PairingResponse extends OkResponse { - - private static final Map headers = - Collections.unmodifiableMap( - new HashMap() { - private static final long serialVersionUID = 1L; - - { - put("Content-type", "application/pairing+tlv8"); - } - }); - - public PairingResponse(byte[] body) { - super(body); - } - - public PairingResponse(int state) { - this(encodeSuccess(state)); - } - - public PairingResponse(int state, ErrorCode errorCode) { - this(encodeError(state, errorCode)); - } - - private static byte[] encodeSuccess(int state) { - TypeLengthValueUtils.Encoder encoder = TypeLengthValueUtils.getEncoder(); - encoder.add(MessageType.STATE, (byte) state); - return encoder.toByteArray(); - } - - private static byte[] encodeError(int state, ErrorCode errorCode) { - TypeLengthValueUtils.Encoder encoder = TypeLengthValueUtils.getEncoder(); - encoder.add(MessageType.STATE, (byte) state); - encoder.add(MessageType.ERROR, (byte) errorCode.getKey()); - return encoder.toByteArray(); - } - - @Override - public Map getHeaders() { - return headers; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/PairingsManager.java b/src/main/java/io/github/hapjava/server/impl/pairing/PairingsManager.java deleted file mode 100644 index 11eb4a709..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/PairingsManager.java +++ /dev/null @@ -1,77 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -import io.github.hapjava.server.HomekitAuthInfo; -import io.github.hapjava.server.impl.http.HttpRequest; -import io.github.hapjava.server.impl.http.HttpResponse; -import io.github.hapjava.server.impl.jmdns.JmdnsHomekitAdvertiser; -import io.github.hapjava.server.impl.pairing.TypeLengthValueUtils.DecodeResult; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Collection; -import java.util.Iterator; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class PairingsManager { - - private final HomekitAuthInfo authInfo; - private final JmdnsHomekitAdvertiser advertiser; - - private static final Logger LOGGER = LoggerFactory.getLogger(PairingsManager.class); - - public PairingsManager(HomekitAuthInfo authInfo, JmdnsHomekitAdvertiser advertiser) { - this.authInfo = authInfo; - this.advertiser = advertiser; - } - - public HttpResponse handle(HttpRequest request) throws IOException { - DecodeResult d = TypeLengthValueUtils.decode(request.getBody()); - - int method = d.getByte(MessageType.METHOD); - - if (method == PairingMethod.ADD_PAIRING.getValue()) { - byte[] username = d.getBytes(MessageType.USERNAME); - byte[] ltpk = d.getBytes(MessageType.PUBLIC_KEY); - byte permissions = d.getByte(MessageType.PERMISSIONS); - authInfo.createUser( - authInfo.getMac() + new String(username, StandardCharsets.UTF_8), ltpk, permissions == 1); - } else if (method == PairingMethod.REMOVE_PAIRING.getValue()) { - byte[] username = d.getBytes(MessageType.USERNAME); - authInfo.removeUser(authInfo.getMac() + new String(username, StandardCharsets.UTF_8)); - if (!authInfo.hasUser()) { - advertiser.setDiscoverable(true); - } - } else if (method == PairingMethod.LIST_PAIRINGS.getValue()) { - TypeLengthValueUtils.Encoder e = TypeLengthValueUtils.getEncoder(); - - Collection usernames = authInfo.listUsers(); - boolean first = true; - Iterator iterator = usernames.iterator(); - String mac = authInfo.getMac(); - - while (iterator.hasNext()) { - String username = iterator.next(); - if (first) { - e.add(MessageType.STATE, (byte) 2); - first = false; - } else { - e.add(MessageType.SEPARATOR); - } - byte[] publicKey = authInfo.getUserPublicKey(username); - boolean isAdmin = authInfo.userIsAdmin(username); - if (username.startsWith(mac)) { - username = username.substring(mac.length()); - } - e.add(MessageType.USERNAME, username); - e.add(MessageType.PUBLIC_KEY, publicKey); - e.add(MessageType.PERMISSIONS, (short) (isAdmin ? 1 : 0)); - } - - return new PairingResponse(e.toByteArray()); - } else { - throw new RuntimeException("Unrecognized method: " + method); - } - - return new PairingResponse(2); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/ServerEvidenceRoutineImpl.java b/src/main/java/io/github/hapjava/server/impl/pairing/ServerEvidenceRoutineImpl.java deleted file mode 100644 index 7cf7b3164..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/ServerEvidenceRoutineImpl.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -import com.nimbusds.srp6.SRP6CryptoParams; -import com.nimbusds.srp6.SRP6ServerEvidenceContext; -import com.nimbusds.srp6.ServerEvidenceRoutine; -import java.math.BigInteger; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; - -class ServerEvidenceRoutineImpl implements ServerEvidenceRoutine { - - @Override - public BigInteger computeServerEvidence( - SRP6CryptoParams cryptoParams, SRP6ServerEvidenceContext ctx) { - - MessageDigest digest; - try { - digest = MessageDigest.getInstance(cryptoParams.H); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("Could not locate requested algorithm", e); - } - - byte[] hS = digest.digest(SrpHandler.bigIntegerToUnsignedByteArray(ctx.S)); - - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(ctx.A)); - digest.update(SrpHandler.bigIntegerToUnsignedByteArray(ctx.M1)); - digest.update(hS); - - return new BigInteger(1, digest.digest()); - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java b/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java deleted file mode 100644 index 5c1c23353..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/SrpHandler.java +++ /dev/null @@ -1,97 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -import com.nimbusds.srp6.*; -import io.github.hapjava.server.impl.http.HttpResponse; -import io.github.hapjava.server.impl.pairing.HomekitSRP6ServerSession.State; -import io.github.hapjava.server.impl.pairing.PairSetupRequest.SRPVerifyRequest; -import io.github.hapjava.server.impl.pairing.TypeLengthValueUtils.Encoder; -import io.github.hapjava.server.impl.responses.ConflictResponse; -import io.github.hapjava.server.impl.responses.NotFoundResponse; -import java.math.BigInteger; -import java.security.MessageDigest; -import java.util.Arrays; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -class SrpHandler { - - // Precomputed safe 3072 bit prime 'N'. Origin RFC 5054, appendix A. - private static final BigInteger N_3072 = - new BigInteger( - "5809605995369958062791915965639201402176612226902900533702900882779736177890990861472094774477339581147373410185646378328043729800750470098210924487866935059164371588168047540943981644516632755067501626434556398193186628990071248660819361205119793693985433297036118232914410171876807536457391277857011849897410207519105333355801121109356897459426271845471397952675959440793493071628394122780510124618488232602464649876850458861245784240929258426287699705312584509625419513463605155428017165714465363094021609290561084025893662561222573202082865797821865270991145082200656978177192827024538990239969175546190770645685893438011714430426409338676314743571154537142031573004276428701433036381801705308659830751190352946025482059931306571004727362479688415574702596946457770284148435989129632853918392117997472632693078113129886487399347796982772784615865232621289656944284216824611318709764535152507354116344703769998514148343807"); - private static final BigInteger G = BigInteger.valueOf(5); - private static final String IDENTIFIER = "Pair-Setup"; - - private static final Logger logger = LoggerFactory.getLogger(SrpHandler.class); - - private final BigInteger salt; - private final HomekitSRP6ServerSession session; - private final SRP6CryptoParams config; - private final String pin; - - public SrpHandler(String pin, BigInteger salt) { - config = new SRP6CryptoParams(N_3072, G, "SHA-512"); - session = new HomekitSRP6ServerSession(config); - session.setClientEvidenceRoutine(new ClientEvidenceRoutineImpl()); - session.setServerEvidenceRoutine(new ServerEvidenceRoutineImpl()); - this.pin = pin; - this.salt = salt; - } - - public HttpResponse handle(PairSetupRequest request) throws Exception { - switch (request.getState()) { - case 1: - return handleSrpStartRequest(); - - case 3: - return handleSrpVerifyRequest((SRPVerifyRequest) request); - - default: - return new NotFoundResponse(); - } - } - - private HttpResponse handleSrpStartRequest() throws Exception { - if (session.getState() != State.INIT) { - logger.warn("Session is not in state INIT when receiving step1"); - return new ConflictResponse(); - } - - SRP6VerifierGenerator verifierGenerator = new SRP6VerifierGenerator(config); - verifierGenerator.setXRoutine(new XRoutineWithUserIdentity()); - BigInteger verifier = verifierGenerator.generateVerifier(salt, IDENTIFIER, pin); - - Encoder encoder = TypeLengthValueUtils.getEncoder(); - encoder.add(MessageType.STATE, (short) 0x02); - encoder.add(MessageType.SALT, salt); - encoder.add(MessageType.PUBLIC_KEY, session.step1(IDENTIFIER, salt, verifier)); - return new PairingResponse(encoder.toByteArray()); - } - - private HttpResponse handleSrpVerifyRequest(SRPVerifyRequest request) throws Exception { - if (session.getState() != State.STEP_1) { - logger.warn("Session is not in state Stage 1 when receiving step2"); - return new ConflictResponse(); - } - BigInteger m2 = session.step2(request.getA(), request.getM1()); - Encoder encoder = TypeLengthValueUtils.getEncoder(); - encoder.add(MessageType.STATE, (short) 0x04); - encoder.add(MessageType.PROOF, m2); - return new PairingResponse(encoder.toByteArray()); - } - - public byte[] getK() { - MessageDigest digest = session.getCryptoParams().getMessageDigestInstance(); - BigInteger S = session.getSessionKey(false); - byte[] sBytes = bigIntegerToUnsignedByteArray(S); - return digest.digest(sBytes); - } - - public static byte[] bigIntegerToUnsignedByteArray(BigInteger i) { - byte[] array = i.toByteArray(); - if (array[0] == 0) { - array = Arrays.copyOfRange(array, 1, array.length); - } - return array; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/TypeLengthValueUtils.java b/src/main/java/io/github/hapjava/server/impl/pairing/TypeLengthValueUtils.java deleted file mode 100644 index cbd76f118..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/TypeLengthValueUtils.java +++ /dev/null @@ -1,120 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; - -public class TypeLengthValueUtils { - - private TypeLengthValueUtils() {} - - public static DecodeResult decode(byte[] content) throws IOException { - DecodeResult ret = new DecodeResult(); - ByteArrayInputStream bais = new ByteArrayInputStream(content); - while (bais.available() > 0) { - byte type = (byte) (bais.read() & 0xFF); - int length = bais.read(); - byte[] part = new byte[length]; - bais.read(part); - ret.add(type, part); - } - return ret; - } - - public static Encoder getEncoder() { - return new Encoder(); - } - - public static final class Encoder { - - private final ByteArrayOutputStream baos; - - private Encoder() { - baos = new ByteArrayOutputStream(); - } - - public void add(MessageType type) { - baos.write(type.getKey()); - baos.write(0); - } - - public void add(MessageType type, BigInteger i) throws IOException { - add(type, ByteUtils.toByteArray(i)); - } - - public void add(MessageType type, short b) { - baos.write(type.getKey()); - baos.write(1); - baos.write(b); - } - - public void add(MessageType type, byte[] bytes) throws IOException { - InputStream bais = new ByteArrayInputStream(bytes); - while (bais.available() > 0) { - int toWrite = bais.available(); - toWrite = toWrite > 255 ? 255 : toWrite; - baos.write(type.getKey()); - baos.write(toWrite); - ByteUtils.copyStream(bais, baos, toWrite); - } - } - - public void add(MessageType type, String string) throws IOException { - add(type, string.getBytes(StandardCharsets.UTF_8)); - } - - public byte[] toByteArray() { - return baos.toByteArray(); - } - } - - public static final class DecodeResult { - private final Map result = new HashMap<>(); - - private DecodeResult() {} - - public String toString() { - return result.toString(); - } - - public boolean hasMessage(MessageType type) { - return result.containsKey(type.getKey()); - } - - public byte getByte(MessageType type) { - return result.get(type.getKey())[0]; - } - - public int getInt(MessageType type) { - ByteBuffer wrapped = ByteBuffer.wrap(result.get(type.getKey())); - return wrapped.getInt(); - } - - public BigInteger getBigInt(MessageType type) { - return new BigInteger(1, result.get(type.getKey())); - } - - public byte[] getBytes(MessageType type) { - return result.get(type.getKey()); - } - - public void getBytes(MessageType type, byte[] dest, int srcOffset) { - byte[] b = result.get(type.getKey()); - System.arraycopy(b, srcOffset, dest, 0, Math.min(dest.length, b.length)); - } - - public int getLength(MessageType type) { - return result.get(type.getKey()).length; - } - - private void add(short type, byte[] bytes) { - result.merge(type, bytes, ByteUtils::joinBytes); - } - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/pairing/UpgradeResponse.java b/src/main/java/io/github/hapjava/server/impl/pairing/UpgradeResponse.java deleted file mode 100644 index 121fc7fd8..000000000 --- a/src/main/java/io/github/hapjava/server/impl/pairing/UpgradeResponse.java +++ /dev/null @@ -1,34 +0,0 @@ -package io.github.hapjava.server.impl.pairing; - -import java.nio.ByteBuffer; - -public class UpgradeResponse extends PairingResponse { - - private final byte[] readKey; - private final byte[] writeKey; - private final String username; - - UpgradeResponse(byte[] body, byte[] readKey, byte[] writeKey, String username) { - super(body); - this.readKey = readKey; - this.writeKey = writeKey; - this.username = username; - } - - @Override - public boolean doUpgrade() { - return true; - } - - public ByteBuffer getReadKey() { - return ByteBuffer.wrap(readKey); - } - - public ByteBuffer getWriteKey() { - return ByteBuffer.wrap(writeKey); - } - - public String getUsername() { - return username; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/responses/ConflictResponse.java b/src/main/java/io/github/hapjava/server/impl/responses/ConflictResponse.java deleted file mode 100644 index 017fee857..000000000 --- a/src/main/java/io/github/hapjava/server/impl/responses/ConflictResponse.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.github.hapjava.server.impl.responses; - -import io.github.hapjava.server.impl.http.HttpResponse; - -public class ConflictResponse implements HttpResponse { - - @Override - public int getStatusCode() { - return 409; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/responses/InternalServerErrorResponse.java b/src/main/java/io/github/hapjava/server/impl/responses/InternalServerErrorResponse.java deleted file mode 100644 index 6be78e75a..000000000 --- a/src/main/java/io/github/hapjava/server/impl/responses/InternalServerErrorResponse.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.github.hapjava.server.impl.responses; - -import io.github.hapjava.server.impl.http.HttpResponse; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; - -public class InternalServerErrorResponse implements HttpResponse { - - private final Exception e; - - public InternalServerErrorResponse(Exception e) { - this.e = e; - } - - @Override - public int getStatusCode() { - return 500; - } - - @Override - public ByteBuffer getBody() { - return ByteBuffer.wrap(e.getClass().getName().getBytes(StandardCharsets.UTF_8)); - } - - public Exception getException() { - return e; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/responses/NotFoundResponse.java b/src/main/java/io/github/hapjava/server/impl/responses/NotFoundResponse.java deleted file mode 100644 index aca74ad9d..000000000 --- a/src/main/java/io/github/hapjava/server/impl/responses/NotFoundResponse.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.github.hapjava.server.impl.responses; - -import io.github.hapjava.server.impl.http.HttpResponse; - -public class NotFoundResponse implements HttpResponse { - - @Override - public int getStatusCode() { - return 404; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/responses/OkResponse.java b/src/main/java/io/github/hapjava/server/impl/responses/OkResponse.java deleted file mode 100644 index b2e62fe76..000000000 --- a/src/main/java/io/github/hapjava/server/impl/responses/OkResponse.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.github.hapjava.server.impl.responses; - -import io.github.hapjava.server.impl.http.HttpResponse; -import java.nio.ByteBuffer; - -public class OkResponse implements HttpResponse { - - private final ByteBuffer body; - - public OkResponse(byte[] body) { - this.body = ByteBuffer.wrap(body); - } - - @Override - public ByteBuffer getBody() { - return body; - } - - @Override - public int getStatusCode() { - return 200; - } -} diff --git a/src/main/java/io/github/hapjava/server/impl/responses/UnauthorizedResponse.java b/src/main/java/io/github/hapjava/server/impl/responses/UnauthorizedResponse.java deleted file mode 100644 index c40a03f08..000000000 --- a/src/main/java/io/github/hapjava/server/impl/responses/UnauthorizedResponse.java +++ /dev/null @@ -1,11 +0,0 @@ -package io.github.hapjava.server.impl.responses; - -import io.github.hapjava.server.impl.http.HttpResponse; - -public class UnauthorizedResponse implements HttpResponse { - - @Override - public int getStatusCode() { - return 401; - } -} diff --git a/src/main/java/io/github/hapjava/services/Service.java b/src/main/java/io/github/hapjava/services/Service.java deleted file mode 100644 index 303cc5463..000000000 --- a/src/main/java/io/github/hapjava/services/Service.java +++ /dev/null @@ -1,46 +0,0 @@ -package io.github.hapjava.services; - -import io.github.hapjava.characteristics.Characteristic; -import java.util.List; - -/** - * Interface for a Service offered by an accessory. - * - * @author Andy Lintner - */ -public interface Service { - - /** - * Characteristics are the variables offered for reading, updating, and eventing by the Service - * over the HomeKit protocol. - * - *

It is important to maintain the order of this list and not change its contents between - * invocations, or a pairing error will result. - * - * @return the list of Characteristics. - */ - List getCharacteristics(); - - /** - * The type is a UUID that uniquely identifies the type of Service offered. Apple defines several - * types for standard Services, however UUIDs outside this range are allowed for custom Services. - * - * @return A string representation of the UUID, with hexadecimal digits in the format - * ########-####-####-####-############. - */ - String getType(); - - /** - * List of all the services to which the service links - * - * @return the list of linked services. - */ - List getLinkedServices(); - - /** - * Add linked services - * - * @param service linked service - */ - void addLinkedService(Service service); -} diff --git a/src/main/java/io/github/hapjava/services/impl/AbstractServiceImpl.java b/src/main/java/io/github/hapjava/services/impl/AbstractServiceImpl.java deleted file mode 100644 index 4dfd9f5f6..000000000 --- a/src/main/java/io/github/hapjava/services/impl/AbstractServiceImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.characteristics.Characteristic; -import io.github.hapjava.services.Service; -import java.util.Collections; -import java.util.LinkedList; -import java.util.List; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -abstract class AbstractServiceImpl implements Service { - private final String type; - private final List characteristics = new LinkedList<>(); - private final List linkedServices = new LinkedList<>(); - private static final Logger logger = LoggerFactory.getLogger(AbstractServiceImpl.class); - - /** @param type unique UUID of the service according to HAP specification. */ - public AbstractServiceImpl(String type) { - this.type = type; - } - - @Override - public List getCharacteristics() { - return Collections.unmodifiableList(characteristics); - } - - @Override - public String getType() { - return type; - } - - @Override - public List getLinkedServices() { - return Collections.unmodifiableList(linkedServices); - } - - public void addCharacteristic(Characteristic characteristic) { - this.characteristics.add(characteristic); - } - - @Override - public void addLinkedService(Service service) { - this.linkedServices.add(service); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/AccessoryInformationService.java b/src/main/java/io/github/hapjava/services/impl/AccessoryInformationService.java deleted file mode 100644 index 1fdb30d2a..000000000 --- a/src/main/java/io/github/hapjava/services/impl/AccessoryInformationService.java +++ /dev/null @@ -1,70 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.HomekitAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithAccessoryFlags; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithHardwareRevision; -import io.github.hapjava.characteristics.impl.accessoryinformation.AccessoryFlagsCharacteristic; -import io.github.hapjava.characteristics.impl.accessoryinformation.FirmwareRevisionCharacteristic; -import io.github.hapjava.characteristics.impl.accessoryinformation.HardwareRevisionCharacteristic; -import io.github.hapjava.characteristics.impl.accessoryinformation.IdentifyCharacteristic; -import io.github.hapjava.characteristics.impl.accessoryinformation.ManufacturerCharacteristic; -import io.github.hapjava.characteristics.impl.accessoryinformation.ModelCharacteristic; -import io.github.hapjava.characteristics.impl.accessoryinformation.SerialNumberCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; - -/** Accessory Information service. */ -public class AccessoryInformationService extends AbstractServiceImpl { - public static final String TYPE = "0000003E-0000-1000-8000-0026BB765291"; - - public AccessoryInformationService( - IdentifyCharacteristic identify, - ManufacturerCharacteristic manufacturer, - ModelCharacteristic model, - NameCharacteristic name, - SerialNumberCharacteristic serialNumber, - FirmwareRevisionCharacteristic firmwareRevision) { - super(TYPE); - addCharacteristic(identify); - addCharacteristic(manufacturer); - addCharacteristic(model); - addCharacteristic(name); - addCharacteristic(serialNumber); - addCharacteristic(firmwareRevision); - } - - public AccessoryInformationService(HomekitAccessory accessory) { - this( - new IdentifyCharacteristic( - value -> { - if (value) { - accessory.identify(); - } - }), - new ManufacturerCharacteristic(accessory::getManufacturer), - new ModelCharacteristic(accessory::getModel), - new NameCharacteristic(accessory::getName), - new SerialNumberCharacteristic(accessory::getSerialNumber), - new FirmwareRevisionCharacteristic(accessory::getFirmwareRevision)); - - if (accessory instanceof AccessoryWithHardwareRevision) { - addOptionalCharacteristic( - new HardwareRevisionCharacteristic( - ((AccessoryWithHardwareRevision) accessory)::getHardwareRevision)); - } - if (accessory instanceof AccessoryWithAccessoryFlags) { - addOptionalCharacteristic( - new AccessoryFlagsCharacteristic( - ((AccessoryWithAccessoryFlags) accessory)::getAccessoryFlags, - ((AccessoryWithAccessoryFlags) accessory)::subscribeAccessoryFlags, - ((AccessoryWithAccessoryFlags) accessory)::unsubscribeAccessoryFlags)); - } - } - - public void addOptionalCharacteristic(HardwareRevisionCharacteristic hardwareRevision) { - addCharacteristic(hardwareRevision); - } - - public void addOptionalCharacteristic(AccessoryFlagsCharacteristic accessoryFlagsCharacteristic) { - addCharacteristic(accessoryFlagsCharacteristic); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/AirPurifierService.java b/src/main/java/io/github/hapjava/services/impl/AirPurifierService.java deleted file mode 100644 index 4918eab81..000000000 --- a/src/main/java/io/github/hapjava/services/impl/AirPurifierService.java +++ /dev/null @@ -1,90 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.AirPurifierAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithPhysicalControlsLock; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithRotationSpeed; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithSwingMode; -import io.github.hapjava.characteristics.impl.airpurifier.CurrentAirPurifierCharacteristic; -import io.github.hapjava.characteristics.impl.airpurifier.TargetAirPurifierStateCharacteristic; -import io.github.hapjava.characteristics.impl.common.ActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.ActiveEnum; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.fan.LockPhysicalControlsCharacteristic; -import io.github.hapjava.characteristics.impl.fan.RotationSpeedCharacteristic; -import io.github.hapjava.characteristics.impl.fan.SwingModeCharacteristic; - -/** This service describes an air purifier. */ -public class AirPurifierService extends AbstractServiceImpl { - - public AirPurifierService( - ActiveCharacteristic active, - CurrentAirPurifierCharacteristic currentState, - TargetAirPurifierStateCharacteristic targetState) { - super("000000BB-0000-1000-8000-0026BB765291"); - addCharacteristic(active); - addCharacteristic(currentState); - addCharacteristic(targetState); - } - - public AirPurifierService(AirPurifierAccessory accessory) { - this( - new ActiveCharacteristic( - () -> accessory.isActive().thenApply(s -> s ? ActiveEnum.ACTIVE : ActiveEnum.INACTIVE), - (v) -> accessory.setActive(v == ActiveEnum.ACTIVE), - accessory::subscribeActive, - accessory::unsubscribeActive), - new CurrentAirPurifierCharacteristic( - accessory::getCurrentState, - accessory::subscribeCurrentState, - accessory::unsubscribeCurrentState), - new TargetAirPurifierStateCharacteristic( - accessory::getTargetState, - accessory::setTargetState, - accessory::subscribeCurrentState, - accessory::unsubscribeCurrentState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithSwingMode) { - addOptionalCharacteristic( - new SwingModeCharacteristic( - ((AccessoryWithSwingMode) accessory)::getSwingMode, - ((AccessoryWithSwingMode) accessory)::setSwingMode, - ((AccessoryWithSwingMode) accessory)::subscribeSwingMode, - ((AccessoryWithSwingMode) accessory)::unsubscribeSwingMode)); - } - if (accessory instanceof AccessoryWithRotationSpeed) { - addOptionalCharacteristic( - new RotationSpeedCharacteristic( - ((AccessoryWithRotationSpeed) accessory)::getRotationSpeed, - ((AccessoryWithRotationSpeed) accessory)::setRotationSpeed, - ((AccessoryWithRotationSpeed) accessory)::subscribeRotationSpeed, - ((AccessoryWithRotationSpeed) accessory)::unsubscribeRotationSpeed)); - } - if (accessory instanceof AccessoryWithPhysicalControlsLock) { - addOptionalCharacteristic( - new LockPhysicalControlsCharacteristic( - ((AccessoryWithPhysicalControlsLock) accessory)::getLockControls, - ((AccessoryWithPhysicalControlsLock) accessory)::setLockControls, - ((AccessoryWithPhysicalControlsLock) accessory)::subscribeLockControls, - ((AccessoryWithPhysicalControlsLock) accessory)::unsubscribeLockControls)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(SwingModeCharacteristic mode) { - addCharacteristic(mode); - } - - public void addOptionalCharacteristic(RotationSpeedCharacteristic speed) { - addCharacteristic(speed); - } - - public void addOptionalCharacteristic(LockPhysicalControlsCharacteristic lock) { - addCharacteristic(lock); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/AirQualityService.java b/src/main/java/io/github/hapjava/services/impl/AirQualityService.java deleted file mode 100644 index 4aa74c88f..000000000 --- a/src/main/java/io/github/hapjava/services/impl/AirQualityService.java +++ /dev/null @@ -1,178 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.AirQualityAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithNitrogenDioxideDensity; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithOzoneDensity; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithPM10Density; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithPM25Density; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusActive; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusFault; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusLowBattery; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusTampered; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithSulphurDioxideDensity; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithVOCDensity; -import io.github.hapjava.characteristics.impl.airquality.AirQualityCharacteristic; -import io.github.hapjava.characteristics.impl.airquality.NitrogenDioxideDensityCharacteristic; -import io.github.hapjava.characteristics.impl.airquality.OzoneDensityCharacteristic; -import io.github.hapjava.characteristics.impl.airquality.PM10DensityCharacteristic; -import io.github.hapjava.characteristics.impl.airquality.PM25DensityCharacteristic; -import io.github.hapjava.characteristics.impl.airquality.SulphurDioxideDensityCharacteristic; -import io.github.hapjava.characteristics.impl.airquality.VOCDensityCharacteristic; -import io.github.hapjava.characteristics.impl.battery.StatusLowBatteryCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusFaultCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusTamperedCharacteristic; - -/** This service describes air quality sensor. */ -public class AirQualityService extends AbstractServiceImpl { - - public AirQualityService(AirQualityCharacteristic airQuality) { - super("0000008D-0000-1000-8000-0026BB765291"); - addCharacteristic(airQuality); - } - - public AirQualityService(AirQualityAccessory accessory) { - this( - new AirQualityCharacteristic( - accessory::getAirQuality, - accessory::subscribeAirQuality, - accessory::unsubscribeAirQuality)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - - if (accessory instanceof AccessoryWithOzoneDensity) { - addOptionalCharacteristic( - new OzoneDensityCharacteristic( - ((AccessoryWithOzoneDensity) accessory)::getOzoneDensity, - ((AccessoryWithOzoneDensity) accessory)::subscribeOzoneDensity, - ((AccessoryWithOzoneDensity) accessory)::unsubscribeOzoneDensity)); - } - if (accessory instanceof AccessoryWithNitrogenDioxideDensity) { - addOptionalCharacteristic( - new NitrogenDioxideDensityCharacteristic( - ((AccessoryWithNitrogenDioxideDensity) accessory).getMinNitrogenDioxideDensity(), - ((AccessoryWithNitrogenDioxideDensity) accessory).getMaxNitrogenDioxideDensity(), - ((AccessoryWithNitrogenDioxideDensity) accessory).getMinStepNitrogenDioxideDensity(), - ((AccessoryWithNitrogenDioxideDensity) accessory)::getNitrogenDioxideDensity, - ((AccessoryWithNitrogenDioxideDensity) accessory)::subscribeNitrogenDioxideDensity, - ((AccessoryWithNitrogenDioxideDensity) accessory) - ::unsubscribeNitrogenDioxideDensity)); - } - - if (accessory instanceof AccessoryWithSulphurDioxideDensity) { - addOptionalCharacteristic( - new SulphurDioxideDensityCharacteristic( - ((AccessoryWithSulphurDioxideDensity) accessory).getMinSulphurDioxideDensity(), - ((AccessoryWithSulphurDioxideDensity) accessory).getMaxSulphurDioxideDensity(), - ((AccessoryWithSulphurDioxideDensity) accessory).getMinStepSulphurDioxideDensity(), - ((AccessoryWithSulphurDioxideDensity) accessory)::getSulphurDioxideDensity, - ((AccessoryWithSulphurDioxideDensity) accessory)::subscribeSulphurDioxideDensity, - ((AccessoryWithSulphurDioxideDensity) accessory)::unsubscribeSulphurDioxideDensity)); - } - if (accessory instanceof AccessoryWithPM25Density) { - addOptionalCharacteristic( - new PM25DensityCharacteristic( - ((AccessoryWithPM25Density) accessory).getMinPM25Density(), - ((AccessoryWithPM25Density) accessory).getMaxPM25Density(), - ((AccessoryWithPM25Density) accessory).getMinStepPM25Density(), - ((AccessoryWithPM25Density) accessory)::getPM25Density, - ((AccessoryWithPM25Density) accessory)::subscribePM25Density, - ((AccessoryWithPM25Density) accessory)::unsubscribePM25Density)); - } - if (accessory instanceof AccessoryWithPM10Density) { - addOptionalCharacteristic( - new PM10DensityCharacteristic( - ((AccessoryWithPM10Density) accessory).getMinPM10Density(), - ((AccessoryWithPM10Density) accessory).getMaxPM10Density(), - ((AccessoryWithPM10Density) accessory).getMinStepPM10Density(), - ((AccessoryWithPM10Density) accessory)::getPM10Density, - ((AccessoryWithPM10Density) accessory)::subscribePM10Density, - ((AccessoryWithPM10Density) accessory)::unsubscribePM10Density)); - } - if (accessory instanceof AccessoryWithVOCDensity) { - addOptionalCharacteristic( - new VOCDensityCharacteristic( - ((AccessoryWithVOCDensity) accessory).getMinVOCDensity(), - ((AccessoryWithVOCDensity) accessory).getMaxVOCDensity(), - ((AccessoryWithVOCDensity) accessory).getMinStepVOCDensity(), - ((AccessoryWithVOCDensity) accessory)::getVOCDensity, - ((AccessoryWithVOCDensity) accessory)::subscribeVOCDensity, - ((AccessoryWithVOCDensity) accessory)::unsubscribeVOCDensity)); - } - if (accessory instanceof AccessoryWithStatusActive) { - addOptionalCharacteristic( - new StatusActiveCharacteristic( - ((AccessoryWithStatusActive) accessory)::getStatusActive, - ((AccessoryWithStatusActive) accessory)::subscribeStatusActive, - ((AccessoryWithStatusActive) accessory)::unsubscribeStatusActive)); - } - if (accessory instanceof AccessoryWithStatusFault) { - addOptionalCharacteristic( - new StatusFaultCharacteristic( - ((AccessoryWithStatusFault) accessory)::getStatusFault, - ((AccessoryWithStatusFault) accessory)::subscribeStatusFault, - ((AccessoryWithStatusFault) accessory)::unsubscribeStatusFault)); - } - if (accessory instanceof AccessoryWithStatusTampered) { - addOptionalCharacteristic( - new StatusTamperedCharacteristic( - ((AccessoryWithStatusTampered) accessory)::getStatusTampered, - ((AccessoryWithStatusTampered) accessory)::subscribeStatusTampered, - ((AccessoryWithStatusTampered) accessory)::unsubscribeStatusTampered)); - } - if (accessory instanceof AccessoryWithStatusLowBattery) { - addOptionalCharacteristic( - new StatusLowBatteryCharacteristic( - ((AccessoryWithStatusLowBattery) accessory)::getStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::subscribeStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::unsubscribeStatusLowBattery)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(OzoneDensityCharacteristic ozoneDensity) { - addCharacteristic(ozoneDensity); - } - - public void addOptionalCharacteristic(NitrogenDioxideDensityCharacteristic nitrogenDensity) { - addCharacteristic(nitrogenDensity); - } - - public void addOptionalCharacteristic(SulphurDioxideDensityCharacteristic sulphuhrDensity) { - addCharacteristic(sulphuhrDensity); - } - - public void addOptionalCharacteristic(PM25DensityCharacteristic pm25Density) { - addCharacteristic(pm25Density); - } - - public void addOptionalCharacteristic(PM10DensityCharacteristic pm10Density) { - addCharacteristic(pm10Density); - } - - public void addOptionalCharacteristic(VOCDensityCharacteristic vocDensity) { - addCharacteristic(vocDensity); - } - - public void addOptionalCharacteristic(StatusActiveCharacteristic statusActive) { - addCharacteristic(statusActive); - } - - public void addOptionalCharacteristic(StatusFaultCharacteristic statusFault) { - addCharacteristic(statusFault); - } - - public void addOptionalCharacteristic(StatusTamperedCharacteristic statusTampered) { - addCharacteristic(statusTampered); - } - - public void addOptionalCharacteristic(StatusLowBatteryCharacteristic statusLowBattery) { - addCharacteristic(statusLowBattery); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/BasicFanService.java b/src/main/java/io/github/hapjava/services/impl/BasicFanService.java deleted file mode 100644 index 9a033dd0c..000000000 --- a/src/main/java/io/github/hapjava/services/impl/BasicFanService.java +++ /dev/null @@ -1,65 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.BasicFanAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithRotationDirection; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithRotationSpeed; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.OnCharacteristic; -import io.github.hapjava.characteristics.impl.fan.RotationDirectionCharacteristic; -import io.github.hapjava.characteristics.impl.fan.RotationSpeedCharacteristic; - -/** - * This service describes a fan. - * - *

In the R1 release of the HAP specification, this is simply described as Fan. It is no longer - * present in the R2 release. - */ -public class BasicFanService extends AbstractServiceImpl { - - public BasicFanService(OnCharacteristic on) { - super("00000040-0000-1000-8000-0026BB765291"); - addCharacteristic(on); - } - - public BasicFanService(BasicFanAccessory accessory) { - this( - new OnCharacteristic( - () -> accessory.isOn(), - (v) -> accessory.setOn(v), - accessory::subscribeOn, - accessory::unsubscribeOn)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - - if (accessory instanceof AccessoryWithRotationDirection) { - addOptionalCharacteristic( - new RotationDirectionCharacteristic( - ((AccessoryWithRotationDirection) accessory)::getRotationDirection, - ((AccessoryWithRotationDirection) accessory)::setRotationDirection, - ((AccessoryWithRotationDirection) accessory)::subscribeRotationDirection, - ((AccessoryWithRotationDirection) accessory)::unsubscribeRotationDirection)); - } - if (accessory instanceof AccessoryWithRotationSpeed) { - addOptionalCharacteristic( - new RotationSpeedCharacteristic( - ((AccessoryWithRotationSpeed) accessory)::getRotationSpeed, - ((AccessoryWithRotationSpeed) accessory)::setRotationSpeed, - ((AccessoryWithRotationSpeed) accessory)::subscribeRotationSpeed, - ((AccessoryWithRotationSpeed) accessory)::unsubscribeRotationSpeed)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(RotationDirectionCharacteristic direction) { - addCharacteristic(direction); - } - - public void addOptionalCharacteristic(RotationSpeedCharacteristic speed) { - addCharacteristic(speed); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/BatteryService.java b/src/main/java/io/github/hapjava/services/impl/BatteryService.java deleted file mode 100644 index 46259a6e8..000000000 --- a/src/main/java/io/github/hapjava/services/impl/BatteryService.java +++ /dev/null @@ -1,45 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.BatteryAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.characteristics.impl.battery.BatteryLevelCharacteristic; -import io.github.hapjava.characteristics.impl.battery.ChargingStateCharacteristic; -import io.github.hapjava.characteristics.impl.battery.StatusLowBatteryCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; - -/** This service describes a battery service. */ -public class BatteryService extends AbstractServiceImpl { - - public BatteryService( - BatteryLevelCharacteristic batteryLevelCharacteristic, - ChargingStateCharacteristic chargingStateCharacteristic, - StatusLowBatteryCharacteristic statusLowBatteryCharacteristic) { - super("00000096-0000-1000-8000-0026BB765291"); - addCharacteristic(batteryLevelCharacteristic); - addCharacteristic(chargingStateCharacteristic); - addCharacteristic(statusLowBatteryCharacteristic); - } - - public BatteryService(BatteryAccessory accessory) { - this( - new BatteryLevelCharacteristic( - accessory::getBatteryLevel, - accessory::subscribeBatteryLevel, - accessory::unsubscribeBatteryLevel), - new ChargingStateCharacteristic( - accessory::getChargingState, - accessory::subscribeBatteryChargingState, - accessory::unsubscribeBatteryChargingState), - new StatusLowBatteryCharacteristic( - accessory::getLowBatteryState, - accessory::subscribeLowBatteryState, - accessory::unsubscribeLowBatteryState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/CarbonDioxideSensorService.java b/src/main/java/io/github/hapjava/services/impl/CarbonDioxideSensorService.java deleted file mode 100644 index b61e91b91..000000000 --- a/src/main/java/io/github/hapjava/services/impl/CarbonDioxideSensorService.java +++ /dev/null @@ -1,114 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.CarbonDioxideSensorAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithCarbonDioxideLevel; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusActive; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusFault; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusLowBattery; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusTampered; -import io.github.hapjava.characteristics.impl.battery.StatusLowBatteryCharacteristic; -import io.github.hapjava.characteristics.impl.carbondioxidesensor.CarbonDioxideDetectedCharacteristic; -import io.github.hapjava.characteristics.impl.carbondioxidesensor.CarbonDioxideLevelCharacteristic; -import io.github.hapjava.characteristics.impl.carbondioxidesensor.CarbonDioxidePeakLevelCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusFaultCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusTamperedCharacteristic; - -/** This service describes a carbon dioxide sensor. */ -public class CarbonDioxideSensorService extends AbstractServiceImpl { - - public CarbonDioxideSensorService(CarbonDioxideDetectedCharacteristic carbonDioxideDetected) { - super("00000097-0000-1000-8000-0026BB765291"); - addCharacteristic(carbonDioxideDetected); - } - - public CarbonDioxideSensorService(CarbonDioxideSensorAccessory accessory) { - this( - new CarbonDioxideDetectedCharacteristic( - accessory::getCarbonDioxideDetectedState, - accessory::subscribeCarbonDioxideDetectedState, - accessory::unsubscribeCarbonDioxideDetectedState)); - - if (accessory instanceof AccessoryWithCarbonDioxideLevel) { - addOptionalCharacteristic( - new CarbonDioxideLevelCharacteristic( - ((AccessoryWithCarbonDioxideLevel) accessory).getMinCarbonDioxideLevel(), - ((AccessoryWithCarbonDioxideLevel) accessory).getMaxCarbonDioxideLevel(), - ((AccessoryWithCarbonDioxideLevel) accessory).getMinStepCarbonDioxideLevel(), - ((AccessoryWithCarbonDioxideLevel) accessory)::getCarbonDioxideLevel, - ((AccessoryWithCarbonDioxideLevel) accessory)::subscribeCarbonDioxideLevel, - ((AccessoryWithCarbonDioxideLevel) accessory)::unsubscribeCarbonDioxideLevel)); - addOptionalCharacteristic( - new CarbonDioxidePeakLevelCharacteristic( - ((AccessoryWithCarbonDioxideLevel) accessory).getMinCarbonDioxidePeakLevel(), - ((AccessoryWithCarbonDioxideLevel) accessory).getMaxCarbonDioxidePeakLevel(), - ((AccessoryWithCarbonDioxideLevel) accessory).getMinStepCarbonDioxidePeakLevel(), - ((AccessoryWithCarbonDioxideLevel) accessory)::getCarbonDioxidePeakLevel, - ((AccessoryWithCarbonDioxideLevel) accessory)::subscribeCarbonDioxidePeakLevel, - ((AccessoryWithCarbonDioxideLevel) accessory)::unsubscribeCarbonDioxidePeakLevel)); - } - - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithStatusActive) { - addOptionalCharacteristic( - new StatusActiveCharacteristic( - ((AccessoryWithStatusActive) accessory)::getStatusActive, - ((AccessoryWithStatusActive) accessory)::subscribeStatusActive, - ((AccessoryWithStatusActive) accessory)::unsubscribeStatusActive)); - } - if (accessory instanceof AccessoryWithStatusFault) { - addOptionalCharacteristic( - new StatusFaultCharacteristic( - ((AccessoryWithStatusFault) accessory)::getStatusFault, - ((AccessoryWithStatusFault) accessory)::subscribeStatusFault, - ((AccessoryWithStatusFault) accessory)::unsubscribeStatusFault)); - } - if (accessory instanceof AccessoryWithStatusTampered) { - addOptionalCharacteristic( - new StatusTamperedCharacteristic( - ((AccessoryWithStatusTampered) accessory)::getStatusTampered, - ((AccessoryWithStatusTampered) accessory)::subscribeStatusTampered, - ((AccessoryWithStatusTampered) accessory)::unsubscribeStatusTampered)); - } - if (accessory instanceof AccessoryWithStatusLowBattery) { - addOptionalCharacteristic( - new StatusLowBatteryCharacteristic( - ((AccessoryWithStatusLowBattery) accessory)::getStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::subscribeStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::unsubscribeStatusLowBattery)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(StatusActiveCharacteristic statusActive) { - addCharacteristic(statusActive); - } - - public void addOptionalCharacteristic(StatusFaultCharacteristic statusFault) { - addCharacteristic(statusFault); - } - - public void addOptionalCharacteristic(StatusTamperedCharacteristic statusTampered) { - addCharacteristic(statusTampered); - } - - public void addOptionalCharacteristic(StatusLowBatteryCharacteristic statusLowBattery) { - addCharacteristic(statusLowBattery); - } - - public void addOptionalCharacteristic(CarbonDioxideLevelCharacteristic carbonDioxideLevel) { - addCharacteristic(carbonDioxideLevel); - } - - public void addOptionalCharacteristic( - CarbonDioxidePeakLevelCharacteristic carbonDioxidePeakLevel) { - addCharacteristic(carbonDioxidePeakLevel); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/CarbonMonoxideSensorService.java b/src/main/java/io/github/hapjava/services/impl/CarbonMonoxideSensorService.java deleted file mode 100644 index 11b66c5c4..000000000 --- a/src/main/java/io/github/hapjava/services/impl/CarbonMonoxideSensorService.java +++ /dev/null @@ -1,108 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.CarbonMonoxideSensorAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithCarbonMonoxideLevel; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusActive; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusFault; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusLowBattery; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusTampered; -import io.github.hapjava.characteristics.impl.battery.StatusLowBatteryCharacteristic; -import io.github.hapjava.characteristics.impl.carbonmonoxidesensor.CarbonMonoxideDetectedCharacteristic; -import io.github.hapjava.characteristics.impl.carbonmonoxidesensor.CarbonMonoxideLevelCharacteristic; -import io.github.hapjava.characteristics.impl.carbonmonoxidesensor.CarbonMonoxidePeakLevelCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusFaultCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusTamperedCharacteristic; - -/** This service describes a carbon monoxide sensor. */ -public class CarbonMonoxideSensorService extends AbstractServiceImpl { - - public CarbonMonoxideSensorService(CarbonMonoxideDetectedCharacteristic carbonMonoxideDetected) { - super("0000007F-0000-1000-8000-0026BB765291"); - addCharacteristic(carbonMonoxideDetected); - } - - public CarbonMonoxideSensorService(CarbonMonoxideSensorAccessory accessory) { - this( - new CarbonMonoxideDetectedCharacteristic( - accessory::getCarbonMonoxideDetectedState, - accessory::subscribeCarbonMonoxideDetectedState, - accessory::unsubscribeCarbonMonoxideDetectedState)); - - if (accessory instanceof AccessoryWithCarbonMonoxideLevel) { - addOptionalCharacteristic( - new CarbonMonoxideLevelCharacteristic( - ((AccessoryWithCarbonMonoxideLevel) accessory)::getCarbonMonoxideLevel, - ((AccessoryWithCarbonMonoxideLevel) accessory)::subscribeCarbonMonoxideLevel, - ((AccessoryWithCarbonMonoxideLevel) accessory)::unsubscribeCarbonMonoxideLevel)); - addOptionalCharacteristic( - new CarbonMonoxidePeakLevelCharacteristic( - ((AccessoryWithCarbonMonoxideLevel) accessory)::getCarbonMonoxidePeakLevel, - ((AccessoryWithCarbonMonoxideLevel) accessory)::subscribeCarbonMonoxidePeakLevel, - ((AccessoryWithCarbonMonoxideLevel) accessory)::unsubscribeCarbonMonoxidePeakLevel)); - } - - if (accessory instanceof AccessoryWithStatusActive) { - addOptionalCharacteristic( - new StatusActiveCharacteristic( - ((AccessoryWithStatusActive) accessory)::getStatusActive, - ((AccessoryWithStatusActive) accessory)::subscribeStatusActive, - ((AccessoryWithStatusActive) accessory)::unsubscribeStatusActive)); - } - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithStatusFault) { - addOptionalCharacteristic( - new StatusFaultCharacteristic( - ((AccessoryWithStatusFault) accessory)::getStatusFault, - ((AccessoryWithStatusFault) accessory)::subscribeStatusFault, - ((AccessoryWithStatusFault) accessory)::unsubscribeStatusFault)); - } - if (accessory instanceof AccessoryWithStatusTampered) { - addOptionalCharacteristic( - new StatusTamperedCharacteristic( - ((AccessoryWithStatusTampered) accessory)::getStatusTampered, - ((AccessoryWithStatusTampered) accessory)::subscribeStatusTampered, - ((AccessoryWithStatusTampered) accessory)::unsubscribeStatusTampered)); - } - if (accessory instanceof AccessoryWithStatusLowBattery) { - addOptionalCharacteristic( - new StatusLowBatteryCharacteristic( - ((AccessoryWithStatusLowBattery) accessory)::getStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::subscribeStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::unsubscribeStatusLowBattery)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(StatusActiveCharacteristic statusActive) { - addCharacteristic(statusActive); - } - - public void addOptionalCharacteristic(StatusFaultCharacteristic statusFault) { - addCharacteristic(statusFault); - } - - public void addOptionalCharacteristic(StatusTamperedCharacteristic statusTampered) { - addCharacteristic(statusTampered); - } - - public void addOptionalCharacteristic(StatusLowBatteryCharacteristic statusLowBattery) { - addCharacteristic(statusLowBattery); - } - - public void addOptionalCharacteristic(CarbonMonoxideLevelCharacteristic carbonMonoxideLevel) { - addCharacteristic(carbonMonoxideLevel); - } - - public void addOptionalCharacteristic( - CarbonMonoxidePeakLevelCharacteristic carbonMonoxidePeakLevel) { - addCharacteristic(carbonMonoxidePeakLevel); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/ContactSensorService.java b/src/main/java/io/github/hapjava/services/impl/ContactSensorService.java deleted file mode 100644 index 675553697..000000000 --- a/src/main/java/io/github/hapjava/services/impl/ContactSensorService.java +++ /dev/null @@ -1,83 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.ContactSensorAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusActive; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusFault; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusLowBattery; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusTampered; -import io.github.hapjava.characteristics.impl.battery.StatusLowBatteryCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusFaultCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusTamperedCharacteristic; -import io.github.hapjava.characteristics.impl.contactsensor.ContactSensorStateCharacteristic; - -/** This service describes a Contact Sensor. */ -public class ContactSensorService extends AbstractServiceImpl { - - public ContactSensorService(ContactSensorStateCharacteristic contactSensorState) { - super("00000080-0000-1000-8000-0026BB765291"); - addCharacteristic(contactSensorState); - } - - public ContactSensorService(ContactSensorAccessory accessory) { - this( - new ContactSensorStateCharacteristic( - accessory::getCurrentState, - accessory::subscribeContactState, - accessory::unsubscribeContactState)); - - if (accessory instanceof AccessoryWithStatusActive) { - addOptionalCharacteristic( - new StatusActiveCharacteristic( - ((AccessoryWithStatusActive) accessory)::getStatusActive, - ((AccessoryWithStatusActive) accessory)::subscribeStatusActive, - ((AccessoryWithStatusActive) accessory)::unsubscribeStatusActive)); - } - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithStatusFault) { - addOptionalCharacteristic( - new StatusFaultCharacteristic( - ((AccessoryWithStatusFault) accessory)::getStatusFault, - ((AccessoryWithStatusFault) accessory)::subscribeStatusFault, - ((AccessoryWithStatusFault) accessory)::unsubscribeStatusFault)); - } - if (accessory instanceof AccessoryWithStatusTampered) { - addOptionalCharacteristic( - new StatusTamperedCharacteristic( - ((AccessoryWithStatusTampered) accessory)::getStatusTampered, - ((AccessoryWithStatusTampered) accessory)::subscribeStatusTampered, - ((AccessoryWithStatusTampered) accessory)::unsubscribeStatusTampered)); - } - if (accessory instanceof AccessoryWithStatusLowBattery) { - addOptionalCharacteristic( - new StatusLowBatteryCharacteristic( - ((AccessoryWithStatusLowBattery) accessory)::getStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::subscribeStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::unsubscribeStatusLowBattery)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(StatusActiveCharacteristic statusActive) { - addCharacteristic(statusActive); - } - - public void addOptionalCharacteristic(StatusFaultCharacteristic statusFault) { - addCharacteristic(statusFault); - } - - public void addOptionalCharacteristic(StatusTamperedCharacteristic statusTampered) { - addCharacteristic(statusTampered); - } - - public void addOptionalCharacteristic(StatusLowBatteryCharacteristic statusLowBattery) { - addCharacteristic(statusLowBattery); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/DoorService.java b/src/main/java/io/github/hapjava/services/impl/DoorService.java deleted file mode 100644 index 51f956f5f..000000000 --- a/src/main/java/io/github/hapjava/services/impl/DoorService.java +++ /dev/null @@ -1,84 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.DoorAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithHoldPosition; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithMute; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithObstructionDetection; -import io.github.hapjava.characteristics.impl.audio.MuteCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.ObstructionDetectedCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.CurrentPositionCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.HoldPositionCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.PositionStateCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.TargetPositionCharacteristic; - -/** This service describes a motorized door. */ -public class DoorService extends AbstractServiceImpl { - - public DoorService( - CurrentPositionCharacteristic currentPositionCharacteristic, - TargetPositionCharacteristic targetPositionCharacteristic, - PositionStateCharacteristic positionStateCharacteristic) { - super("00000081-0000-1000-8000-0026BB765291"); - addCharacteristic(currentPositionCharacteristic); - addCharacteristic(targetPositionCharacteristic); - addCharacteristic(positionStateCharacteristic); - } - - public DoorService(DoorAccessory accessory) { - this( - new CurrentPositionCharacteristic( - accessory::getCurrentPosition, - accessory::subscribeCurrentPosition, - accessory::unsubscribeCurrentPosition), - new TargetPositionCharacteristic( - accessory::getTargetPosition, - accessory::setTargetPosition, - accessory::subscribeTargetPosition, - accessory::unsubscribeTargetPosition), - new PositionStateCharacteristic( - accessory::getPositionState, - accessory::subscribePositionState, - accessory::unsubscribePositionState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithHoldPosition) { - addOptionalCharacteristic( - new HoldPositionCharacteristic(((AccessoryWithHoldPosition) accessory)::setHoldPosition)); - } - if (accessory instanceof AccessoryWithObstructionDetection) { - addOptionalCharacteristic( - new ObstructionDetectedCharacteristic( - ((AccessoryWithObstructionDetection) accessory)::getObstructionDetected, - ((AccessoryWithObstructionDetection) accessory)::subscribeObstructionDetected, - ((AccessoryWithObstructionDetection) accessory)::unsubscribeObstructionDetected)); - } - if (accessory instanceof AccessoryWithMute) { - addOptionalCharacteristic( - new MuteCharacteristic( - ((AccessoryWithMute) accessory)::isMuted, - ((AccessoryWithMute) accessory)::setMute, - ((AccessoryWithMute) accessory)::subscribeMuteState, - ((AccessoryWithMute) accessory)::unsubscribeMuteState)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(HoldPositionCharacteristic holdPositionCharacteristic) { - addCharacteristic(holdPositionCharacteristic); - } - - public void addOptionalCharacteristic( - ObstructionDetectedCharacteristic obstructionDetectedCharacteristic) { - addCharacteristic(obstructionDetectedCharacteristic); - } - - public void addOptionalCharacteristic(MuteCharacteristic muteCharacteristic) { - addCharacteristic(muteCharacteristic); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/DoorbellService.java b/src/main/java/io/github/hapjava/services/impl/DoorbellService.java deleted file mode 100644 index fd8fc7004..000000000 --- a/src/main/java/io/github/hapjava/services/impl/DoorbellService.java +++ /dev/null @@ -1,58 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.DoorbellAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithBrightness; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithVolume; -import io.github.hapjava.characteristics.impl.audio.VolumeCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.ProgrammableSwitchEventCharacteristic; -import io.github.hapjava.characteristics.impl.lightbulb.BrightnessCharacteristic; - -/** The Doorbell service describes a doorbell. */ -public class DoorbellService extends AbstractServiceImpl { - - public DoorbellService(ProgrammableSwitchEventCharacteristic switchEvent) { - super("00000121-0000-1000-8000-0026BB765291"); - addCharacteristic(switchEvent); - } - - public DoorbellService(DoorbellAccessory accessory) { - this( - new ProgrammableSwitchEventCharacteristic( - accessory::getSwitchEvent, - accessory::subscribeSwitchEvent, - accessory::unsubscribeSwitchEvent)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithBrightness) { - addOptionalCharacteristic( - new BrightnessCharacteristic( - ((AccessoryWithBrightness) accessory)::getBrightness, - ((AccessoryWithBrightness) accessory)::setBrightness, - ((AccessoryWithBrightness) accessory)::subscribeBrightness, - ((AccessoryWithBrightness) accessory)::unsubscribeBrightness)); - } - if (accessory instanceof AccessoryWithVolume) { - addOptionalCharacteristic( - new VolumeCharacteristic( - ((AccessoryWithVolume) accessory)::getVolume, - ((AccessoryWithVolume) accessory)::setVolume, - ((AccessoryWithVolume) accessory)::subscribeVolume, - ((AccessoryWithVolume) accessory)::unsubscribeVolume)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(BrightnessCharacteristic brightness) { - addCharacteristic(brightness); - } - - public void addOptionalCharacteristic(VolumeCharacteristic volume) { - addCharacteristic(volume); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/FanService.java b/src/main/java/io/github/hapjava/services/impl/FanService.java deleted file mode 100644 index a8f3a7103..000000000 --- a/src/main/java/io/github/hapjava/services/impl/FanService.java +++ /dev/null @@ -1,118 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.FanAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithFanState; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithPhysicalControlsLock; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithRotationDirection; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithRotationSpeed; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithSwingMode; -import io.github.hapjava.characteristics.impl.common.ActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.ActiveEnum; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.fan.CurrentFanStateCharacteristic; -import io.github.hapjava.characteristics.impl.fan.LockPhysicalControlsCharacteristic; -import io.github.hapjava.characteristics.impl.fan.RotationDirectionCharacteristic; -import io.github.hapjava.characteristics.impl.fan.RotationSpeedCharacteristic; -import io.github.hapjava.characteristics.impl.fan.SwingModeCharacteristic; -import io.github.hapjava.characteristics.impl.fan.TargetFanStateCharacteristic; - -/** - * This service describes a fan. - * - *

In the R1 release of the HAP specification, this is described as Fan v2. In the R1 release of - * the HAP specification, this is simply described as Fan. - */ -public class FanService extends AbstractServiceImpl { - - public FanService(ActiveCharacteristic active) { - super("000000B7-0000-1000-8000-0026BB765291"); - addCharacteristic(active); - } - - public FanService(FanAccessory accessory) { - this( - new ActiveCharacteristic( - () -> accessory.isActive().thenApply(s -> s ? ActiveEnum.ACTIVE : ActiveEnum.INACTIVE), - (v) -> accessory.setActive(v == ActiveEnum.ACTIVE), - accessory::subscribeActive, - accessory::unsubscribeActive)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - - if (accessory instanceof AccessoryWithFanState) { - addOptionalCharacteristic( - new CurrentFanStateCharacteristic( - ((AccessoryWithFanState) accessory)::getCurrentFanState, - ((AccessoryWithFanState) accessory)::subscribeCurrentFanState, - ((AccessoryWithFanState) accessory)::unsubscribeCurrentFanState)); - addOptionalCharacteristic( - new TargetFanStateCharacteristic( - ((AccessoryWithFanState) accessory)::getTargetFanState, - ((AccessoryWithFanState) accessory)::setTargetFanState, - ((AccessoryWithFanState) accessory)::subscribeTargetFanState, - ((AccessoryWithFanState) accessory)::unsubscribeTargetFanState)); - } - if (accessory instanceof AccessoryWithRotationDirection) { - addOptionalCharacteristic( - new RotationDirectionCharacteristic( - ((AccessoryWithRotationDirection) accessory)::getRotationDirection, - ((AccessoryWithRotationDirection) accessory)::setRotationDirection, - ((AccessoryWithRotationDirection) accessory)::subscribeRotationDirection, - ((AccessoryWithRotationDirection) accessory)::unsubscribeRotationDirection)); - } - if (accessory instanceof AccessoryWithRotationSpeed) { - addOptionalCharacteristic( - new RotationSpeedCharacteristic( - ((AccessoryWithRotationSpeed) accessory)::getRotationSpeed, - ((AccessoryWithRotationSpeed) accessory)::setRotationSpeed, - ((AccessoryWithRotationSpeed) accessory)::subscribeRotationSpeed, - ((AccessoryWithRotationSpeed) accessory)::unsubscribeRotationSpeed)); - } - if (accessory instanceof AccessoryWithSwingMode) { - addOptionalCharacteristic( - new SwingModeCharacteristic( - ((AccessoryWithSwingMode) accessory)::getSwingMode, - ((AccessoryWithSwingMode) accessory)::setSwingMode, - ((AccessoryWithSwingMode) accessory)::subscribeSwingMode, - ((AccessoryWithSwingMode) accessory)::unsubscribeSwingMode)); - } - if (accessory instanceof AccessoryWithPhysicalControlsLock) { - addOptionalCharacteristic( - new LockPhysicalControlsCharacteristic( - ((AccessoryWithPhysicalControlsLock) accessory)::getLockControls, - ((AccessoryWithPhysicalControlsLock) accessory)::setLockControls, - ((AccessoryWithPhysicalControlsLock) accessory)::subscribeLockControls, - ((AccessoryWithPhysicalControlsLock) accessory)::unsubscribeLockControls)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(CurrentFanStateCharacteristic state) { - addCharacteristic(state); - } - - public void addOptionalCharacteristic(TargetFanStateCharacteristic state) { - addCharacteristic(state); - } - - public void addOptionalCharacteristic(RotationDirectionCharacteristic direction) { - addCharacteristic(direction); - } - - public void addOptionalCharacteristic(RotationSpeedCharacteristic speed) { - addCharacteristic(speed); - } - - public void addOptionalCharacteristic(SwingModeCharacteristic mode) { - addCharacteristic(mode); - } - - public void addOptionalCharacteristic(LockPhysicalControlsCharacteristic lock) { - addCharacteristic(lock); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/FaucetService.java b/src/main/java/io/github/hapjava/services/impl/FaucetService.java deleted file mode 100644 index 1028fa9b1..000000000 --- a/src/main/java/io/github/hapjava/services/impl/FaucetService.java +++ /dev/null @@ -1,50 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.FaucetAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusFault; -import io.github.hapjava.characteristics.impl.common.ActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.ActiveEnum; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusFaultCharacteristic; - -/** - * This service describes accessories like faucets or shower heads and must only be included when an - * accessory has either a linked {@link HeaterCoolerService}, single linked {@link ValveService} or - * multiple linked {@link ValveService} (with/without {@link HeaterCoolerService} to describe water - * outlets. This service serves as a top level service for such accessories. - */ -public class FaucetService extends AbstractServiceImpl { - - public FaucetService(ActiveCharacteristic active) { - super("000000D7-0000-1000-8000-0026BB765291"); - addCharacteristic(active); - } - - public FaucetService(FaucetAccessory accessory) { - this( - new ActiveCharacteristic( - () -> accessory.isActive().thenApply(s -> s ? ActiveEnum.ACTIVE : ActiveEnum.INACTIVE), - (v) -> accessory.setActive(v == ActiveEnum.ACTIVE), - accessory::subscribeActive, - accessory::unsubscribeActive)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithStatusFault) { - addOptionalCharacteristic( - new StatusFaultCharacteristic( - ((AccessoryWithStatusFault) accessory)::getStatusFault, - ((AccessoryWithStatusFault) accessory)::subscribeStatusFault, - ((AccessoryWithStatusFault) accessory)::unsubscribeStatusFault)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(StatusFaultCharacteristic statusFault) { - addCharacteristic(statusFault); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/FilterMaintenanceService.java b/src/main/java/io/github/hapjava/services/impl/FilterMaintenanceService.java deleted file mode 100644 index 10788cdea..000000000 --- a/src/main/java/io/github/hapjava/services/impl/FilterMaintenanceService.java +++ /dev/null @@ -1,57 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.FilterMaintenanceAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithFilterLifeLevel; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithResetFilterIndication; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.filtermaintenance.FilterChangeIndicationCharacteristic; -import io.github.hapjava.characteristics.impl.filtermaintenance.FilterLifeLevelCharacteristic; -import io.github.hapjava.characteristics.impl.filtermaintenance.ResetFilterIndicationCharacteristic; - -/** This service describes a filter maintenance. */ -public class FilterMaintenanceService extends AbstractServiceImpl { - - public FilterMaintenanceService(FilterChangeIndicationCharacteristic filerChange) { - super("000000BA-0000-1000-8000-0026BB765291"); - addCharacteristic(filerChange); - } - - public FilterMaintenanceService(FilterMaintenanceAccessory accessory) { - this( - new FilterChangeIndicationCharacteristic( - accessory::getFilterChangeIndication, - accessory::subscribeFilterChangeIndication, - accessory::unsubscribeFilterChangeIndication)); - - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - - if (accessory instanceof AccessoryWithFilterLifeLevel) { - addOptionalCharacteristic( - new FilterLifeLevelCharacteristic( - ((AccessoryWithFilterLifeLevel) accessory)::getFilterLifeLevel, - ((AccessoryWithFilterLifeLevel) accessory)::subscribeFilterLifeLevel, - ((AccessoryWithFilterLifeLevel) accessory)::unsubscribeFilterLifeLevel)); - } - - if (accessory instanceof AccessoryWithResetFilterIndication) { - addOptionalCharacteristic( - new ResetFilterIndicationCharacteristic( - ((AccessoryWithResetFilterIndication) accessory)::resetFilterIndication)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(FilterLifeLevelCharacteristic filterLifeLevel) { - addCharacteristic(filterLifeLevel); - } - - public void addOptionalCharacteristic(ResetFilterIndicationCharacteristic resetFilterIndication) { - addCharacteristic(resetFilterIndication); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/GarageDoorOpenerService.java b/src/main/java/io/github/hapjava/services/impl/GarageDoorOpenerService.java deleted file mode 100644 index b90a7e5ee..000000000 --- a/src/main/java/io/github/hapjava/services/impl/GarageDoorOpenerService.java +++ /dev/null @@ -1,73 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.GarageDoorOpenerAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithLockCurrentState; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithLockTargetState; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.ObstructionDetectedCharacteristic; -import io.github.hapjava.characteristics.impl.garagedoor.CurrentDoorStateCharacteristic; -import io.github.hapjava.characteristics.impl.garagedoor.TargetDoorStateCharacteristic; -import io.github.hapjava.characteristics.impl.lock.LockCurrentStateCharacteristic; -import io.github.hapjava.characteristics.impl.lock.LockTargetStateCharacteristic; - -/** This service describes a garage door opener that controls a single door. */ -public class GarageDoorOpenerService extends AbstractServiceImpl { - - public GarageDoorOpenerService( - CurrentDoorStateCharacteristic currentState, - TargetDoorStateCharacteristic targetState, - ObstructionDetectedCharacteristic obstruction) { - super("00000041-0000-1000-8000-0026BB765291"); - addCharacteristic(currentState); - addCharacteristic(targetState); - addCharacteristic(obstruction); - } - - public GarageDoorOpenerService(GarageDoorOpenerAccessory accessory) { - this( - new CurrentDoorStateCharacteristic( - accessory::getCurrentDoorState, - accessory::subscribeCurrentDoorState, - accessory::unsubscribeCurrentDoorState), - new TargetDoorStateCharacteristic( - accessory::getTargetDoorState, - accessory::setTargetDoorState, - accessory::subscribeTargetDoorState, - accessory::unsubscribeTargetDoorState), - new ObstructionDetectedCharacteristic( - accessory::getObstructionDetected, - accessory::subscribeObstructionDetected, - accessory::unsubscribeObstructionDetected)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithLockCurrentState) { - addOptionalCharacteristic( - new LockCurrentStateCharacteristic( - ((AccessoryWithLockCurrentState) accessory)::getLockCurrentState, - ((AccessoryWithLockCurrentState) accessory)::subscribeLockCurrentState, - ((AccessoryWithLockCurrentState) accessory)::unsubscribeLockCurrentState)); - } - if (accessory instanceof AccessoryWithLockTargetState) { - addOptionalCharacteristic( - new LockTargetStateCharacteristic( - ((AccessoryWithLockTargetState) accessory)::getLockTargetState, - ((AccessoryWithLockTargetState) accessory)::setLockTargetState, - ((AccessoryWithLockTargetState) accessory)::subscribeLockTargetState, - ((AccessoryWithLockTargetState) accessory)::unsubscribeLockTargetState)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(LockCurrentStateCharacteristic lockState) { - addCharacteristic(lockState); - } - - public void addOptionalCharacteristic(LockTargetStateCharacteristic lockState) { - addCharacteristic(lockState); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/HAPProtocolInformationService.java b/src/main/java/io/github/hapjava/services/impl/HAPProtocolInformationService.java deleted file mode 100644 index bc49852f5..000000000 --- a/src/main/java/io/github/hapjava/services/impl/HAPProtocolInformationService.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.characteristics.impl.common.VersionCharacteristic; - -/** This service HAP version. */ -public class HAPProtocolInformationService extends AbstractServiceImpl { - - public HAPProtocolInformationService(VersionCharacteristic versionCharacteristic) { - super("000000A2-0000-1000-8000-0026BB765291"); - addCharacteristic(versionCharacteristic); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/HeaterCoolerService.java b/src/main/java/io/github/hapjava/services/impl/HeaterCoolerService.java deleted file mode 100644 index 5204ae006..000000000 --- a/src/main/java/io/github/hapjava/services/impl/HeaterCoolerService.java +++ /dev/null @@ -1,162 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.HeaterCoolerAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithCoolingThresholdTemperature; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithHeatingThresholdTemperature; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithPhysicalControlsLock; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithRotationSpeed; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithSwingMode; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithTemperatureDisplayUnits; -import io.github.hapjava.characteristics.impl.common.ActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.ActiveEnum; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.fan.LockPhysicalControlsCharacteristic; -import io.github.hapjava.characteristics.impl.fan.RotationSpeedCharacteristic; -import io.github.hapjava.characteristics.impl.fan.SwingModeCharacteristic; -import io.github.hapjava.characteristics.impl.heatercooler.CurrentHeaterCoolerStateCharacteristic; -import io.github.hapjava.characteristics.impl.heatercooler.TargetHeaterCoolerStateCharacteristic; -import io.github.hapjava.characteristics.impl.thermostat.CoolingThresholdTemperatureCharacteristic; -import io.github.hapjava.characteristics.impl.thermostat.CurrentTemperatureCharacteristic; -import io.github.hapjava.characteristics.impl.thermostat.HeatingThresholdTemperatureCharacteristic; -import io.github.hapjava.characteristics.impl.thermostat.TemperatureDisplayUnitCharacteristic; - -/** This service can be used to describe a heater and/or a cooler */ -public class HeaterCoolerService extends AbstractServiceImpl { - - public HeaterCoolerService( - ActiveCharacteristic activeCharacteristic, - CurrentTemperatureCharacteristic currentTemperatureCharacteristic, - CurrentHeaterCoolerStateCharacteristic currentHeaterCoolerStateCharacteristic, - TargetHeaterCoolerStateCharacteristic targetHeaterCoolerStateCharacteristic) { - super("000000BC-0000-1000-8000-0026BB765291"); - addCharacteristic(activeCharacteristic); - addCharacteristic(currentTemperatureCharacteristic); - addCharacteristic(currentHeaterCoolerStateCharacteristic); - addCharacteristic(targetHeaterCoolerStateCharacteristic); - } - - public HeaterCoolerService(HeaterCoolerAccessory accessory) { - this( - new ActiveCharacteristic( - () -> accessory.isActive().thenApply(s -> s ? ActiveEnum.ACTIVE : ActiveEnum.INACTIVE), - (v) -> accessory.setActive(v == ActiveEnum.ACTIVE), - accessory::subscribeActive, - accessory::unsubscribeActive), - new CurrentTemperatureCharacteristic( - accessory::getCurrentTemperature, - accessory::subscribeCurrentTemperature, - accessory::unsubscribeCurrentTemperature), - new CurrentHeaterCoolerStateCharacteristic( - accessory.getCurrentHeaterCoolerStateValidValues(), - accessory::getCurrentHeaterCoolerState, - accessory::subscribeCurrentHeaterCoolerState, - accessory::unsubscribeCurrentHeaterCoolerState), - new TargetHeaterCoolerStateCharacteristic( - accessory.getTargetHeaterCoolerStateValidValues(), - accessory::getTargetHeaterCoolerState, - accessory::setTargetHeaterCoolerState, - accessory::subscribeTargetHeaterCoolerState, - accessory::unsubscribeTargetHeaterCoolerState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithRotationSpeed) { - addOptionalCharacteristic( - new RotationSpeedCharacteristic( - ((AccessoryWithRotationSpeed) accessory)::getRotationSpeed, - ((AccessoryWithRotationSpeed) accessory)::setRotationSpeed, - ((AccessoryWithRotationSpeed) accessory)::subscribeRotationSpeed, - ((AccessoryWithRotationSpeed) accessory)::unsubscribeRotationSpeed)); - } - if (accessory instanceof AccessoryWithSwingMode) { - addOptionalCharacteristic( - new SwingModeCharacteristic( - ((AccessoryWithSwingMode) accessory)::getSwingMode, - ((AccessoryWithSwingMode) accessory)::setSwingMode, - ((AccessoryWithSwingMode) accessory)::subscribeSwingMode, - ((AccessoryWithSwingMode) accessory)::unsubscribeSwingMode)); - } - if (accessory instanceof AccessoryWithPhysicalControlsLock) { - addOptionalCharacteristic( - new LockPhysicalControlsCharacteristic( - ((AccessoryWithPhysicalControlsLock) accessory)::getLockControls, - ((AccessoryWithPhysicalControlsLock) accessory)::setLockControls, - ((AccessoryWithPhysicalControlsLock) accessory)::subscribeLockControls, - ((AccessoryWithPhysicalControlsLock) accessory)::unsubscribeLockControls)); - } - if (accessory instanceof AccessoryWithCoolingThresholdTemperature) { - addOptionalCharacteristic( - new CoolingThresholdTemperatureCharacteristic( - ((AccessoryWithCoolingThresholdTemperature) accessory) - .getMinCoolingThresholdTemperature(), - ((AccessoryWithCoolingThresholdTemperature) accessory) - .getMaxCoolingThresholdTemperature(), - ((AccessoryWithCoolingThresholdTemperature) accessory) - .getStepCoolingThresholdTemperature(), - ((AccessoryWithCoolingThresholdTemperature) accessory) - ::getCoolingThresholdTemperature, - ((AccessoryWithCoolingThresholdTemperature) accessory) - ::setCoolingThresholdTemperature, - ((AccessoryWithCoolingThresholdTemperature) accessory) - ::subscribeCoolingThresholdTemperature, - ((AccessoryWithCoolingThresholdTemperature) accessory) - ::unsubscribeCoolingThresholdTemperature)); - } - if (accessory instanceof AccessoryWithHeatingThresholdTemperature) { - addOptionalCharacteristic( - new HeatingThresholdTemperatureCharacteristic( - ((AccessoryWithHeatingThresholdTemperature) accessory) - .getMinHeatingThresholdTemperature(), - ((AccessoryWithHeatingThresholdTemperature) accessory) - .getMaxHeatingThresholdTemperature(), - ((AccessoryWithHeatingThresholdTemperature) accessory) - .getStepHeatingThresholdTemperature(), - ((AccessoryWithHeatingThresholdTemperature) accessory) - ::getHeatingThresholdTemperature, - ((AccessoryWithHeatingThresholdTemperature) accessory) - ::setHeatingThresholdTemperature, - ((AccessoryWithHeatingThresholdTemperature) accessory) - ::subscribeHeatingThresholdTemperature, - ((AccessoryWithHeatingThresholdTemperature) accessory) - ::unsubscribeHeatingThresholdTemperature)); - } - if (accessory instanceof AccessoryWithTemperatureDisplayUnits) { - addOptionalCharacteristic( - new TemperatureDisplayUnitCharacteristic( - ((AccessoryWithTemperatureDisplayUnits) accessory)::getTemperatureDisplayUnits, - ((AccessoryWithTemperatureDisplayUnits) accessory)::setTemperatureDisplayUnits, - ((AccessoryWithTemperatureDisplayUnits) accessory)::subscribeTemperatureDisplayUnits, - ((AccessoryWithTemperatureDisplayUnits) accessory) - ::unsubscribeTemperatureDisplayUnits)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(RotationSpeedCharacteristic speed) { - addCharacteristic(speed); - } - - public void addOptionalCharacteristic(SwingModeCharacteristic mode) { - addCharacteristic(mode); - } - - public void addOptionalCharacteristic(LockPhysicalControlsCharacteristic lock) { - addCharacteristic(lock); - } - - public void addOptionalCharacteristic(CoolingThresholdTemperatureCharacteristic threshold) { - addCharacteristic(threshold); - } - - public void addOptionalCharacteristic(HeatingThresholdTemperatureCharacteristic threshold) { - addCharacteristic(threshold); - } - - public void addOptionalCharacteristic(TemperatureDisplayUnitCharacteristic displayUnits) { - addCharacteristic(displayUnits); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/HumidifierDehumidifierService.java b/src/main/java/io/github/hapjava/services/impl/HumidifierDehumidifierService.java deleted file mode 100644 index afd1dfdb2..000000000 --- a/src/main/java/io/github/hapjava/services/impl/HumidifierDehumidifierService.java +++ /dev/null @@ -1,143 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.HumidifierDehumidifierAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithHumidityDehumidifierThreshold; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithHumidityHumidifierThreshold; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithPhysicalControlsLock; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithRotationSpeed; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithSwingMode; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithWaterLevel; -import io.github.hapjava.characteristics.impl.common.ActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.ActiveEnum; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.WaterLavelCharacteristic; -import io.github.hapjava.characteristics.impl.fan.LockPhysicalControlsCharacteristic; -import io.github.hapjava.characteristics.impl.fan.RotationSpeedCharacteristic; -import io.github.hapjava.characteristics.impl.fan.SwingModeCharacteristic; -import io.github.hapjava.characteristics.impl.humidifier.CurrentHumidifierDehumidifierStateCharacteristic; -import io.github.hapjava.characteristics.impl.humidifier.HumidityDehumidifierThresholdCharacteristic; -import io.github.hapjava.characteristics.impl.humidifier.HumidityHumidifierThresholdCharacteristic; -import io.github.hapjava.characteristics.impl.humidifier.TargetHumidifierDehumidifierStateCharacteristic; -import io.github.hapjava.characteristics.impl.humiditysensor.CurrentRelativeHumidityCharacteristic; - -/** This service can be used to describe an air humidifier or/and an air dehumidifier. */ -public class HumidifierDehumidifierService extends AbstractServiceImpl { - - public HumidifierDehumidifierService( - ActiveCharacteristic activeCharacteristic, - CurrentRelativeHumidityCharacteristic currentRelativeHumidityCharacteristic, - CurrentHumidifierDehumidifierStateCharacteristic - currentHumidifierDehumidifierStateCharacteristic, - TargetHumidifierDehumidifierStateCharacteristic - targetHumidifierDehumidifierStateCharacteristic) { - super("000000BD-0000-1000-8000-0026BB765291"); - addCharacteristic(activeCharacteristic); - addCharacteristic(currentRelativeHumidityCharacteristic); - addCharacteristic(currentHumidifierDehumidifierStateCharacteristic); - addCharacteristic(targetHumidifierDehumidifierStateCharacteristic); - } - - public HumidifierDehumidifierService(HumidifierDehumidifierAccessory accessory) { - this( - new ActiveCharacteristic( - () -> accessory.isActive().thenApply(s -> s ? ActiveEnum.ACTIVE : ActiveEnum.INACTIVE), - (v) -> accessory.setActive(v == ActiveEnum.ACTIVE), - accessory::subscribeActive, - accessory::unsubscribeActive), - new CurrentRelativeHumidityCharacteristic( - accessory::getCurrentHumidity, - accessory::subscribeCurrentHumidity, - accessory::unsubscribeCurrentHumidity), - new CurrentHumidifierDehumidifierStateCharacteristic( - accessory::getCurrentHumidifierDehumidifierState, - accessory::subscribeCurrentHumidifierDehumidifierState, - accessory::unsubscribeCurrentHumidifierDehumidifierState), - new TargetHumidifierDehumidifierStateCharacteristic( - accessory.getTargetHumidifierDehumidifierStateValidValues(), - accessory::getTargetHumidifierDehumidifierState, - accessory::setTargetHumidifierDehumidifierState, - accessory::subscribeTargetHumidifierDehumidifierState, - accessory::unsubscribeTargetHumidifierDehumidifierState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithRotationSpeed) { - addOptionalCharacteristic( - new RotationSpeedCharacteristic( - ((AccessoryWithRotationSpeed) accessory)::getRotationSpeed, - ((AccessoryWithRotationSpeed) accessory)::setRotationSpeed, - ((AccessoryWithRotationSpeed) accessory)::subscribeRotationSpeed, - ((AccessoryWithRotationSpeed) accessory)::unsubscribeRotationSpeed)); - } - if (accessory instanceof AccessoryWithSwingMode) { - addOptionalCharacteristic( - new SwingModeCharacteristic( - ((AccessoryWithSwingMode) accessory)::getSwingMode, - ((AccessoryWithSwingMode) accessory)::setSwingMode, - ((AccessoryWithSwingMode) accessory)::subscribeSwingMode, - ((AccessoryWithSwingMode) accessory)::unsubscribeSwingMode)); - } - if (accessory instanceof AccessoryWithPhysicalControlsLock) { - addOptionalCharacteristic( - new LockPhysicalControlsCharacteristic( - ((AccessoryWithPhysicalControlsLock) accessory)::getLockControls, - ((AccessoryWithPhysicalControlsLock) accessory)::setLockControls, - ((AccessoryWithPhysicalControlsLock) accessory)::subscribeLockControls, - ((AccessoryWithPhysicalControlsLock) accessory)::unsubscribeLockControls)); - } - if (accessory instanceof AccessoryWithHumidityDehumidifierThreshold) { - addOptionalCharacteristic( - new HumidityDehumidifierThresholdCharacteristic( - ((AccessoryWithHumidityDehumidifierThreshold) accessory)::getHumidityThreshold, - ((AccessoryWithHumidityDehumidifierThreshold) accessory)::setHumidityThreshold, - ((AccessoryWithHumidityDehumidifierThreshold) accessory)::subscribeHumidityThreshold, - ((AccessoryWithHumidityDehumidifierThreshold) accessory) - ::unsubscribeHumidityThreshold)); - } - if (accessory instanceof AccessoryWithHumidityHumidifierThreshold) { - addOptionalCharacteristic( - new HumidityHumidifierThresholdCharacteristic( - ((AccessoryWithHumidityHumidifierThreshold) accessory)::getHumidityThreshold, - ((AccessoryWithHumidityHumidifierThreshold) accessory)::setHumidityThreshold, - ((AccessoryWithHumidityHumidifierThreshold) accessory)::subscribeHumidityThreshold, - ((AccessoryWithHumidityHumidifierThreshold) accessory) - ::unsubscribeHumidityThreshold)); - } - if (accessory instanceof AccessoryWithWaterLevel) { - addOptionalCharacteristic( - new WaterLavelCharacteristic( - ((AccessoryWithWaterLevel) accessory)::getWaterLevel, - ((AccessoryWithWaterLevel) accessory)::subscribeWaterLevel, - ((AccessoryWithWaterLevel) accessory)::unsubscribeWaterLevel)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(RotationSpeedCharacteristic speed) { - addCharacteristic(speed); - } - - public void addOptionalCharacteristic(SwingModeCharacteristic mode) { - addCharacteristic(mode); - } - - public void addOptionalCharacteristic(LockPhysicalControlsCharacteristic lock) { - addCharacteristic(lock); - } - - public void addOptionalCharacteristic(HumidityDehumidifierThresholdCharacteristic threshold) { - addCharacteristic(threshold); - } - - public void addOptionalCharacteristic(HumidityHumidifierThresholdCharacteristic threshold) { - addCharacteristic(threshold); - } - - public void addOptionalCharacteristic(WaterLavelCharacteristic level) { - addCharacteristic(level); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/HumiditySensorService.java b/src/main/java/io/github/hapjava/services/impl/HumiditySensorService.java deleted file mode 100644 index 4153510a3..000000000 --- a/src/main/java/io/github/hapjava/services/impl/HumiditySensorService.java +++ /dev/null @@ -1,84 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.HumiditySensorAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusActive; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusFault; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusLowBattery; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusTampered; -import io.github.hapjava.characteristics.impl.battery.StatusLowBatteryCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusFaultCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusTamperedCharacteristic; -import io.github.hapjava.characteristics.impl.humiditysensor.CurrentRelativeHumidityCharacteristic; - -/** This service describes a humidity sensor. */ -public class HumiditySensorService extends AbstractServiceImpl { - - public HumiditySensorService( - CurrentRelativeHumidityCharacteristic currentRelativeHumidityCharacteristic) { - super("00000082-0000-1000-8000-0026BB765291"); - addCharacteristic(currentRelativeHumidityCharacteristic); - } - - public HumiditySensorService(HumiditySensorAccessory accessory) { - this( - new CurrentRelativeHumidityCharacteristic( - accessory::getCurrentRelativeHumidity, - accessory::subscribeCurrentRelativeHumidity, - accessory::unsubscribeCurrentRelativeHumidity)); - - if (accessory instanceof AccessoryWithStatusActive) { - addOptionalCharacteristic( - new StatusActiveCharacteristic( - ((AccessoryWithStatusActive) accessory)::getStatusActive, - ((AccessoryWithStatusActive) accessory)::subscribeStatusActive, - ((AccessoryWithStatusActive) accessory)::unsubscribeStatusActive)); - } - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithStatusFault) { - addOptionalCharacteristic( - new StatusFaultCharacteristic( - ((AccessoryWithStatusFault) accessory)::getStatusFault, - ((AccessoryWithStatusFault) accessory)::subscribeStatusFault, - ((AccessoryWithStatusFault) accessory)::unsubscribeStatusFault)); - } - if (accessory instanceof AccessoryWithStatusTampered) { - addOptionalCharacteristic( - new StatusTamperedCharacteristic( - ((AccessoryWithStatusTampered) accessory)::getStatusTampered, - ((AccessoryWithStatusTampered) accessory)::subscribeStatusTampered, - ((AccessoryWithStatusTampered) accessory)::unsubscribeStatusTampered)); - } - if (accessory instanceof AccessoryWithStatusLowBattery) { - addOptionalCharacteristic( - new StatusLowBatteryCharacteristic( - ((AccessoryWithStatusLowBattery) accessory)::getStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::subscribeStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::unsubscribeStatusLowBattery)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(StatusActiveCharacteristic statusActive) { - addCharacteristic(statusActive); - } - - public void addOptionalCharacteristic(StatusFaultCharacteristic statusFault) { - addCharacteristic(statusFault); - } - - public void addOptionalCharacteristic(StatusTamperedCharacteristic statusTampered) { - addCharacteristic(statusTampered); - } - - public void addOptionalCharacteristic(StatusLowBatteryCharacteristic statusLowBattery) { - addCharacteristic(statusLowBattery); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/InputSourceService.java b/src/main/java/io/github/hapjava/services/impl/InputSourceService.java deleted file mode 100644 index 4af2736a2..000000000 --- a/src/main/java/io/github/hapjava/services/impl/InputSourceService.java +++ /dev/null @@ -1,91 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.InputSourceAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithIdentifier; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithInputDeviceType; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithTargetVisibilityState; -import io.github.hapjava.characteristics.impl.common.ConfiguredNameCharacteristic; -import io.github.hapjava.characteristics.impl.common.IdentifierCharacteristic; -import io.github.hapjava.characteristics.impl.common.IsConfiguredCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.inputsource.CurrentVisibilityStateCharacteristic; -import io.github.hapjava.characteristics.impl.inputsource.InputDeviceTypeCharacteristic; -import io.github.hapjava.characteristics.impl.inputsource.InputSourceTypeCharacteristic; -import io.github.hapjava.characteristics.impl.inputsource.TargetVisibilityStateCharacteristic; - -/** This service describes a input source. */ -public class InputSourceService extends AbstractServiceImpl { - - public InputSourceService( - ConfiguredNameCharacteristic configuredNameCharacteristic, - InputSourceTypeCharacteristic inputSourceTypeCharacteristic, - IsConfiguredCharacteristic isConfiguredCharacteristic, - CurrentVisibilityStateCharacteristic currentVisibilityStateCharacteristic) { - super("000000D9-0000-1000-8000-0026BB765291"); - addCharacteristic(configuredNameCharacteristic); - addCharacteristic(inputSourceTypeCharacteristic); - addCharacteristic(isConfiguredCharacteristic); - addCharacteristic(currentVisibilityStateCharacteristic); - } - - public InputSourceService(InputSourceAccessory accessory) { - this( - new ConfiguredNameCharacteristic( - accessory::getConfiguredName, - accessory::setConfiguredName, - accessory::subscribeConfiguredName, - accessory::unsubscribeConfiguredName), - new InputSourceTypeCharacteristic( - accessory::getInputSourceType, - accessory::subscribeInputSourceType, - accessory::unsubscribeInputSourceType), - new IsConfiguredCharacteristic( - accessory::isConfigured, - accessory::setIsConfigured, - accessory::subscribeIsConfigured, - accessory::unsubscribeIsConfigured), - new CurrentVisibilityStateCharacteristic( - accessory::getCurrentVisibilityState, - accessory::subscribeCurrentVisibilityState, - accessory::unsubscribeCurrentVisibilityState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithIdentifier) { - addOptionalCharacteristic( - new IdentifierCharacteristic(((AccessoryWithIdentifier) accessory)::getIdentifier)); - } - if (accessory instanceof AccessoryWithInputDeviceType) { - addOptionalCharacteristic( - new InputDeviceTypeCharacteristic( - ((AccessoryWithInputDeviceType) accessory)::getInputDeviceType, - ((AccessoryWithInputDeviceType) accessory)::subscribeInputDeviceType, - ((AccessoryWithInputDeviceType) accessory)::unsubscribeInputDeviceType)); - } - if (accessory instanceof AccessoryWithTargetVisibilityState) { - addOptionalCharacteristic( - new TargetVisibilityStateCharacteristic( - ((AccessoryWithTargetVisibilityState) accessory)::getTargetVisibilityState, - ((AccessoryWithTargetVisibilityState) accessory)::setTargetVisibilityState, - ((AccessoryWithTargetVisibilityState) accessory)::subscribeTargetVisibilityState, - ((AccessoryWithTargetVisibilityState) accessory)::unsubscribeTargetVisibilityState)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(IdentifierCharacteristic identifier) { - addCharacteristic(identifier); - } - - public void addOptionalCharacteristic(InputDeviceTypeCharacteristic inputDeviceType) { - addCharacteristic(inputDeviceType); - } - - public void addOptionalCharacteristic(TargetVisibilityStateCharacteristic targetVisibilityState) { - addCharacteristic(targetVisibilityState); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/IrrigationSystemService.java b/src/main/java/io/github/hapjava/services/impl/IrrigationSystemService.java deleted file mode 100644 index 3501ba723..000000000 --- a/src/main/java/io/github/hapjava/services/impl/IrrigationSystemService.java +++ /dev/null @@ -1,71 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.IrrigationSystemAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithRemainingDuration; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusFault; -import io.github.hapjava.characteristics.impl.common.ActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.InUseCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.ProgramModeCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusFaultCharacteristic; -import io.github.hapjava.characteristics.impl.valve.RemainingDurationCharacteristic; - -/** An irrigation system service */ -public class IrrigationSystemService extends AbstractServiceImpl { - - public IrrigationSystemService( - ActiveCharacteristic activeCharacteristic, - InUseCharacteristic inUseCharacteristic, - ProgramModeCharacteristic programModeCharacteristic) { - super("000000CF-0000-1000-8000-0026BB765291"); - addCharacteristic(activeCharacteristic); - addCharacteristic(inUseCharacteristic); - addCharacteristic(programModeCharacteristic); - } - - public IrrigationSystemService(IrrigationSystemAccessory accessory) { - this( - new ActiveCharacteristic( - accessory::getActive, - accessory::setActive, - accessory::subscribeActive, - accessory::unsubscribeActive), - new InUseCharacteristic( - accessory::getInUse, accessory::subscribeInUse, accessory::unsubscribeInUse), - new ProgramModeCharacteristic( - accessory::getProgramMode, - accessory::subscribeProgramMode, - accessory::unsubscribeProgramMode)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithStatusFault) { - addOptionalCharacteristic( - new StatusFaultCharacteristic( - ((AccessoryWithStatusFault) accessory)::getStatusFault, - ((AccessoryWithStatusFault) accessory)::subscribeStatusFault, - ((AccessoryWithStatusFault) accessory)::unsubscribeStatusFault)); - } - if (accessory instanceof AccessoryWithRemainingDuration) { - addOptionalCharacteristic( - new RemainingDurationCharacteristic( - ((AccessoryWithRemainingDuration) accessory)::getRemainingDuration, - ((AccessoryWithRemainingDuration) accessory)::subscribeRemainingDuration, - ((AccessoryWithRemainingDuration) accessory)::unsubscribeRemainingDuration)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(StatusFaultCharacteristic statusFaultCharacteristic) { - addCharacteristic(statusFaultCharacteristic); - } - - public void addOptionalCharacteristic( - RemainingDurationCharacteristic remainingDurationCharacteristic) { - addCharacteristic(remainingDurationCharacteristic); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/LeakSensorService.java b/src/main/java/io/github/hapjava/services/impl/LeakSensorService.java deleted file mode 100644 index b8470371a..000000000 --- a/src/main/java/io/github/hapjava/services/impl/LeakSensorService.java +++ /dev/null @@ -1,83 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.LeakSensorAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusActive; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusFault; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusLowBattery; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusTampered; -import io.github.hapjava.characteristics.impl.battery.StatusLowBatteryCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusFaultCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusTamperedCharacteristic; -import io.github.hapjava.characteristics.impl.leaksensor.LeakDetectedStateCharacteristic; - -/** This service describes a leak sensor. */ -public class LeakSensorService extends AbstractServiceImpl { - - public LeakSensorService(LeakDetectedStateCharacteristic leakDetectedState) { - super("00000083-0000-1000-8000-0026BB765291"); - addCharacteristic(leakDetectedState); - } - - public LeakSensorService(LeakSensorAccessory accessory) { - this( - new LeakDetectedStateCharacteristic( - accessory::getLeakDetected, - accessory::subscribeLeakDetected, - accessory::unsubscribeLeakDetected)); - - if (accessory instanceof AccessoryWithStatusActive) { - addOptionalCharacteristic( - new StatusActiveCharacteristic( - ((AccessoryWithStatusActive) accessory)::getStatusActive, - ((AccessoryWithStatusActive) accessory)::subscribeStatusActive, - ((AccessoryWithStatusActive) accessory)::unsubscribeStatusActive)); - } - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithStatusFault) { - addOptionalCharacteristic( - new StatusFaultCharacteristic( - ((AccessoryWithStatusFault) accessory)::getStatusFault, - ((AccessoryWithStatusFault) accessory)::subscribeStatusFault, - ((AccessoryWithStatusFault) accessory)::unsubscribeStatusFault)); - } - if (accessory instanceof AccessoryWithStatusTampered) { - addOptionalCharacteristic( - new StatusTamperedCharacteristic( - ((AccessoryWithStatusTampered) accessory)::getStatusTampered, - ((AccessoryWithStatusTampered) accessory)::subscribeStatusTampered, - ((AccessoryWithStatusTampered) accessory)::unsubscribeStatusTampered)); - } - if (accessory instanceof AccessoryWithStatusLowBattery) { - addOptionalCharacteristic( - new StatusLowBatteryCharacteristic( - ((AccessoryWithStatusLowBattery) accessory)::getStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::subscribeStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::unsubscribeStatusLowBattery)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(StatusActiveCharacteristic statusActive) { - addCharacteristic(statusActive); - } - - public void addOptionalCharacteristic(StatusFaultCharacteristic statusFault) { - addCharacteristic(statusFault); - } - - public void addOptionalCharacteristic(StatusTamperedCharacteristic statusTampered) { - addCharacteristic(statusTampered); - } - - public void addOptionalCharacteristic(StatusLowBatteryCharacteristic statusLowBattery) { - addCharacteristic(statusLowBattery); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/LightSensorService.java b/src/main/java/io/github/hapjava/services/impl/LightSensorService.java deleted file mode 100644 index 6aef8cd34..000000000 --- a/src/main/java/io/github/hapjava/services/impl/LightSensorService.java +++ /dev/null @@ -1,86 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.LightSensorAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusActive; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusFault; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusLowBattery; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusTampered; -import io.github.hapjava.characteristics.impl.battery.StatusLowBatteryCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusFaultCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusTamperedCharacteristic; -import io.github.hapjava.characteristics.impl.lightsensor.CurrentAmbientLightLevelCharacteristic; - -/** This service describes a light sensor. */ -public class LightSensorService extends AbstractServiceImpl { - - public LightSensorService(CurrentAmbientLightLevelCharacteristic lightLevel) { - super("00000084-0000-1000-8000-0026BB765291"); - addCharacteristic(lightLevel); - } - - public LightSensorService(LightSensorAccessory accessory) { - this( - new CurrentAmbientLightLevelCharacteristic( - accessory.getMinCurrentAmbientLightLevel(), - accessory.getMaxCurrentAmbientLightLevel(), - accessory.getMinStepCurrentAmbientLightLevel(), - accessory::getCurrentAmbientLightLevel, - accessory::subscribeCurrentAmbientLightLevel, - accessory::unsubscribeCurrentAmbientLightLevel)); - - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithStatusActive) { - addOptionalCharacteristic( - new StatusActiveCharacteristic( - ((AccessoryWithStatusActive) accessory)::getStatusActive, - ((AccessoryWithStatusActive) accessory)::subscribeStatusActive, - ((AccessoryWithStatusActive) accessory)::unsubscribeStatusActive)); - } - if (accessory instanceof AccessoryWithStatusFault) { - addOptionalCharacteristic( - new StatusFaultCharacteristic( - ((AccessoryWithStatusFault) accessory)::getStatusFault, - ((AccessoryWithStatusFault) accessory)::subscribeStatusFault, - ((AccessoryWithStatusFault) accessory)::unsubscribeStatusFault)); - } - if (accessory instanceof AccessoryWithStatusTampered) { - addOptionalCharacteristic( - new StatusTamperedCharacteristic( - ((AccessoryWithStatusTampered) accessory)::getStatusTampered, - ((AccessoryWithStatusTampered) accessory)::subscribeStatusTampered, - ((AccessoryWithStatusTampered) accessory)::unsubscribeStatusTampered)); - } - if (accessory instanceof AccessoryWithStatusLowBattery) { - addOptionalCharacteristic( - new StatusLowBatteryCharacteristic( - ((AccessoryWithStatusLowBattery) accessory)::getStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::subscribeStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::unsubscribeStatusLowBattery)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(StatusActiveCharacteristic statusActive) { - addCharacteristic(statusActive); - } - - public void addOptionalCharacteristic(StatusFaultCharacteristic statusFault) { - addCharacteristic(statusFault); - } - - public void addOptionalCharacteristic(StatusTamperedCharacteristic statusTampered) { - addCharacteristic(statusTampered); - } - - public void addOptionalCharacteristic(StatusLowBatteryCharacteristic statusLowBattery) { - addCharacteristic(statusLowBattery); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/LightbulbService.java b/src/main/java/io/github/hapjava/services/impl/LightbulbService.java deleted file mode 100644 index b37ca4d2c..000000000 --- a/src/main/java/io/github/hapjava/services/impl/LightbulbService.java +++ /dev/null @@ -1,86 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.LightbulbAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithBrightness; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithColor; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithColorTemperature; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.OnCharacteristic; -import io.github.hapjava.characteristics.impl.lightbulb.BrightnessCharacteristic; -import io.github.hapjava.characteristics.impl.lightbulb.ColorTemperatureCharacteristic; -import io.github.hapjava.characteristics.impl.lightbulb.HueCharacteristic; -import io.github.hapjava.characteristics.impl.lightbulb.SaturationCharacteristic; - -/** This service describes a light bulb. */ -public class LightbulbService extends AbstractServiceImpl { - - public LightbulbService(OnCharacteristic onState) { - super("00000043-0000-1000-8000-0026BB765291"); - addCharacteristic(onState); - } - - public LightbulbService(LightbulbAccessory accessory) { - this( - new OnCharacteristic( - accessory::getLightbulbPowerState, - accessory::setLightbulbPowerState, - accessory::subscribeLightbulbPowerState, - accessory::unsubscribeLightbulbPowerState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithColor) { - addOptionalCharacteristic( - new HueCharacteristic( - ((AccessoryWithColor) accessory)::getHue, - ((AccessoryWithColor) accessory)::setHue, - ((AccessoryWithColor) accessory)::subscribeHue, - ((AccessoryWithColor) accessory)::unsubscribeHue)); - addOptionalCharacteristic( - new SaturationCharacteristic( - ((AccessoryWithColor) accessory)::getSaturation, - ((AccessoryWithColor) accessory)::setSaturation, - ((AccessoryWithColor) accessory)::subscribeSaturation, - ((AccessoryWithColor) accessory)::unsubscribeSaturation)); - } - if (accessory instanceof AccessoryWithBrightness) { - addOptionalCharacteristic( - new BrightnessCharacteristic( - ((AccessoryWithBrightness) accessory)::getBrightness, - ((AccessoryWithBrightness) accessory)::setBrightness, - ((AccessoryWithBrightness) accessory)::subscribeBrightness, - ((AccessoryWithBrightness) accessory)::unsubscribeBrightness)); - } - if (accessory instanceof AccessoryWithColorTemperature) { - addOptionalCharacteristic( - new ColorTemperatureCharacteristic( - ((AccessoryWithColorTemperature) accessory).getMinColorTemperature(), - ((AccessoryWithColorTemperature) accessory).getMaxColorTemperature(), - ((AccessoryWithColorTemperature) accessory)::getColorTemperature, - ((AccessoryWithColorTemperature) accessory)::setColorTemperature, - ((AccessoryWithColorTemperature) accessory)::subscribeColorTemperature, - ((AccessoryWithColorTemperature) accessory)::unsubscribeColorTemperature)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(HueCharacteristic hue) { - addCharacteristic(hue); - } - - public void addOptionalCharacteristic(BrightnessCharacteristic brightness) { - addCharacteristic(brightness); - } - - public void addOptionalCharacteristic(SaturationCharacteristic saturation) { - addCharacteristic(saturation); - } - - public void addOptionalCharacteristic(ColorTemperatureCharacteristic color) { - addCharacteristic(color); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/LockMechanismService.java b/src/main/java/io/github/hapjava/services/impl/LockMechanismService.java deleted file mode 100644 index de59ca516..000000000 --- a/src/main/java/io/github/hapjava/services/impl/LockMechanismService.java +++ /dev/null @@ -1,39 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.LockMechanismAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.lock.LockCurrentStateCharacteristic; -import io.github.hapjava.characteristics.impl.lock.LockTargetStateCharacteristic; - -/** The Lock Mechanism Service describes the physical lock mechanism on a device. */ -public class LockMechanismService extends AbstractServiceImpl { - - public LockMechanismService( - LockCurrentStateCharacteristic lockCurrentState, - LockTargetStateCharacteristic lockTargetState) { - super("00000045-0000-1000-8000-0026BB765291"); - addCharacteristic(lockCurrentState); - addCharacteristic(lockTargetState); - } - - public LockMechanismService(LockMechanismAccessory accessory) { - this( - new LockCurrentStateCharacteristic( - accessory::getLockCurrentState, - accessory::subscribeLockCurrentState, - accessory::unsubscribeLockCurrentState), - new LockTargetStateCharacteristic( - accessory::getLockTargetState, - accessory::setLockTargetState, - accessory::subscribeLockTargetState, - accessory::unsubscribeLockTargetState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/MicrophoneService.java b/src/main/java/io/github/hapjava/services/impl/MicrophoneService.java deleted file mode 100644 index 3f72bd4f7..000000000 --- a/src/main/java/io/github/hapjava/services/impl/MicrophoneService.java +++ /dev/null @@ -1,48 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.MicrophoneAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithVolume; -import io.github.hapjava.characteristics.impl.audio.MuteCharacteristic; -import io.github.hapjava.characteristics.impl.audio.VolumeCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; - -/** - * A Microphone service is used to control the sourcing of the input audio – primarily through a - * microphone. - */ -public class MicrophoneService extends AbstractServiceImpl { - - public MicrophoneService(MuteCharacteristic muteCharacteristic) { - super("00000112-0000-1000-8000-0026BB765291"); - addCharacteristic(muteCharacteristic); - } - - public MicrophoneService(MicrophoneAccessory accessory) { - this( - new MuteCharacteristic( - accessory::isMuted, - accessory::setMute, - accessory::subscribeMuteState, - accessory::unsubscribeMuteState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithVolume) { - addOptionalCharacteristic( - new VolumeCharacteristic( - ((AccessoryWithVolume) accessory)::getVolume, - ((AccessoryWithVolume) accessory)::setVolume, - ((AccessoryWithVolume) accessory)::subscribeVolume, - ((AccessoryWithVolume) accessory)::unsubscribeVolume)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(VolumeCharacteristic volume) { - addCharacteristic(volume); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/MotionSensorService.java b/src/main/java/io/github/hapjava/services/impl/MotionSensorService.java deleted file mode 100644 index 388448b35..000000000 --- a/src/main/java/io/github/hapjava/services/impl/MotionSensorService.java +++ /dev/null @@ -1,82 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.MotionSensorAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusActive; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusFault; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusLowBattery; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusTampered; -import io.github.hapjava.characteristics.impl.battery.StatusLowBatteryCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusFaultCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusTamperedCharacteristic; -import io.github.hapjava.characteristics.impl.motionsensor.MotionDetectedCharacteristic; - -/** This service describes a motion sensor. */ -public class MotionSensorService extends AbstractServiceImpl { - - public MotionSensorService(MotionDetectedCharacteristic motionDetectedCharacteristic) { - super("00000085-0000-1000-8000-0026BB765291"); - addCharacteristic(motionDetectedCharacteristic); - } - - public MotionSensorService(MotionSensorAccessory accessory) { - this( - new MotionDetectedCharacteristic( - accessory::getMotionDetected, - accessory::subscribeMotionDetected, - accessory::unsubscribeMotionDetected)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithStatusActive) { - addOptionalCharacteristic( - new StatusActiveCharacteristic( - ((AccessoryWithStatusActive) accessory)::getStatusActive, - ((AccessoryWithStatusActive) accessory)::subscribeStatusActive, - ((AccessoryWithStatusActive) accessory)::unsubscribeStatusActive)); - } - if (accessory instanceof AccessoryWithStatusFault) { - addOptionalCharacteristic( - new StatusFaultCharacteristic( - ((AccessoryWithStatusFault) accessory)::getStatusFault, - ((AccessoryWithStatusFault) accessory)::subscribeStatusFault, - ((AccessoryWithStatusFault) accessory)::unsubscribeStatusFault)); - } - if (accessory instanceof AccessoryWithStatusTampered) { - addOptionalCharacteristic( - new StatusTamperedCharacteristic( - ((AccessoryWithStatusTampered) accessory)::getStatusTampered, - ((AccessoryWithStatusTampered) accessory)::subscribeStatusTampered, - ((AccessoryWithStatusTampered) accessory)::unsubscribeStatusTampered)); - } - if (accessory instanceof AccessoryWithStatusLowBattery) { - addOptionalCharacteristic( - new StatusLowBatteryCharacteristic( - ((AccessoryWithStatusLowBattery) accessory)::getStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::subscribeStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::unsubscribeStatusLowBattery)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(StatusActiveCharacteristic statusActive) { - addCharacteristic(statusActive); - } - - public void addOptionalCharacteristic(StatusFaultCharacteristic statusFault) { - addCharacteristic(statusFault); - } - - public void addOptionalCharacteristic(StatusTamperedCharacteristic statusTampered) { - addCharacteristic(statusTampered); - } - - public void addOptionalCharacteristic(StatusLowBatteryCharacteristic statusLowBattery) { - addCharacteristic(statusLowBattery); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/OccupancySensorService.java b/src/main/java/io/github/hapjava/services/impl/OccupancySensorService.java deleted file mode 100644 index 12771e60e..000000000 --- a/src/main/java/io/github/hapjava/services/impl/OccupancySensorService.java +++ /dev/null @@ -1,82 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.OccupancySensorAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusActive; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusFault; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusLowBattery; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusTampered; -import io.github.hapjava.characteristics.impl.battery.StatusLowBatteryCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusFaultCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusTamperedCharacteristic; -import io.github.hapjava.characteristics.impl.occupancysensor.OccupancyDetectedCharacteristic; - -/** This service describes an occupancy sensor. */ -public class OccupancySensorService extends AbstractServiceImpl { - - public OccupancySensorService(OccupancyDetectedCharacteristic occupancyDetectedCharacteristic) { - super("00000086-0000-1000-8000-0026BB765291"); - addCharacteristic(occupancyDetectedCharacteristic); - } - - public OccupancySensorService(OccupancySensorAccessory accessory) { - this( - new OccupancyDetectedCharacteristic( - accessory::getOccupancyDetected, - accessory::subscribeOccupancyDetected, - accessory::unsubscribeOccupancyDetected)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithStatusActive) { - addOptionalCharacteristic( - new StatusActiveCharacteristic( - ((AccessoryWithStatusActive) accessory)::getStatusActive, - ((AccessoryWithStatusActive) accessory)::subscribeStatusActive, - ((AccessoryWithStatusActive) accessory)::unsubscribeStatusActive)); - } - if (accessory instanceof AccessoryWithStatusFault) { - addOptionalCharacteristic( - new StatusFaultCharacteristic( - ((AccessoryWithStatusFault) accessory)::getStatusFault, - ((AccessoryWithStatusFault) accessory)::subscribeStatusFault, - ((AccessoryWithStatusFault) accessory)::unsubscribeStatusFault)); - } - if (accessory instanceof AccessoryWithStatusTampered) { - addOptionalCharacteristic( - new StatusTamperedCharacteristic( - ((AccessoryWithStatusTampered) accessory)::getStatusTampered, - ((AccessoryWithStatusTampered) accessory)::subscribeStatusTampered, - ((AccessoryWithStatusTampered) accessory)::unsubscribeStatusTampered)); - } - if (accessory instanceof AccessoryWithStatusLowBattery) { - addOptionalCharacteristic( - new StatusLowBatteryCharacteristic( - ((AccessoryWithStatusLowBattery) accessory)::getStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::subscribeStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::unsubscribeStatusLowBattery)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(StatusActiveCharacteristic statusActive) { - addCharacteristic(statusActive); - } - - public void addOptionalCharacteristic(StatusFaultCharacteristic statusFault) { - addCharacteristic(statusFault); - } - - public void addOptionalCharacteristic(StatusTamperedCharacteristic statusTampered) { - addCharacteristic(statusTampered); - } - - public void addOptionalCharacteristic(StatusLowBatteryCharacteristic statusLowBattery) { - addCharacteristic(statusLowBattery); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/OutletService.java b/src/main/java/io/github/hapjava/services/impl/OutletService.java deleted file mode 100644 index 780024f1f..000000000 --- a/src/main/java/io/github/hapjava/services/impl/OutletService.java +++ /dev/null @@ -1,37 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.OutletAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.OnCharacteristic; -import io.github.hapjava.characteristics.impl.outlet.OutletInUseCharacteristic; - -/** This service describes a power outlet. */ -public class OutletService extends AbstractServiceImpl { - - public OutletService(OnCharacteristic onState, OutletInUseCharacteristic outletInUse) { - super("00000047-0000-1000-8000-0026BB765291"); - addCharacteristic(onState); - addCharacteristic(outletInUse); - } - - public OutletService(OutletAccessory accessory) { - this( - new OnCharacteristic( - accessory::getPowerState, - accessory::setPowerState, - accessory::subscribePowerState, - accessory::unsubscribePowerState), - new OutletInUseCharacteristic( - accessory::getOutletInUse, - accessory::subscribeOutletInUse, - accessory::unsubscribeOutletInUse)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/SecuritySystemService.java b/src/main/java/io/github/hapjava/services/impl/SecuritySystemService.java deleted file mode 100644 index f2bc8d02e..000000000 --- a/src/main/java/io/github/hapjava/services/impl/SecuritySystemService.java +++ /dev/null @@ -1,80 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.SecuritySystemAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithSecurityAlarmType; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusFault; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusTampered; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusFaultCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusTamperedCharacteristic; -import io.github.hapjava.characteristics.impl.securitysystem.CurrentSecuritySystemStateCharacteristic; -import io.github.hapjava.characteristics.impl.securitysystem.SecuritySystemAlarmTypeCharacteristic; -import io.github.hapjava.characteristics.impl.securitysystem.TargetSecuritySystemStateCharacteristic; - -/** This service describes a security system service. */ -public class SecuritySystemService extends AbstractServiceImpl { - - public SecuritySystemService( - CurrentSecuritySystemStateCharacteristic currentState, - TargetSecuritySystemStateCharacteristic targetState) { - super("0000007E-0000-1000-8000-0026BB765291"); - addCharacteristic(currentState); - addCharacteristic(targetState); - } - - public SecuritySystemService(SecuritySystemAccessory accessory) { - this( - new CurrentSecuritySystemStateCharacteristic( - accessory.getCurrentSecuritySystemStateValidValues(), - accessory::getCurrentSecuritySystemState, - accessory::subscribeCurrentSecuritySystemState, - accessory::unsubscribeCurrentSecuritySystemState), - new TargetSecuritySystemStateCharacteristic( - accessory.getTargetSecuritySystemStateValidValues(), - accessory::getTargetSecuritySystemState, - accessory::setTargetSecuritySystemState, - accessory::subscribeTargetSecuritySystemState, - accessory::unsubscribeTargetSecuritySystemState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithStatusFault) { - addOptionalCharacteristic( - new StatusFaultCharacteristic( - ((AccessoryWithStatusFault) accessory)::getStatusFault, - ((AccessoryWithStatusFault) accessory)::subscribeStatusFault, - ((AccessoryWithStatusFault) accessory)::unsubscribeStatusFault)); - } - if (accessory instanceof AccessoryWithStatusTampered) { - addOptionalCharacteristic( - new StatusTamperedCharacteristic( - ((AccessoryWithStatusTampered) accessory)::getStatusTampered, - ((AccessoryWithStatusTampered) accessory)::subscribeStatusTampered, - ((AccessoryWithStatusTampered) accessory)::unsubscribeStatusTampered)); - } - if (accessory instanceof AccessoryWithSecurityAlarmType) { - addOptionalCharacteristic( - new SecuritySystemAlarmTypeCharacteristic( - ((AccessoryWithSecurityAlarmType) accessory)::getSecurityAlarmType, - ((AccessoryWithSecurityAlarmType) accessory)::subscribeSecurityAlarmType, - ((AccessoryWithSecurityAlarmType) accessory)::unsubscribeSecurityAlarmType)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(SecuritySystemAlarmTypeCharacteristic alarmType) { - addCharacteristic(alarmType); - } - - public void addOptionalCharacteristic(StatusFaultCharacteristic statusFault) { - addCharacteristic(statusFault); - } - - public void addOptionalCharacteristic(StatusTamperedCharacteristic statusTampered) { - addCharacteristic(statusTampered); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/ServiceLabelService.java b/src/main/java/io/github/hapjava/services/impl/ServiceLabelService.java deleted file mode 100644 index bee40f094..000000000 --- a/src/main/java/io/github/hapjava/services/impl/ServiceLabelService.java +++ /dev/null @@ -1,13 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.characteristics.impl.common.ServiceLabelNamespaceCharacteristic; - -/** This service describes label scheme. */ -public class ServiceLabelService extends AbstractServiceImpl { - - public ServiceLabelService( - ServiceLabelNamespaceCharacteristic serviceLabelNamespaceCharacteristic) { - super("000000CC-0000-1000-8000-0026BB765291"); - addCharacteristic(serviceLabelNamespaceCharacteristic); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/SlatService.java b/src/main/java/io/github/hapjava/services/impl/SlatService.java deleted file mode 100644 index 5993983fa..000000000 --- a/src/main/java/io/github/hapjava/services/impl/SlatService.java +++ /dev/null @@ -1,77 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.SlatAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithCurrentTilting; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithSwingMode; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithTargetTilting; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.fan.SwingModeCharacteristic; -import io.github.hapjava.characteristics.impl.slat.CurrentSlatStateCharacteristic; -import io.github.hapjava.characteristics.impl.slat.CurrentTiltAngleCharacteristic; -import io.github.hapjava.characteristics.impl.slat.SlatTypeCharacteristic; -import io.github.hapjava.characteristics.impl.slat.TargetTiltAngleCharacteristic; - -/** This service describes a slat */ -public class SlatService extends AbstractServiceImpl { - - public SlatService( - CurrentSlatStateCharacteristic state, SlatTypeCharacteristic slatTypeCharacteristic) { - super("000000B9-0000-1000-8000-0026BB765291"); - addCharacteristic(state); - addCharacteristic(slatTypeCharacteristic); - } - - public SlatService(SlatAccessory accessory) { - this( - new CurrentSlatStateCharacteristic( - accessory::getSlatState, - accessory::subscribeSlatState, - accessory::unsubscribeSlatState), - new SlatTypeCharacteristic(accessory::getSlatType)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithSwingMode) { - addOptionalCharacteristic( - new SwingModeCharacteristic( - ((AccessoryWithSwingMode) accessory)::getSwingMode, - ((AccessoryWithSwingMode) accessory)::setSwingMode, - ((AccessoryWithSwingMode) accessory)::subscribeSwingMode, - ((AccessoryWithSwingMode) accessory)::unsubscribeSwingMode)); - } - if (accessory instanceof AccessoryWithCurrentTilting) { - addOptionalCharacteristic( - new CurrentTiltAngleCharacteristic( - ((AccessoryWithCurrentTilting) accessory)::getCurrentTiltAngle, - ((AccessoryWithCurrentTilting) accessory)::subscribeCurrentTiltAngle, - ((AccessoryWithCurrentTilting) accessory)::unsubscribeCurrentTiltAngle)); - } - if (accessory instanceof AccessoryWithTargetTilting) { - addOptionalCharacteristic( - new TargetTiltAngleCharacteristic( - ((AccessoryWithTargetTilting) accessory)::getTargetTiltAngle, - ((AccessoryWithTargetTilting) accessory)::setTargetTiltAngle, - ((AccessoryWithTargetTilting) accessory)::subscribeTargetTiltAngle, - ((AccessoryWithTargetTilting) accessory)::unsubscribeTargetTiltAngle)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(SwingModeCharacteristic mode) { - addCharacteristic(mode); - } - - public void addOptionalCharacteristic( - TargetTiltAngleCharacteristic targetTiltAngleCharacteristic) { - addCharacteristic(targetTiltAngleCharacteristic); - } - - public void addOptionalCharacteristic( - CurrentTiltAngleCharacteristic currentTiltAngleCharacteristic) { - addCharacteristic(currentTiltAngleCharacteristic); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/SmartSpeakerService.java b/src/main/java/io/github/hapjava/services/impl/SmartSpeakerService.java deleted file mode 100644 index e5f57eff4..000000000 --- a/src/main/java/io/github/hapjava/services/impl/SmartSpeakerService.java +++ /dev/null @@ -1,95 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.SmartSpeakerAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithAirPlayEnable; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithConfiguredName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithMute; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithVolume; -import io.github.hapjava.characteristics.impl.audio.MuteCharacteristic; -import io.github.hapjava.characteristics.impl.audio.VolumeCharacteristic; -import io.github.hapjava.characteristics.impl.common.AirPlayEnableCharacteristic; -import io.github.hapjava.characteristics.impl.common.ConfiguredNameCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.television.CurrentMediaStateCharacteristic; -import io.github.hapjava.characteristics.impl.television.TargetMediaStateCharacteristic; - -/** A smart speaker service can be used to control the audio output settings on a speaker device. */ -public class SmartSpeakerService extends AbstractServiceImpl { - - public SmartSpeakerService( - CurrentMediaStateCharacteristic currentMediaStateCharacteristic, - TargetMediaStateCharacteristic targetMediaStateCharacteristic) { - super("00000228-0000-1000-8000-0026BB765291"); - addCharacteristic(currentMediaStateCharacteristic); - addCharacteristic(targetMediaStateCharacteristic); - } - - public SmartSpeakerService(SmartSpeakerAccessory accessory) { - this( - new CurrentMediaStateCharacteristic( - accessory::getCurrentMediaState, - accessory::subscribeCurrentMediaState, - accessory::unsubscribeCurrentMediaState), - new TargetMediaStateCharacteristic( - accessory::getTargetMediaState, - accessory::setTargetMediaState, - accessory::subscribeTargetMediaState, - accessory::unsubscribeTargetMediaState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithVolume) { - addOptionalCharacteristic( - new VolumeCharacteristic( - ((AccessoryWithVolume) accessory)::getVolume, - ((AccessoryWithVolume) accessory)::setVolume, - ((AccessoryWithVolume) accessory)::subscribeVolume, - ((AccessoryWithVolume) accessory)::unsubscribeVolume)); - } - if (accessory instanceof AccessoryWithConfiguredName) { - addOptionalCharacteristic( - new ConfiguredNameCharacteristic( - ((AccessoryWithConfiguredName) accessory)::getConfiguredName, - ((AccessoryWithConfiguredName) accessory)::setConfiguredName, - ((AccessoryWithConfiguredName) accessory)::subscribeConfiguredName, - ((AccessoryWithConfiguredName) accessory)::unsubscribeConfiguredName)); - } - if (accessory instanceof AccessoryWithMute) { - addOptionalCharacteristic( - new MuteCharacteristic( - ((AccessoryWithMute) accessory)::isMuted, - ((AccessoryWithMute) accessory)::setMute, - ((AccessoryWithMute) accessory)::subscribeMuteState, - ((AccessoryWithMute) accessory)::unsubscribeMuteState)); - } - if (accessory instanceof AccessoryWithAirPlayEnable) { - addOptionalCharacteristic( - new AirPlayEnableCharacteristic( - ((AccessoryWithAirPlayEnable) accessory)::getAirPlayEnable, - ((AccessoryWithAirPlayEnable) accessory)::setAirPlayEnable, - ((AccessoryWithAirPlayEnable) accessory)::subscribeAirPlayEnable, - ((AccessoryWithAirPlayEnable) accessory)::unsubscribeAirPlayEnable)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(VolumeCharacteristic volume) { - addCharacteristic(volume); - } - - public void addOptionalCharacteristic(ConfiguredNameCharacteristic configuredNameCharacteristic) { - addCharacteristic(configuredNameCharacteristic); - } - - public void addOptionalCharacteristic(MuteCharacteristic muteCharacteristic) { - addCharacteristic(muteCharacteristic); - } - - public void addOptionalCharacteristic(AirPlayEnableCharacteristic airPlayEnableCharacteristic) { - addCharacteristic(airPlayEnableCharacteristic); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/SmokeSensorService.java b/src/main/java/io/github/hapjava/services/impl/SmokeSensorService.java deleted file mode 100644 index b6bf2f8d6..000000000 --- a/src/main/java/io/github/hapjava/services/impl/SmokeSensorService.java +++ /dev/null @@ -1,82 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.SmokeSensorAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusActive; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusFault; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusLowBattery; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusTampered; -import io.github.hapjava.characteristics.impl.battery.StatusLowBatteryCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusFaultCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusTamperedCharacteristic; -import io.github.hapjava.characteristics.impl.smokesensor.SmokeDetectedCharacteristic; - -/** This service describes a Smoke detector Sensor. */ -public class SmokeSensorService extends AbstractServiceImpl { - - public SmokeSensorService(SmokeDetectedCharacteristic smokeDetectedCharacteristic) { - super("00000087-0000-1000-8000-0026BB765291"); - addCharacteristic(smokeDetectedCharacteristic); - } - - public SmokeSensorService(SmokeSensorAccessory accessory) { - this( - new SmokeDetectedCharacteristic( - accessory::getSmokeDetectedState, - accessory::subscribeSmokeDetectedState, - accessory::unsubscribeSmokeDetectedState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithStatusActive) { - addOptionalCharacteristic( - new StatusActiveCharacteristic( - ((AccessoryWithStatusActive) accessory)::getStatusActive, - ((AccessoryWithStatusActive) accessory)::subscribeStatusActive, - ((AccessoryWithStatusActive) accessory)::unsubscribeStatusActive)); - } - if (accessory instanceof AccessoryWithStatusFault) { - addOptionalCharacteristic( - new StatusFaultCharacteristic( - ((AccessoryWithStatusFault) accessory)::getStatusFault, - ((AccessoryWithStatusFault) accessory)::subscribeStatusFault, - ((AccessoryWithStatusFault) accessory)::unsubscribeStatusFault)); - } - if (accessory instanceof AccessoryWithStatusTampered) { - addOptionalCharacteristic( - new StatusTamperedCharacteristic( - ((AccessoryWithStatusTampered) accessory)::getStatusTampered, - ((AccessoryWithStatusTampered) accessory)::subscribeStatusTampered, - ((AccessoryWithStatusTampered) accessory)::unsubscribeStatusTampered)); - } - if (accessory instanceof AccessoryWithStatusLowBattery) { - addOptionalCharacteristic( - new StatusLowBatteryCharacteristic( - ((AccessoryWithStatusLowBattery) accessory)::getStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::subscribeStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::unsubscribeStatusLowBattery)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(StatusActiveCharacteristic statusActive) { - addCharacteristic(statusActive); - } - - public void addOptionalCharacteristic(StatusFaultCharacteristic statusFault) { - addCharacteristic(statusFault); - } - - public void addOptionalCharacteristic(StatusTamperedCharacteristic statusTampered) { - addCharacteristic(statusTampered); - } - - public void addOptionalCharacteristic(StatusLowBatteryCharacteristic statusLowBattery) { - addCharacteristic(statusLowBattery); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/SpeakerService.java b/src/main/java/io/github/hapjava/services/impl/SpeakerService.java deleted file mode 100644 index 8619d5a50..000000000 --- a/src/main/java/io/github/hapjava/services/impl/SpeakerService.java +++ /dev/null @@ -1,45 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.SpeakerAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithVolume; -import io.github.hapjava.characteristics.impl.audio.MuteCharacteristic; -import io.github.hapjava.characteristics.impl.audio.VolumeCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; - -/** A Speaker service can be used to control the audio output settings on a speaker device. */ -public class SpeakerService extends AbstractServiceImpl { - - public SpeakerService(MuteCharacteristic muteCharacteristic) { - super("00000113-0000-1000-8000-0026BB765291"); - addCharacteristic(muteCharacteristic); - } - - public SpeakerService(SpeakerAccessory accessory) { - this( - new MuteCharacteristic( - accessory::isMuted, - accessory::setMute, - accessory::subscribeMuteState, - accessory::unsubscribeMuteState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithVolume) { - addOptionalCharacteristic( - new VolumeCharacteristic( - ((AccessoryWithVolume) accessory)::getVolume, - ((AccessoryWithVolume) accessory)::setVolume, - ((AccessoryWithVolume) accessory)::subscribeVolume, - ((AccessoryWithVolume) accessory)::unsubscribeVolume)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(VolumeCharacteristic volume) { - addCharacteristic(volume); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/StatelessProgrammableSwitchService.java b/src/main/java/io/github/hapjava/services/impl/StatelessProgrammableSwitchService.java deleted file mode 100644 index bded30f47..000000000 --- a/src/main/java/io/github/hapjava/services/impl/StatelessProgrammableSwitchService.java +++ /dev/null @@ -1,42 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.StatelessProgrammableSwitchAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithServiceLabelIndex; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.ProgrammableSwitchEventCharacteristic; -import io.github.hapjava.characteristics.impl.common.ServiceLabelIndexCharacteristic; - -/** This service describes a stateless programmable switch. */ -public class StatelessProgrammableSwitchService extends AbstractServiceImpl { - - public StatelessProgrammableSwitchService(ProgrammableSwitchEventCharacteristic switchEvent) { - super("00000089-0000-1000-8000-0026BB765291"); - addCharacteristic(switchEvent); - } - - public StatelessProgrammableSwitchService(StatelessProgrammableSwitchAccessory accessory) { - this( - new ProgrammableSwitchEventCharacteristic( - accessory::getSwitchEvent, - accessory::subscribeSwitchEvent, - accessory::unsubscribeSwitchEvent)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithServiceLabelIndex) { - addOptionalCharacteristic( - new ServiceLabelIndexCharacteristic( - ((AccessoryWithServiceLabelIndex) accessory)::getServiceLabelIndex)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic( - ServiceLabelIndexCharacteristic serviceLabelIndexCharacteristic) { - addCharacteristic(serviceLabelIndexCharacteristic); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/SwitchService.java b/src/main/java/io/github/hapjava/services/impl/SwitchService.java deleted file mode 100644 index 65a8f2124..000000000 --- a/src/main/java/io/github/hapjava/services/impl/SwitchService.java +++ /dev/null @@ -1,31 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.SwitchAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.OnCharacteristic; - -/** This service describes a binary switch. */ -public class SwitchService extends AbstractServiceImpl { - - public SwitchService(OnCharacteristic onState) { - super("00000049-0000-1000-8000-0026BB765291"); - addCharacteristic(onState); - } - - public SwitchService(SwitchAccessory accessory) { - this( - new OnCharacteristic( - accessory::getSwitchState, - accessory::setSwitchState, - accessory::subscribeSwitchState, - accessory::unsubscribeSwitchState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/TelevisionService.java b/src/main/java/io/github/hapjava/services/impl/TelevisionService.java deleted file mode 100644 index 8846cffe1..000000000 --- a/src/main/java/io/github/hapjava/services/impl/TelevisionService.java +++ /dev/null @@ -1,139 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.TelevisionAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithBrightness; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithClosedCaptions; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithCurrentMediaState; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithPictureMode; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithPowerMode; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithTargetMediaState; -import io.github.hapjava.characteristics.impl.common.ActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.ActiveEnum; -import io.github.hapjava.characteristics.impl.common.ActiveIdentifierCharacteristic; -import io.github.hapjava.characteristics.impl.common.ConfiguredNameCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.lightbulb.BrightnessCharacteristic; -import io.github.hapjava.characteristics.impl.television.ClosedCaptionsCharacteristic; -import io.github.hapjava.characteristics.impl.television.CurrentMediaStateCharacteristic; -import io.github.hapjava.characteristics.impl.television.PictureModeCharacteristic; -import io.github.hapjava.characteristics.impl.television.PowerModeCharacteristic; -import io.github.hapjava.characteristics.impl.television.RemoteKeyCharacteristic; -import io.github.hapjava.characteristics.impl.television.SleepDiscoveryModeCharacteristic; -import io.github.hapjava.characteristics.impl.television.TargetMediaStateCharacteristic; - -/** This service describes a television. */ -public class TelevisionService extends AbstractServiceImpl { - - public TelevisionService( - ActiveCharacteristic activeCharacteristic, - ActiveIdentifierCharacteristic activeIdentifierCharacteristic, - ConfiguredNameCharacteristic configuredNameCharacteristic, - RemoteKeyCharacteristic remoteKeyCharacteristic, - SleepDiscoveryModeCharacteristic sleepDiscoveryModeCharacteristic) { - super("000000D8-0000-1000-8000-0026BB765291"); - addCharacteristic(activeCharacteristic); - addCharacteristic(activeIdentifierCharacteristic); - addCharacteristic(configuredNameCharacteristic); - addCharacteristic(remoteKeyCharacteristic); - addCharacteristic(sleepDiscoveryModeCharacteristic); - } - - public TelevisionService(TelevisionAccessory accessory) { - this( - new ActiveCharacteristic( - () -> accessory.isActive().thenApply(s -> s ? ActiveEnum.ACTIVE : ActiveEnum.INACTIVE), - (v) -> accessory.setActive(v == ActiveEnum.ACTIVE), - accessory::subscribeActive, - accessory::unsubscribeActive), - new ActiveIdentifierCharacteristic( - accessory::getActiveIdentifier, - accessory::setActiveIdentifier, - accessory::subscribeActiveIdentifier, - accessory::unsubscribeActiveIdentifier), - new ConfiguredNameCharacteristic( - accessory::getConfiguredName, - accessory::setConfiguredName, - accessory::subscribeConfiguredName, - accessory::unsubscribeConfiguredName), - new RemoteKeyCharacteristic(accessory::setRemoteKey), - new SleepDiscoveryModeCharacteristic( - accessory::getSleepDiscoveryMode, - accessory::subscribeSleepDiscoveryMode, - accessory::unsubscribeSleepDiscoveryMode)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithBrightness) { - addOptionalCharacteristic( - new BrightnessCharacteristic( - ((AccessoryWithBrightness) accessory)::getBrightness, - ((AccessoryWithBrightness) accessory)::setBrightness, - ((AccessoryWithBrightness) accessory)::subscribeBrightness, - ((AccessoryWithBrightness) accessory)::unsubscribeBrightness)); - } - if (accessory instanceof AccessoryWithPowerMode) { - addOptionalCharacteristic( - new PowerModeCharacteristic(((AccessoryWithPowerMode) accessory)::setPowerMode)); - } - if (accessory instanceof AccessoryWithClosedCaptions) { - addOptionalCharacteristic( - new ClosedCaptionsCharacteristic( - ((AccessoryWithClosedCaptions) accessory)::getClosedCaptions, - ((AccessoryWithClosedCaptions) accessory)::setClosedCaptions, - ((AccessoryWithClosedCaptions) accessory)::subscribeClosedCaptions, - ((AccessoryWithClosedCaptions) accessory)::unsubscribeClosedCaptions)); - } - if (accessory instanceof AccessoryWithCurrentMediaState) { - addOptionalCharacteristic( - new CurrentMediaStateCharacteristic( - ((AccessoryWithCurrentMediaState) accessory)::getCurrentMediaState, - ((AccessoryWithCurrentMediaState) accessory)::subscribeCurrentMediaState, - ((AccessoryWithCurrentMediaState) accessory)::unsubscribeCurrentMediaState)); - } - if (accessory instanceof AccessoryWithTargetMediaState) { - addOptionalCharacteristic( - new TargetMediaStateCharacteristic( - ((AccessoryWithTargetMediaState) accessory)::getTargetMediaState, - ((AccessoryWithTargetMediaState) accessory)::setTargetMediaState, - ((AccessoryWithTargetMediaState) accessory)::subscribeTargetMediaState, - ((AccessoryWithTargetMediaState) accessory)::unsubscribeTargetMediaState)); - } - if (accessory instanceof AccessoryWithPictureMode) { - addOptionalCharacteristic( - new PictureModeCharacteristic( - ((AccessoryWithPictureMode) accessory)::getPictureMode, - ((AccessoryWithPictureMode) accessory)::setPictureMode, - ((AccessoryWithPictureMode) accessory)::subscribePictureMode, - ((AccessoryWithPictureMode) accessory)::unsubscribePictureMode)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(PowerModeCharacteristic powerMode) { - addCharacteristic(powerMode); - } - - public void addOptionalCharacteristic(ClosedCaptionsCharacteristic closedCaptions) { - addCharacteristic(closedCaptions); - } - - public void addOptionalCharacteristic(CurrentMediaStateCharacteristic currentMediaState) { - addCharacteristic(currentMediaState); - } - - public void addOptionalCharacteristic(TargetMediaStateCharacteristic targetMediaState) { - addCharacteristic(targetMediaState); - } - - public void addOptionalCharacteristic(PictureModeCharacteristic pictureMode) { - addCharacteristic(pictureMode); - } - - public void addOptionalCharacteristic(BrightnessCharacteristic brightness) { - addCharacteristic(brightness); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/TelevisionSpeakerService.java b/src/main/java/io/github/hapjava/services/impl/TelevisionSpeakerService.java deleted file mode 100644 index b53fb81bd..000000000 --- a/src/main/java/io/github/hapjava/services/impl/TelevisionSpeakerService.java +++ /dev/null @@ -1,75 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.TelevisionSpeakerAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithActive; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithVolume; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithVolumeControlType; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithVolumeSelector; -import io.github.hapjava.characteristics.impl.audio.MuteCharacteristic; -import io.github.hapjava.characteristics.impl.audio.VolumeCharacteristic; -import io.github.hapjava.characteristics.impl.common.ActiveCharacteristic; -import io.github.hapjava.characteristics.impl.televisionspeaker.VolumeControlTypeCharacteristic; -import io.github.hapjava.characteristics.impl.televisionspeaker.VolumeSelectorCharacteristic; - -/** This service describes a television. */ -public class TelevisionSpeakerService extends AbstractServiceImpl { - - public TelevisionSpeakerService(MuteCharacteristic muteCharacteristic) { - super("00000113-0000-1000-8000-0026BB765291"); - addCharacteristic(muteCharacteristic); - } - - public TelevisionSpeakerService(TelevisionSpeakerAccessory accessory) { - this( - new MuteCharacteristic( - accessory::isMuted, - accessory::setMute, - accessory::subscribeMuteState, - accessory::unsubscribeMuteState)); - if (accessory instanceof AccessoryWithActive) { - addOptionalCharacteristic( - new ActiveCharacteristic( - ((AccessoryWithActive) accessory)::getActive, - ((AccessoryWithActive) accessory)::setActive, - ((AccessoryWithActive) accessory)::subscribeActive, - ((AccessoryWithActive) accessory)::unsubscribeActive)); - } - if (accessory instanceof AccessoryWithVolume) { - addOptionalCharacteristic( - new VolumeCharacteristic( - ((AccessoryWithVolume) accessory)::getVolume, - ((AccessoryWithVolume) accessory)::setVolume, - ((AccessoryWithVolume) accessory)::subscribeVolume, - ((AccessoryWithVolume) accessory)::unsubscribeVolume)); - } - if (accessory instanceof AccessoryWithVolumeSelector) { - addOptionalCharacteristic( - new VolumeSelectorCharacteristic( - ((AccessoryWithVolumeSelector) accessory)::setVolumeSelector)); - } - if (accessory instanceof AccessoryWithVolumeControlType) { - addOptionalCharacteristic( - new VolumeControlTypeCharacteristic( - ((AccessoryWithVolumeControlType) accessory)::getVolumeControlType, - ((AccessoryWithVolumeControlType) accessory)::subscribeVolumeControlType, - ((AccessoryWithVolumeControlType) accessory)::unsubscribeVolumeControlType)); - ; - } - } - - public void addOptionalCharacteristic(ActiveCharacteristic activeCharacteristic) { - addCharacteristic(activeCharacteristic); - } - - public void addOptionalCharacteristic(VolumeCharacteristic volume) { - addCharacteristic(volume); - } - - public void addOptionalCharacteristic(VolumeSelectorCharacteristic volumeSelector) { - addCharacteristic(volumeSelector); - } - - public void addOptionalCharacteristic(VolumeControlTypeCharacteristic volumeControlType) { - addCharacteristic(volumeControlType); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/TemperatureSensorService.java b/src/main/java/io/github/hapjava/services/impl/TemperatureSensorService.java deleted file mode 100644 index bef9fff60..000000000 --- a/src/main/java/io/github/hapjava/services/impl/TemperatureSensorService.java +++ /dev/null @@ -1,86 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.TemperatureSensorAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusActive; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusFault; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusLowBattery; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusTampered; -import io.github.hapjava.characteristics.impl.battery.StatusLowBatteryCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusFaultCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusTamperedCharacteristic; -import io.github.hapjava.characteristics.impl.thermostat.CurrentTemperatureCharacteristic; - -/** This service describes a Temperature Sensor. */ -public class TemperatureSensorService extends AbstractServiceImpl { - - public TemperatureSensorService( - CurrentTemperatureCharacteristic currentTemperatureCharacteristic) { - super("0000008A-0000-1000-8000-0026BB765291"); - addCharacteristic(currentTemperatureCharacteristic); - } - - public TemperatureSensorService(TemperatureSensorAccessory accessory) { - this( - new CurrentTemperatureCharacteristic( - accessory.getMinCurrentTemperature(), - accessory.getMaxCurrentTemperature(), - accessory.getMinStepCurrentTemperature(), - accessory::getCurrentTemperature, - accessory::subscribeCurrentTemperature, - accessory::unsubscribeCurrentTemperature)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithStatusActive) { - addOptionalCharacteristic( - new StatusActiveCharacteristic( - ((AccessoryWithStatusActive) accessory)::getStatusActive, - ((AccessoryWithStatusActive) accessory)::subscribeStatusActive, - ((AccessoryWithStatusActive) accessory)::unsubscribeStatusActive)); - } - if (accessory instanceof AccessoryWithStatusFault) { - addOptionalCharacteristic( - new StatusFaultCharacteristic( - ((AccessoryWithStatusFault) accessory)::getStatusFault, - ((AccessoryWithStatusFault) accessory)::subscribeStatusFault, - ((AccessoryWithStatusFault) accessory)::unsubscribeStatusFault)); - } - if (accessory instanceof AccessoryWithStatusTampered) { - addOptionalCharacteristic( - new StatusTamperedCharacteristic( - ((AccessoryWithStatusTampered) accessory)::getStatusTampered, - ((AccessoryWithStatusTampered) accessory)::subscribeStatusTampered, - ((AccessoryWithStatusTampered) accessory)::unsubscribeStatusTampered)); - } - if (accessory instanceof AccessoryWithStatusLowBattery) { - addOptionalCharacteristic( - new StatusLowBatteryCharacteristic( - ((AccessoryWithStatusLowBattery) accessory)::getStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::subscribeStatusLowBattery, - ((AccessoryWithStatusLowBattery) accessory)::unsubscribeStatusLowBattery)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(StatusActiveCharacteristic statusActive) { - addCharacteristic(statusActive); - } - - public void addOptionalCharacteristic(StatusFaultCharacteristic statusFault) { - addCharacteristic(statusFault); - } - - public void addOptionalCharacteristic(StatusTamperedCharacteristic statusTampered) { - addCharacteristic(statusTampered); - } - - public void addOptionalCharacteristic(StatusLowBatteryCharacteristic statusLowBattery) { - addCharacteristic(statusLowBattery); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/ThermostatService.java b/src/main/java/io/github/hapjava/services/impl/ThermostatService.java deleted file mode 100644 index c775a41d5..000000000 --- a/src/main/java/io/github/hapjava/services/impl/ThermostatService.java +++ /dev/null @@ -1,147 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.ThermostatAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithCoolingThresholdTemperature; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithCurrentRelativeHumidity; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithHeatingThresholdTemperature; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithTargetRelativeHumidity; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.humiditysensor.CurrentRelativeHumidityCharacteristic; -import io.github.hapjava.characteristics.impl.humiditysensor.TargetRelativeHumidityCharacteristic; -import io.github.hapjava.characteristics.impl.thermostat.CoolingThresholdTemperatureCharacteristic; -import io.github.hapjava.characteristics.impl.thermostat.CurrentHeatingCoolingStateCharacteristic; -import io.github.hapjava.characteristics.impl.thermostat.CurrentTemperatureCharacteristic; -import io.github.hapjava.characteristics.impl.thermostat.HeatingThresholdTemperatureCharacteristic; -import io.github.hapjava.characteristics.impl.thermostat.TargetHeatingCoolingStateCharacteristic; -import io.github.hapjava.characteristics.impl.thermostat.TargetTemperatureCharacteristic; -import io.github.hapjava.characteristics.impl.thermostat.TemperatureDisplayUnitCharacteristic; - -/** This service describes a thermostat. */ -public class ThermostatService extends AbstractServiceImpl { - - public ThermostatService( - CurrentHeatingCoolingStateCharacteristic currentHeatingCoolingStateCharacteristic, - TargetHeatingCoolingStateCharacteristic targetHeatingCoolingStateCharacteristic, - CurrentTemperatureCharacteristic currentTemperatureCharacteristic, - TargetTemperatureCharacteristic targetTemperatureCharacteristic, - TemperatureDisplayUnitCharacteristic temperatureUnitsCharacteristic) { - super("0000004A-0000-1000-8000-0026BB765291"); - addCharacteristic(currentHeatingCoolingStateCharacteristic); - addCharacteristic(targetHeatingCoolingStateCharacteristic); - addCharacteristic(currentTemperatureCharacteristic); - addCharacteristic(targetTemperatureCharacteristic); - addCharacteristic(temperatureUnitsCharacteristic); - } - - public ThermostatService(ThermostatAccessory accessory) { - this( - new CurrentHeatingCoolingStateCharacteristic( - accessory.getCurrentHeatingCoolingStateValidValues(), - accessory::getCurrentState, - accessory::subscribeCurrentState, - accessory::unsubscribeCurrentState), - new TargetHeatingCoolingStateCharacteristic( - accessory.getTargetHeatingCoolingStateValidValues(), - accessory::getTargetState, - accessory::setTargetState, - accessory::subscribeTargetState, - accessory::unsubscribeTargetState), - new CurrentTemperatureCharacteristic( - accessory.getMinCurrentTemperature(), - accessory.getMaxCurrentTemperature(), - accessory.getMinStepCurrentTemperature(), - accessory::getCurrentTemperature, - accessory::subscribeCurrentTemperature, - accessory::unsubscribeCurrentTemperature), - new TargetTemperatureCharacteristic( - accessory.getMinTargetTemperature(), - accessory.getMaxTargetTemperature(), - accessory.getMinStepTargetTemperature(), - accessory::getTargetTemperature, - accessory::setTargetTemperature, - accessory::subscribeTargetTemperature, - accessory::unsubscribeTargetTemperature), - new TemperatureDisplayUnitCharacteristic( - accessory::getTemperatureDisplayUnit, - accessory::setTemperatureDisplayUnit, - accessory::subscribeTemperatureDisplayUnit, - accessory::unsubscribeTemperatureDisplayUnit)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithCoolingThresholdTemperature) { - addOptionalCharacteristic( - new CoolingThresholdTemperatureCharacteristic( - ((AccessoryWithCoolingThresholdTemperature) accessory) - .getMinCoolingThresholdTemperature(), - ((AccessoryWithCoolingThresholdTemperature) accessory) - .getMaxCoolingThresholdTemperature(), - ((AccessoryWithCoolingThresholdTemperature) accessory) - .getStepCoolingThresholdTemperature(), - ((AccessoryWithCoolingThresholdTemperature) accessory) - ::getCoolingThresholdTemperature, - ((AccessoryWithCoolingThresholdTemperature) accessory) - ::setCoolingThresholdTemperature, - ((AccessoryWithCoolingThresholdTemperature) accessory) - ::subscribeCoolingThresholdTemperature, - ((AccessoryWithCoolingThresholdTemperature) accessory) - ::unsubscribeCoolingThresholdTemperature)); - } - if (accessory instanceof AccessoryWithHeatingThresholdTemperature) { - addOptionalCharacteristic( - new HeatingThresholdTemperatureCharacteristic( - ((AccessoryWithHeatingThresholdTemperature) accessory) - .getMinHeatingThresholdTemperature(), - ((AccessoryWithHeatingThresholdTemperature) accessory) - .getMaxHeatingThresholdTemperature(), - ((AccessoryWithHeatingThresholdTemperature) accessory) - .getStepHeatingThresholdTemperature(), - ((AccessoryWithHeatingThresholdTemperature) accessory) - ::getHeatingThresholdTemperature, - ((AccessoryWithHeatingThresholdTemperature) accessory) - ::setHeatingThresholdTemperature, - ((AccessoryWithHeatingThresholdTemperature) accessory) - ::subscribeHeatingThresholdTemperature, - ((AccessoryWithHeatingThresholdTemperature) accessory) - ::unsubscribeHeatingThresholdTemperature)); - } - if (accessory instanceof AccessoryWithCurrentRelativeHumidity) { - addOptionalCharacteristic( - new CurrentRelativeHumidityCharacteristic( - ((AccessoryWithCurrentRelativeHumidity) accessory)::getCurrentRelativeHumidity, - ((AccessoryWithCurrentRelativeHumidity) accessory)::subscribeCurrentRelativeHumidity, - ((AccessoryWithCurrentRelativeHumidity) accessory) - ::unsubscribeCurrentRelativeHumidity)); - } - if (accessory instanceof AccessoryWithTargetRelativeHumidity) { - addOptionalCharacteristic( - new TargetRelativeHumidityCharacteristic( - ((AccessoryWithTargetRelativeHumidity) accessory)::getTargetRelativeHumidity, - ((AccessoryWithTargetRelativeHumidity) accessory)::setTargetRelativeHumidity, - ((AccessoryWithTargetRelativeHumidity) accessory)::subscribeTargetRelativeHumidity, - ((AccessoryWithTargetRelativeHumidity) accessory) - ::unsubscribeTargetRelativeHumidity)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(CoolingThresholdTemperatureCharacteristic threshold) { - addCharacteristic(threshold); - } - - public void addOptionalCharacteristic(HeatingThresholdTemperatureCharacteristic threshold) { - addCharacteristic(threshold); - } - - public void addOptionalCharacteristic(CurrentRelativeHumidityCharacteristic humidity) { - addCharacteristic(humidity); - } - - public void addOptionalCharacteristic(TargetRelativeHumidityCharacteristic humidity) { - addCharacteristic(humidity); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/ValveService.java b/src/main/java/io/github/hapjava/services/impl/ValveService.java deleted file mode 100644 index 519502a3c..000000000 --- a/src/main/java/io/github/hapjava/services/impl/ValveService.java +++ /dev/null @@ -1,117 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.ValveAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithDuration; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithIsConfigured; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithRemainingDuration; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithServiceLabelIndex; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithStatusFault; -import io.github.hapjava.characteristics.impl.common.ActiveCharacteristic; -import io.github.hapjava.characteristics.impl.common.InUseCharacteristic; -import io.github.hapjava.characteristics.impl.common.IsConfiguredCharacteristic; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.ServiceLabelIndexCharacteristic; -import io.github.hapjava.characteristics.impl.common.StatusFaultCharacteristic; -import io.github.hapjava.characteristics.impl.valve.RemainingDurationCharacteristic; -import io.github.hapjava.characteristics.impl.valve.SetDurationCharacteristic; -import io.github.hapjava.characteristics.impl.valve.ValveTypeCharacteristic; - -/** This service describes accessories valves. */ -public class ValveService extends AbstractServiceImpl { - - public ValveService( - ActiveCharacteristic activeCharacteristic, - InUseCharacteristic inUseCharacteristic, - ValveTypeCharacteristic valveTypeCharacteristic) { - super("000000D0-0000-1000-8000-0026BB765291"); - addCharacteristic(activeCharacteristic); - addCharacteristic(inUseCharacteristic); - addCharacteristic(valveTypeCharacteristic); - } - - public ValveService(ValveAccessory accessory) { - this( - new ActiveCharacteristic( - accessory::getValveActive, - accessory::setValveActive, - accessory::subscribeValveActive, - accessory::unsubscribeValveActive), - new InUseCharacteristic( - accessory::getValveInUse, - accessory::subscribeValveInUse, - accessory::unsubscribeValveInUse), - new ValveTypeCharacteristic( - accessory::getValveType, - accessory::subscribeValveType, - accessory::unsubscribeValveType)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithStatusFault) { - addOptionalCharacteristic( - new StatusFaultCharacteristic( - ((AccessoryWithStatusFault) accessory)::getStatusFault, - ((AccessoryWithStatusFault) accessory)::subscribeStatusFault, - ((AccessoryWithStatusFault) accessory)::unsubscribeStatusFault)); - } - if (accessory instanceof AccessoryWithDuration) { - addOptionalCharacteristic( - new SetDurationCharacteristic( - ((AccessoryWithDuration) accessory).getMinDuration(), - ((AccessoryWithDuration) accessory).getMaxDuration(), - ((AccessoryWithDuration) accessory)::getSetDuration, - ((AccessoryWithDuration) accessory)::setSetDuration, - ((AccessoryWithDuration) accessory)::subscribeSetDuration, - ((AccessoryWithDuration) accessory)::unsubscribeSetDuration)); - } - if (accessory instanceof AccessoryWithRemainingDuration) { - addOptionalCharacteristic( - new RemainingDurationCharacteristic( - ((AccessoryWithRemainingDuration) accessory).getMinRemainingDuration(), - ((AccessoryWithRemainingDuration) accessory).getMaxRemainingDuration(), - ((AccessoryWithRemainingDuration) accessory)::getRemainingDuration, - ((AccessoryWithRemainingDuration) accessory)::subscribeRemainingDuration, - ((AccessoryWithRemainingDuration) accessory)::unsubscribeRemainingDuration)); - } - if (accessory instanceof AccessoryWithIsConfigured) { - addOptionalCharacteristic( - new IsConfiguredCharacteristic( - ((AccessoryWithIsConfigured) accessory)::getIsConfigured, - ((AccessoryWithIsConfigured) accessory)::setIsConfigured, - ((AccessoryWithIsConfigured) accessory)::subscribeIsConfigured, - ((AccessoryWithIsConfigured) accessory)::unsubscribeIsConfigured)); - } - if (accessory instanceof AccessoryWithServiceLabelIndex) { - addOptionalCharacteristic( - new ServiceLabelIndexCharacteristic( - ((AccessoryWithServiceLabelIndex) accessory)::getServiceLabelIndex)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(StatusFaultCharacteristic statusFaultCharacteristic) { - addCharacteristic(statusFaultCharacteristic); - } - - public void addOptionalCharacteristic(SetDurationCharacteristic setDurationCharacteristic) { - addCharacteristic(setDurationCharacteristic); - } - - public void addOptionalCharacteristic( - RemainingDurationCharacteristic remainingDurationCharacteristic) { - addCharacteristic(remainingDurationCharacteristic); - } - - public void addOptionalCharacteristic(IsConfiguredCharacteristic isConfiguredCharacteristic) { - addCharacteristic(isConfiguredCharacteristic); - } - - public void addOptionalCharacteristic( - ServiceLabelIndexCharacteristic serviceLabelIndexCharacteristic) { - addCharacteristic(serviceLabelIndexCharacteristic); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/WindowCoveringService.java b/src/main/java/io/github/hapjava/services/impl/WindowCoveringService.java deleted file mode 100644 index fe483e4c0..000000000 --- a/src/main/java/io/github/hapjava/services/impl/WindowCoveringService.java +++ /dev/null @@ -1,135 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.WindowCoveringAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithCurrentHorizontalTilting; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithCurrentVerticalTilting; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithHoldPosition; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithObstructionDetection; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithTargetHorizontalTilting; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithTargetVerticalTilting; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.ObstructionDetectedCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.CurrentHorizontalTiltAngleCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.CurrentPositionCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.CurrentVerticalTiltAngleCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.HoldPositionCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.PositionStateCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.TargetHorizontalTiltAngleCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.TargetPositionCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.TargetVerticalTiltAngleCharacteristic; - -/** This service describes motorized window coverings or shades */ -public class WindowCoveringService extends AbstractServiceImpl { - - public WindowCoveringService( - TargetPositionCharacteristic targetPositionCharacteristic, - CurrentPositionCharacteristic currentPositionCharacteristic, - PositionStateCharacteristic positionStateCharacteristic) { - super("0000008C-0000-1000-8000-0026BB765291"); - addCharacteristic(targetPositionCharacteristic); - addCharacteristic(currentPositionCharacteristic); - addCharacteristic(positionStateCharacteristic); - } - - public WindowCoveringService(WindowCoveringAccessory accessory) { - this( - new TargetPositionCharacteristic( - accessory::getTargetPosition, - accessory::setTargetPosition, - accessory::subscribeTargetPosition, - accessory::unsubscribeTargetPosition), - new CurrentPositionCharacteristic( - accessory::getCurrentPosition, - accessory::subscribeCurrentPosition, - accessory::unsubscribeCurrentPosition), - new PositionStateCharacteristic( - accessory::getPositionState, - accessory::subscribePositionState, - accessory::unsubscribePositionState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithHoldPosition) { - addOptionalCharacteristic( - new HoldPositionCharacteristic(((AccessoryWithHoldPosition) accessory)::setHoldPosition)); - } - - if (accessory instanceof AccessoryWithObstructionDetection) { - addOptionalCharacteristic( - new ObstructionDetectedCharacteristic( - ((AccessoryWithObstructionDetection) accessory)::getObstructionDetected, - ((AccessoryWithObstructionDetection) accessory)::subscribeObstructionDetected, - ((AccessoryWithObstructionDetection) accessory)::unsubscribeObstructionDetected)); - } - if (accessory instanceof AccessoryWithCurrentHorizontalTilting) { - addOptionalCharacteristic( - new CurrentHorizontalTiltAngleCharacteristic( - ((AccessoryWithCurrentHorizontalTilting) accessory)::getCurrentHorizontalTiltAngle, - ((AccessoryWithCurrentHorizontalTilting) accessory) - ::subscribeCurrentHorizontalTiltAngle, - ((AccessoryWithCurrentHorizontalTilting) accessory) - ::unsubscribeCurrentHorizontalTiltAngle)); - } - if (accessory instanceof AccessoryWithTargetHorizontalTilting) { - addOptionalCharacteristic( - new TargetHorizontalTiltAngleCharacteristic( - ((AccessoryWithTargetHorizontalTilting) accessory)::getTargetHorizontalTiltAngle, - ((AccessoryWithTargetHorizontalTilting) accessory)::setTargetHorizontalTiltAngle, - ((AccessoryWithTargetHorizontalTilting) accessory) - ::subscribeTargetHorizontalTiltAngle, - ((AccessoryWithTargetHorizontalTilting) accessory) - ::unsubscribeTargetHorizontalTiltAngle)); - } - if (accessory instanceof AccessoryWithCurrentVerticalTilting) { - addOptionalCharacteristic( - new CurrentVerticalTiltAngleCharacteristic( - ((AccessoryWithCurrentVerticalTilting) accessory)::getCurrentVerticalTiltAngle, - ((AccessoryWithCurrentVerticalTilting) accessory)::subscribeCurrentVerticalTiltAngle, - ((AccessoryWithCurrentVerticalTilting) accessory) - ::unsubscribeCurrentVerticalTiltAngle)); - } - if (accessory instanceof AccessoryWithTargetVerticalTilting) { - addOptionalCharacteristic( - new TargetVerticalTiltAngleCharacteristic( - ((AccessoryWithTargetVerticalTilting) accessory)::getTargetVerticalTiltAngle, - ((AccessoryWithTargetVerticalTilting) accessory)::setTargetVerticalTiltAngle, - ((AccessoryWithTargetVerticalTilting) accessory)::subscribeTargetVerticalTiltAngle, - ((AccessoryWithTargetVerticalTilting) accessory) - ::unsubscribeTargetVerticalTiltAngle)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(HoldPositionCharacteristic holdPositionCharacteristic) { - addCharacteristic(holdPositionCharacteristic); - } - - public void addOptionalCharacteristic( - ObstructionDetectedCharacteristic obstructionDetectedCharacteristic) { - addCharacteristic(obstructionDetectedCharacteristic); - } - - public void addOptionalCharacteristic( - CurrentHorizontalTiltAngleCharacteristic currentHorizontalTiltAngleCharacteristic) { - addCharacteristic(currentHorizontalTiltAngleCharacteristic); - } - - public void addOptionalCharacteristic( - TargetHorizontalTiltAngleCharacteristic targetHorizontalTiltAngleCharacteristic) { - addCharacteristic(targetHorizontalTiltAngleCharacteristic); - } - - public void addOptionalCharacteristic( - CurrentVerticalTiltAngleCharacteristic currentVerticalTiltAngleCharacteristic) { - addCharacteristic(currentVerticalTiltAngleCharacteristic); - } - - public void addOptionalCharacteristic( - TargetVerticalTiltAngleCharacteristic targetVerticalTiltAngleCharacteristic) { - addCharacteristic(targetVerticalTiltAngleCharacteristic); - } -} diff --git a/src/main/java/io/github/hapjava/services/impl/WindowService.java b/src/main/java/io/github/hapjava/services/impl/WindowService.java deleted file mode 100644 index e7f2e775d..000000000 --- a/src/main/java/io/github/hapjava/services/impl/WindowService.java +++ /dev/null @@ -1,71 +0,0 @@ -package io.github.hapjava.services.impl; - -import io.github.hapjava.accessories.WindowAccessory; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithHoldPosition; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithName; -import io.github.hapjava.accessories.optionalcharacteristic.AccessoryWithObstructionDetection; -import io.github.hapjava.characteristics.impl.common.NameCharacteristic; -import io.github.hapjava.characteristics.impl.common.ObstructionDetectedCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.CurrentPositionCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.HoldPositionCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.PositionStateCharacteristic; -import io.github.hapjava.characteristics.impl.windowcovering.TargetPositionCharacteristic; - -/** This service describes a motorized window. */ -public class WindowService extends AbstractServiceImpl { - - public WindowService( - CurrentPositionCharacteristic currentPositionCharacteristic, - TargetPositionCharacteristic targetPositionCharacteristic, - PositionStateCharacteristic positionStateCharacteristic) { - super("0000008B-0000-1000-8000-0026BB765291"); - addCharacteristic(currentPositionCharacteristic); - addCharacteristic(targetPositionCharacteristic); - addCharacteristic(positionStateCharacteristic); - } - - public WindowService(WindowAccessory accessory) { - this( - new CurrentPositionCharacteristic( - accessory::getCurrentPosition, - accessory::subscribeCurrentPosition, - accessory::unsubscribeCurrentPosition), - new TargetPositionCharacteristic( - accessory::getTargetPosition, - accessory::setTargetPosition, - accessory::subscribeTargetPosition, - accessory::unsubscribeTargetPosition), - new PositionStateCharacteristic( - accessory::getPositionState, - accessory::subscribePositionState, - accessory::unsubscribePositionState)); - if (accessory instanceof AccessoryWithName) { - addOptionalCharacteristic(new NameCharacteristic(((AccessoryWithName) accessory)::getName)); - } - if (accessory instanceof AccessoryWithHoldPosition) { - addOptionalCharacteristic( - new HoldPositionCharacteristic(((AccessoryWithHoldPosition) accessory)::setHoldPosition)); - } - - if (accessory instanceof AccessoryWithObstructionDetection) { - addOptionalCharacteristic( - new ObstructionDetectedCharacteristic( - ((AccessoryWithObstructionDetection) accessory)::getObstructionDetected, - ((AccessoryWithObstructionDetection) accessory)::subscribeObstructionDetected, - ((AccessoryWithObstructionDetection) accessory)::unsubscribeObstructionDetected)); - } - } - - public void addOptionalCharacteristic(NameCharacteristic name) { - addCharacteristic(name); - } - - public void addOptionalCharacteristic(HoldPositionCharacteristic holdPositionCharacteristic) { - addCharacteristic(holdPositionCharacteristic); - } - - public void addOptionalCharacteristic( - ObstructionDetectedCharacteristic obstructionDetectedCharacteristic) { - addCharacteristic(obstructionDetectedCharacteristic); - } -} diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml new file mode 100644 index 000000000..65087d6a3 --- /dev/null +++ b/src/main/resources/log4j2.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml new file mode 100644 index 000000000..e4680b944 --- /dev/null +++ b/src/main/resources/logback.xml @@ -0,0 +1,30 @@ + + + + true + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + application.log + + %date - [%level] - from %logger in %thread + %n%message%n%xException%n + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/simplelogger.properties b/src/main/resources/simplelogger.properties new file mode 100644 index 000000000..895eeb271 --- /dev/null +++ b/src/main/resources/simplelogger.properties @@ -0,0 +1 @@ +org.slf4j.simpleLogger.defaultLogLevel=INFO \ No newline at end of file diff --git a/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java b/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java deleted file mode 100644 index 81d2666e5..000000000 --- a/src/test/java/io/github/hapjava/server/impl/HomekitRootTest.java +++ /dev/null @@ -1,113 +0,0 @@ -package io.github.hapjava.server.impl; - -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import io.github.hapjava.accessories.HomekitAccessory; -import io.github.hapjava.server.HomekitAccessoryCategories; -import io.github.hapjava.server.HomekitAuthInfo; -import io.github.hapjava.server.HomekitWebHandler; -import io.github.hapjava.server.impl.http.HomekitClientConnectionFactory; -import io.github.hapjava.server.impl.jmdns.JmdnsHomekitAdvertiser; -import java.util.concurrent.CompletableFuture; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -public class HomekitRootTest { - - private HomekitAccessory accessory; - private HomekitRoot root; - private HomekitWebHandler webHandler; - private JmdnsHomekitAdvertiser advertiser; - private HomekitAuthInfo authInfo; - - private static final int PORT = 12345; - private static final String SETUPID = "Gx12"; - - private static final String LABEL = "Test Label"; - - @Before - public void setup() throws Exception { - accessory = mock(HomekitAccessory.class); - when(accessory.getId()).thenReturn(2); - webHandler = mock(HomekitWebHandler.class); - when(webHandler.start(any())).thenReturn(CompletableFuture.completedFuture(PORT)); - advertiser = mock(JmdnsHomekitAdvertiser.class); - authInfo = mock(HomekitAuthInfo.class); - root = - new HomekitRoot(LABEL, HomekitAccessoryCategories.OTHER, webHandler, authInfo, advertiser); - } - - @Test - public void verifyRegistryAdded() throws Exception { - root.addAccessory(accessory); - Assert.assertTrue( - "Registry does not contain accessory", - root.getRegistry().getAccessories().contains(accessory)); - } - - @Test - public void verifyRegistryRemoved() throws Exception { - root.addAccessory(accessory); - root.removeAccessory(accessory); - Assert.assertFalse( - "Registry still contains accessory", - root.getRegistry().getAccessories().contains(accessory)); - } - - @Test - public void testWebHandlerStarts() throws Exception { - root.start(); - verify(webHandler).start(any(HomekitClientConnectionFactory.class)); - } - - @Test - public void testWebHandlerStops() throws Exception { - root.start(); - root.stop(); - verify(webHandler).stop(); - } - - @Test - public void testAdvertiserStarts() throws Exception { - final String mac = "00:00:00:00:00:00"; - when(authInfo.getMac()).thenReturn(mac); - when(authInfo.getSetupId()).thenReturn(SETUPID); - - root.start(); - verify(advertiser).advertise(eq(LABEL), eq(1), eq(mac), eq(PORT), eq(1), eq(SETUPID)); - } - - @Test - public void testAdvertiserStops() throws Exception { - root.start(); - root.stop(); - verify(advertiser).stop(); - } - - @Test - public void testAddAccessoryDoesntResetWeb() { - root.start(); - root.addAccessory(accessory); - verify(webHandler, never()).resetConnections(); - } - - @Test - public void testRemoveAccessoryDoesntResetWeb() { - root.addAccessory(accessory); - root.start(); - root.removeAccessory(accessory); - verify(webHandler, never()).resetConnections(); - } - - @Test(expected = IndexOutOfBoundsException.class) - public void testAddIndexOneAccessory() throws Exception { - when(accessory.getId()).thenReturn(1); - root.addAccessory(accessory); - } -} diff --git a/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java b/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java deleted file mode 100644 index 870bd739b..000000000 --- a/src/test/java/io/github/hapjava/server/impl/jmdns/JmdnsHomekitAdvertiserTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package io.github.hapjava.server.impl.jmdns; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import java.io.IOException; -import java.net.UnknownHostException; -import javax.jmdns.JmDNS; -import javax.jmdns.ServiceInfo; -import org.junit.Before; -import org.junit.Test; -import org.mockito.ArgumentCaptor; - -public class JmdnsHomekitAdvertiserTest { - - JmdnsHomekitAdvertiser subject; - JmDNS jmdns; - - @Before - public void setup() throws UnknownHostException, IOException { - jmdns = mock(JmDNS.class); - subject = new JmdnsHomekitAdvertiser(jmdns); - } - - @Test - public void testAdvertiseTwiceFails() throws Exception { - advertise(); - assertThatThrownBy(() -> advertise()).isNotNull(); - } - - /* - * Verify that the unregister call is for the initial registered service - * when changing discoverability causes advertising to be toggled. - */ - @Test - public void testSetDiscoverableAfterAdvertise() throws Exception { - subject.setDiscoverable(false); - advertise(); - subject.setDiscoverable(true); - assertThat(getArgumentFromUnregister().getPropertyString("sf")).isEqualTo("0"); - } - - /* - * Verify that the unregister call is for the initial registered service - * when changing the config index causes advertising to be toggled. - */ - @Test - public void testSetConfigurationIndex() throws Exception { - subject.setConfigurationIndex(1); - advertise(); - subject.setConfigurationIndex(2); - assertThat(getArgumentFromUnregister().getPropertyString("c#")).isEqualTo("1"); - } - - private ServiceInfo getArgumentFromUnregister() { - ArgumentCaptor serviceInfoCaptor = ArgumentCaptor.forClass(ServiceInfo.class); - verify(jmdns).unregisterService(serviceInfoCaptor.capture()); - return serviceInfoCaptor.getValue(); - } - - private void advertise() throws Exception { - subject.advertise("test", 1, "00:00:00:00:00:00", 1234, 1, "1"); - } -}