-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ZigBee firmware provider backed by GitHub repository
Signed-off-by: Chris Jackson <[email protected]>
- Loading branch information
Showing
12 changed files
with
971 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
This content is produced and maintained by the openHAB project. | ||
|
||
* Project home: https://www.openhab.org | ||
|
||
== Declared Project Licenses | ||
|
||
This program and the accompanying materials are made available under the terms | ||
of the Eclipse Public License 2.0 which is available at | ||
https://www.eclipse.org/legal/epl-2.0/. | ||
|
||
== Source Code | ||
|
||
https://github.com/openhab/org.openhab.binding.zigbee | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.openhab.addons.bundles</groupId> | ||
<artifactId>org.openhab.addons.zigbee.reactor</artifactId> | ||
<version>3.3.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>org.openhab.binding.zigbee.firmware</artifactId> | ||
|
||
<name>openHAB Add-ons :: Bundles :: ZigBee Firmware Provider</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.openhab.addons.bundles</groupId> | ||
<artifactId>org.openhab.binding.zigbee</artifactId> | ||
<version>${project.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.zsmartsystems.zigbee</groupId> | ||
<artifactId>com.zsmartsystems.zigbee</artifactId> | ||
<version>${zsmartsystems.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
156 changes: 156 additions & 0 deletions
156
...ee.firmware/src/main/java/org/openhab/binding/zigbee/firmware/ZigBeeFirmwareProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
/** | ||
* Copyright (c) 2010-2021 Contributors to the openHAB project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.openhab.binding.zigbee.firmware; | ||
|
||
import java.io.File; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Set; | ||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ScheduledExecutorService; | ||
|
||
import org.eclipse.jdt.annotation.NonNull; | ||
import org.eclipse.jdt.annotation.Nullable; | ||
import org.openhab.binding.zigbee.firmware.internal.DirectoryFileEntry; | ||
import org.openhab.binding.zigbee.firmware.internal.GithubLibraryReader; | ||
import org.openhab.binding.zigbee.handler.ZigBeeFirmwareVersion; | ||
import org.openhab.binding.zigbee.handler.ZigBeeThingHandler; | ||
import org.openhab.core.OpenHAB; | ||
import org.openhab.core.thing.Thing; | ||
import org.openhab.core.thing.ThingTypeUID; | ||
import org.openhab.core.thing.binding.firmware.Firmware; | ||
import org.openhab.core.thing.binding.firmware.FirmwareBuilder; | ||
import org.openhab.core.thing.firmware.FirmwareProvider; | ||
import org.osgi.service.component.annotations.Activate; | ||
import org.osgi.service.component.annotations.Component; | ||
import org.osgi.service.component.annotations.Deactivate; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* The firmware provider using a github based repository | ||
* | ||
* @author Chris Jackson | ||
*/ | ||
@Component(service = FirmwareProvider.class, immediate = true, configurationPid = "org.openhab.binding.zigbee.firmware") | ||
public class ZigBeeFirmwareProvider implements FirmwareProvider { | ||
private Logger logger = LoggerFactory.getLogger(ZigBeeFirmwareProvider.class); | ||
|
||
private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); | ||
|
||
private GithubLibraryReader directoryReader; | ||
|
||
@Activate | ||
protected void activate() { | ||
logger.debug("ZigBee Firmware Provider: Activated"); | ||
String folder = OpenHAB.getUserDataFolder() + File.separator + "firmware" + File.separator; | ||
directoryReader = new GithubLibraryReader(folder); | ||
try { | ||
directoryReader.create("https://raw.githubusercontent.com/Koenkk/zigbee-OTA/master"); | ||
directoryReader.updateRemoteDirectory(); | ||
} catch (Exception e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Deactivate | ||
protected void deactivate() { | ||
logger.debug("ZigBee Firmware Provider: Deactivated"); | ||
} | ||
|
||
@Override | ||
public @Nullable Firmware getFirmware(@NonNull Thing thing, @NonNull String version) { | ||
return getFirmware(thing, version, null); | ||
} | ||
|
||
@Override | ||
public @Nullable Firmware getFirmware(@NonNull Thing thing, @NonNull String version, @Nullable Locale locale) { | ||
ZigBeeFirmwareVersion requestedVersion = getRequestedVersionFromThing(thing); | ||
if (requestedVersion == null) { | ||
return null; | ||
} | ||
|
||
List<DirectoryFileEntry> directory = directoryReader.getDirectory(); | ||
for (DirectoryFileEntry firmware : directory) { | ||
if (firmware.getFirmwareVersion().equals(requestedVersion)) { | ||
return getZigBeeFirmware(thing.getThingTypeUID(), firmware); | ||
} | ||
} | ||
|
||
logger.debug("Unable to find firmware version {}", version); | ||
return null; | ||
} | ||
|
||
@Override | ||
public @Nullable Set<@NonNull Firmware> getFirmwares(@NonNull Thing thing) { | ||
return getFirmwares(thing, null); | ||
} | ||
|
||
@Override | ||
public @Nullable Set<@NonNull Firmware> getFirmwares(@NonNull Thing thing, @Nullable Locale locale) { | ||
final Set<Firmware> firmwareSet = new HashSet<>(); | ||
|
||
ZigBeeFirmwareVersion requestedVersion = getRequestedVersionFromThing(thing); | ||
if (requestedVersion == null) { | ||
return firmwareSet; | ||
} | ||
|
||
for (DirectoryFileEntry firmware : directoryReader.getDirectory()) { | ||
if (firmware.getFirmwareVersion().equals(requestedVersion)) { | ||
firmwareSet.add(getZigBeeFirmware(thing.getThingTypeUID(), firmware)); | ||
} | ||
} | ||
return firmwareSet; | ||
} | ||
|
||
private ZigBeeFirmwareVersion getRequestedVersionFromThing(@NonNull Thing thing) { | ||
// We only deal in ZigBee devices here | ||
if (!(thing.getHandler() instanceof ZigBeeThingHandler)) { | ||
return null; | ||
} | ||
ZigBeeThingHandler zigbeeHandler = (ZigBeeThingHandler) thing.getHandler(); | ||
if (zigbeeHandler == null) { | ||
return null; | ||
} | ||
return zigbeeHandler.getRequestedFirmwareVersion(); | ||
} | ||
|
||
private Firmware getZigBeeFirmware(@NonNull ThingTypeUID thingTypeUID, DirectoryFileEntry directoryEntry) { | ||
FirmwareBuilder builder = FirmwareBuilder.create(thingTypeUID, directoryEntry.getVersion().toString()); | ||
|
||
if (!directoryEntry.getModel().isEmpty()) { | ||
builder.withModel(directoryEntry.getModel()); | ||
} | ||
if (!directoryEntry.getVendor().isEmpty()) { | ||
builder.withVendor(directoryEntry.getVendor()); | ||
} | ||
if (!directoryEntry.getDescription().isEmpty()) { | ||
builder.withDescription(directoryEntry.getDescription()); | ||
} | ||
if (!directoryEntry.getMd5().isEmpty()) { | ||
builder.withMd5Hash(directoryEntry.getMd5()); | ||
} | ||
if (!directoryEntry.getPrerequisiteVersion().isEmpty()) { | ||
builder.withPrerequisiteVersion(directoryEntry.getPrerequisiteVersion()); | ||
} | ||
|
||
// BufferedInputStream inputStream = new BufferedInputStream(new URL("").openStream()); | ||
|
||
// builder.withInputStream(inputStream); | ||
|
||
return builder.build(); | ||
} | ||
|
||
} |
Oops, something went wrong.