Skip to content

Commit

Permalink
fix(channel): 🔃 keep properties and firmware channel information in sync
Browse files Browse the repository at this point in the history
- keep firmware property and channel in sync
- README.md updated

Signed-off-by: Patrik Gfeller <patrik.gfeller@proton.me>
  • Loading branch information
pgfeller committed May 7, 2024
1 parent a4e7e94 commit 0549ac6
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 29 deletions.
29 changes: 16 additions & 13 deletions bundles/org.openhab.binding.huesync/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,37 +39,40 @@ $ avahi-browse --resolve _huesync._tcp

</details>


## Thing Configuration

To enable the binding to communicate with the device, a registration is required.
Once the registration process is completed, the acquired token will authorize the binding to communicate with the device.
After initial discovery and thing creation the device will stay offline.
To complete the authentication you need to pressed the registration button on the sync box for 3 seconds.


_Describe what is needed to manually configure a thing, either through the UI or via a thing-file._
_This should be mainly about its mandatory and optional configuration parameters._

_Note that it is planned to generate some part of this based on the XML files within ```src/main/resources/OH-INF/thing``` of your binding._

### `sample` Thing Configuration
### Thing Configuration `huesyncthing`

| Name | Type | Description | Default | Required | Advanced |
|-----------------|---------|---------------------------------------|---------|----------|----------|
| hostname | text | Hostname or IP address of the device | N/A | yes | no |
| password | text | Password to access the device | N/A | yes | no |
| refreshInterval | integer | Interval the device is polled in sec. | 600 | no | yes |
| Name | Type | Description | Default | Required | Advanced |
| -------------------- | ------- | --------------------------------- | ------- | -------- | -------- |
| host | text | IP address of the device | N/A | yes | no |
| port | integer | Port of the HDMI Sync Box. | 443 | yes | yes |
| registrationId | text | Application Registration Id | N/A | no | yes |
| apiAccessToken | text | API Access Token | N/A | no | yes |
| statusUpdateInterval | integer | Status Update Interval in seconds | 10 | yes | yes |

## Channels

_Here you should provide information about available channel types, what their meaning is and how they can be used._
### Channel Group `device-firmware`

_Note that it is planned to generate some part of this based on the XML files within ```src/main/resources/OH-INF/thing``` of your binding._
#### Firmware

Information about the installed device firmware and available updates.

| Channel | Type | Read/Write | Description |
|---------|--------|------------|-----------------------------|
| control | Switch | RW | This is the control channel |
| Channel | Type | Read/Write | Description |
| ------------------ | ------ | ---------- | --------------------------------- |
| firmware | String | R | Installed firmware version |
| available-firmware | String | R | Latest available firmware version |

## Full Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public static class ENDPOINTS {
public static class CHANNELS {
public static class DEVICE {
public static class INFORMATION {
public static final String FIRMWARE = "device-information#firmware";
public static final String FIRMWARE_AVAILABLE = "device-information#available-firmware";
public static final String FIRMWARE = "device-firmware#firmware";
public static final String FIRMWARE_AVAILABLE = "device-firmware#available-firmware";
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ private void updateDeviceStatus(@Nullable HueSyncDetailedDeviceInfo deviceState)
? deviceState.updatableFirmwareVersion
: deviceState.firmwareVersion);

setProperty(Thing.PROPERTY_FIRMWARE_VERSION, deviceState.firmwareVersion);
setProperty(HueSyncHandler.PROPERTY_API_VERSION, String.format("%d", deviceState.apiLevel));

this.updateState(HueSyncConstants.CHANNELS.DEVICE.INFORMATION.FIRMWARE, firmwareState);
this.updateState(HueSyncConstants.CHANNELS.DEVICE.INFORMATION.FIRMWARE_AVAILABLE, firmwareAvailableState);
}
Expand All @@ -165,7 +168,7 @@ private void setRegistration(HueSyncRegistration registration) {
if (id.isPresent() && token.isPresent()) {
this.stopTask(deviceRegistrationTask);

addProperty(HueSyncConstants.REGISTRATION_ID, id.get());
setProperty(HueSyncConstants.REGISTRATION_ID, id.get());

Configuration configuration = this.editConfiguration();
configuration.put(HueSyncConstants.REGISTRATION_ID, id.get());
Expand Down Expand Up @@ -194,16 +197,27 @@ private void checkCompatibility() throws HueSyncApiException {
}
}

private void addProperty(String key, @Nullable String value) {
private void setProperty(String key, @Nullable String value) {
if (value != null) {
Map<String, String> properties = this.editProperties();

properties.put(key, value);

this.updateProperties(properties);
if (properties.containsKey(key)) {
@Nullable
String currentValue = properties.get(key);
if (!(value.equals(currentValue))) {
saveProperty(key, value, properties);
}
} else {
saveProperty(key, value, properties);
}
}
}

private void saveProperty(String key, String value, Map<String, String> properties) {
properties.put(key, value);
this.updateProperties(properties);
}

// #endregion

// #region Override
Expand All @@ -224,12 +238,12 @@ public void initialize() {
this.deviceInfo = this.connection.getDeviceInfo();

Optional.ofNullable(this.deviceInfo).ifPresent((info) -> {
addProperty(Thing.PROPERTY_SERIAL_NUMBER, info.uniqueId);
addProperty(Thing.PROPERTY_MODEL_ID, info.deviceType);
addProperty(Thing.PROPERTY_FIRMWARE_VERSION, info.firmwareVersion);
setProperty(Thing.PROPERTY_SERIAL_NUMBER, info.uniqueId);
setProperty(Thing.PROPERTY_MODEL_ID, info.deviceType);

addProperty(HueSyncHandler.PROPERTY_API_VERSION, String.format("%d", info.apiLevel));
addProperty(HueSyncHandler.PROPERTY_NETWORK_STATE, info.wifiState);
setProperty(Thing.PROPERTY_FIRMWARE_VERSION, info.firmwareVersion);
setProperty(HueSyncHandler.PROPERTY_API_VERSION, String.format("%d", info.apiLevel));
// setProperty(HueSyncHandler.PROPERTY_NETWORK_STATE, info.wifiState);
try {
this.checkCompatibility();
this.startBackgroundTasks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<label>Status Update Interval</label>
<description>Seconds between fetching values from the Hue Sync Box.</description>
<advanced>true</advanced>
<required>true</required>
<default>10</default>
<unitLabel>Seconds</unitLabel>
</parameter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ thing-type.config.huesync.thing.statusUpdateInterval.description = Seconds betwe

# channel group types

channel-group-type.huesync.device-information.label = Firmware
channel-group-type.huesync.device-information.description = Information about the installed device firmaware and available updates.
channel-group-type.huesync.device-firmware.label = Firmware
channel-group-type.huesync.device-firmware.description = Information about the installed device firmaware and available updates.

# channel types

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</description>

<channel-groups>
<channel-group id="device-information" typeId="device-information"></channel-group>
<channel-group id="device-firmware" typeId="device-firmware"></channel-group>
</channel-groups>

<properties>
Expand All @@ -25,7 +25,7 @@
<config-description-ref uri="thing-type:huesync:thing"/>
</thing-type>

<channel-group-type id="device-information">
<channel-group-type id="device-firmware">
<label>Firmware</label>
<description>Information about the installed device firmaware and available updates.</description>
<category></category>
Expand Down

0 comments on commit 0549ac6

Please sign in to comment.