Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [dirigera] Initial contribution #17719

Open
wants to merge 125 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
125 commits
Select commit Hold shift + click to select a range
24e55c5
initial commit
weymann Oct 7, 2024
50f66c9
initial commit
weymann Oct 7, 2024
d41a437
framework is running
weymann Oct 8, 2024
8c141b9
rebase fix
weymann Nov 7, 2024
69b19b9
add motion sensor
weymann Oct 9, 2024
232e442
add light sensor
weymann Oct 9, 2024
d6c243e
rebase fix
weymann Nov 7, 2024
95d8fdb
add temperature light
weymann Oct 10, 2024
5e4bc04
add smart plug
weymann Oct 11, 2024
fe58c44
add device speaker
weymann Oct 11, 2024
a298c4d
bugfixing speaker device
weymann Oct 12, 2024
482dc87
prepare unit tests
weymann Oct 14, 2024
6b518a3
make discovery configurable
weymann Oct 14, 2024
b32fa02
add test files
weymann Nov 3, 2024
7595430
add test files
weymann Nov 3, 2024
2c9efb1
add ota channels
weymann Oct 15, 2024
80e8afc
add ota channels
weymann Oct 15, 2024
906f3e3
hub channels
weymann Oct 15, 2024
b059283
add scene handler
weymann Oct 15, 2024
0a3bb82
ping pong tryout
weymann Oct 15, 2024
cf9aec6
add repeater device
weymann Oct 15, 2024
6717ba5
add repeater device
weymann Oct 15, 2024
cf23644
add lightcontroller device
weymann Oct 16, 2024
1d8648e
add lightcontroller device
weymann Oct 16, 2024
e7626b3
heartbeat finished
weymann Oct 17, 2024
a263d4a
motion-light-sensor added
weymann Oct 17, 2024
2be32ec
plug differentiation
weymann Oct 17, 2024
8ca6d23
bugfix speaker image
weymann Oct 17, 2024
5e40b23
add envrionment sensor
weymann Oct 17, 2024
0d483f7
smaller bugfixes
weymann Oct 17, 2024
0a8893f
add water sensor
weymann Oct 17, 2024
a902ac9
handler model cross check
weymann Oct 18, 2024
2a9b395
add refresh tests for all handlers
weymann Oct 18, 2024
276f387
several smaller code fixes
weymann Oct 18, 2024
9599427
handler
weymann Nov 3, 2024
3f37c79
API simulation added
weymann Oct 20, 2024
442b76d
model disco´very rework
weymann Oct 21, 2024
a905067
model disco´very rework
weymann Oct 21, 2024
a79238e
add and remove device scanrios
weymann Oct 21, 2024
08baaa7
add json channel
weymann Oct 22, 2024
d36357a
bugfix identify device
weymann Oct 22, 2024
884a243
count model updates
weymann Oct 22, 2024
ee95625
add simple plug
weymann Oct 23, 2024
864bc66
add simple plug
weymann Oct 23, 2024
25ca954
remove gson dependency
weymann Oct 23, 2024
ec5e91f
add blind devices
weymann Oct 23, 2024
2a02e16
asd air purifier device
weymann Oct 23, 2024
129268f
handler reorg
weymann Oct 23, 2024
d4f159a
add blinds controller
weymann Oct 23, 2024
ccf0adc
add sound controller
weymann Oct 23, 2024
938837c
add shortcut controller
weymann Oct 23, 2024
fdc78b4
fix compiler warnings
weymann Oct 23, 2024
b669602
add startup behavior channel
weymann Oct 23, 2024
3cb0c00
add energy channels
weymann Oct 23, 2024
7849e53
resolved ambigiuous state channels
weymann Oct 24, 2024
e0d71b2
correct plug init
weymann Oct 25, 2024
67ba8fc
add dimmable light
weymann Oct 25, 2024
d034589
add tests
weymann Nov 3, 2024
b526329
start detecttion after handler removal
weymann Oct 25, 2024
0ef365f
created reference unit test
weymann Oct 26, 2024
bb2f01c
created reference unit test
weymann Oct 26, 2024
384b3cd
thing status i18n
weymann Oct 26, 2024
b979399
desynchronized API
weymann Oct 26, 2024
5e5ccd1
add filter remain time
weymann Oct 26, 2024
dfffebc
bugfixes after real testing
weymann Oct 27, 2024
9ebf451
double shortcut controller working
weymann Oct 29, 2024
f8f1503
double shortcut controller working
weymann Oct 29, 2024
d45c0a5
bugfixes
weymann Oct 29, 2024
1cae5de
further bugfixes
weymann Oct 29, 2024
31487df
readme adaptions
weymann Oct 31, 2024
b6ec4f9
readme adaptions
weymann Oct 31, 2024
d95da43
add custom name channel
weymann Oct 31, 2024
2531a0d
adjust junit tests
weymann Nov 3, 2024
aea9e52
feuture timeout for motion sensor
weymann Nov 1, 2024
864bca1
intermediate stage
weymann Nov 1, 2024
0da50eb
intermediate stage
weymann Nov 1, 2024
82b2dff
bugfixes device linking
weymann Nov 1, 2024
91c16f3
feature sensor activity added
weymann Nov 1, 2024
a52e71e
add feature sensorconfig
weymann Nov 2, 2024
958beaf
bugfixes
weymann Nov 3, 2024
911ac61
readme adaptions
weymann Nov 3, 2024
1c9feac
readme adaptions
weymann Nov 3, 2024
1dae7a7
doc update
weymann Nov 3, 2024
3b37eee
documentation & smaller changes
weymann Nov 4, 2024
975d852
model rework
weymann Nov 4, 2024
377827b
storage key is ip and color corrections
weymann Nov 5, 2024
e7cb404
storage key is ip and color corrections
weymann Nov 5, 2024
2cda4fb
reduce motion debugging
weymann Nov 5, 2024
6c22c68
cleanup json
weymann Nov 5, 2024
6c18d7b
scene template added
weymann Nov 6, 2024
2cbb241
better error handling during gateway initialization
weymann Nov 6, 2024
7da0f2d
OH4.1 compatibility fix
weymann Nov 7, 2024
fbb94c0
add ip log output for discovery
weymann Nov 7, 2024
376ffd8
brightness dimmer functionality
weymann Nov 7, 2024
203c92f
update readme
weymann Nov 7, 2024
3f5a91f
codeowner and pom files
weymann Nov 7, 2024
6940cb4
spotless:apply for pom.xml
weymann Nov 7, 2024
1126ff6
fix unit test time
weymann Nov 7, 2024
8707fac
light rework
weymann Nov 12, 2024
861ea47
light rework
weymann Nov 12, 2024
2a39d25
finally handling to esnure freeing resources after queue access
weymann Nov 13, 2024
7d35ebb
channel adaptions from review
weymann Nov 15, 2024
d3c3c72
channel updates
weymann Nov 18, 2024
579ee3c
color channel fix
weymann Nov 18, 2024
37f710d
add gateway location channel
weymann Nov 18, 2024
f47fd0e
add coordinates channel and channel updates
weymann Nov 19, 2024
e941c21
add receive and send capabilities
weymann Nov 19, 2024
42bbfed
correct light identification
weymann Nov 19, 2024
b128a63
add switch light
weymann Nov 19, 2024
6d17f93
add switch light
weymann Nov 19, 2024
ca14efc
inspelning reset handling
weymann Nov 19, 2024
d1ba3ec
inspelning reset handling
weymann Nov 20, 2024
736982d
bugfixes exceptions during error handling
weymann Nov 20, 2024
341a7fa
imrpove exception handling in api
weymann Nov 20, 2024
7f91996
watchdog first version
weymann Nov 23, 2024
0d6efe5
add air purifier fan speed channel
weymann Nov 24, 2024
90fb6ed
bugfix air purifier after testing
weymann Nov 24, 2024
af3856f
readme adaptions
weymann Nov 25, 2024
231c155
enhance readme
weymann Nov 25, 2024
185b20d
add device dump action
weymann Nov 25, 2024
16605f5
add debug actions
weymann Nov 26, 2024
68c7baa
channel cleanup
weymann Nov 29, 2024
acedd42
correct version
weymann Dec 1, 2024
b3bf3c2
translations
weymann Dec 1, 2024
e6b15f1
fix channel typo
weymann Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
/bundles/org.openhab.binding.deutschebahn/ @soenkekueper
/bundles/org.openhab.binding.digiplex/ @rmichalak
/bundles/org.openhab.binding.digitalstrom/ @openhab/add-ons-maintainers
/bundles/org.openhab.binding.dirigera/ @weymann
/bundles/org.openhab.binding.dlinksmarthome/ @MikeJMajor
/bundles/org.openhab.binding.dmx/ @openhab/add-ons-maintainers
/bundles/org.openhab.binding.dolbycp/ @Cybso
Expand Down
5 changes: 5 additions & 0 deletions bom/openhab-addons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@
<artifactId>org.openhab.binding.digitalstrom</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.dirigera</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.openhab.addons.bundles</groupId>
<artifactId>org.openhab.binding.dlinksmarthome</artifactId>
Expand Down
13 changes: 13 additions & 0 deletions bundles/org.openhab.binding.dirigera/NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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/openhab-addons
890 changes: 890 additions & 0 deletions bundles/org.openhab.binding.dirigera/README.md

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions bundles/org.openhab.binding.dirigera/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://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.reactor.bundles</artifactId>
<version>4.3.0-SNAPSHOT</version>
</parent>

<artifactId>org.openhab.binding.dirigera</artifactId>

<name>openHAB Add-ons :: Bundles :: Dirigera Binding</name>
<dependencies>
<!-- version needs to match with other projects like org.openhab.io.openhabcloud.pom.xml -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20231013</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<features name="org.openhab.binding.dirigera-${project.version}" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
<repository>mvn:org.openhab.core.features.karaf/org.openhab.core.features.karaf.openhab-core/${ohc.version}/xml/features</repository>

<feature name="openhab-binding-dirigera" description="Dirigera Binding" version="${project.version}">
<feature>openhab-runtime-base</feature>
<bundle start-level="80">mvn:org.openhab.addons.bundles/org.openhab.binding.dirigera/${project.version}</bundle>
</feature>
</features>

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) 2010-2024 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.dirigera.internal;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.core.events.EventPublisher;
import org.openhab.core.thing.binding.BaseDynamicCommandDescriptionProvider;
import org.openhab.core.thing.i18n.ChannelTypeI18nLocalizationService;
import org.openhab.core.thing.link.ItemChannelLinkRegistry;
import org.openhab.core.thing.type.DynamicCommandDescriptionProvider;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

/**
* Dynamic provider of command options while leaving other state description fields as original.
*
* @author Bernd Weymann - Initial contribution
*/
@NonNullByDefault
@Component(service = { DynamicCommandDescriptionProvider.class, DirigeraCommandProvider.class })
public class DirigeraCommandProvider extends BaseDynamicCommandDescriptionProvider {
@Activate
public DirigeraCommandProvider(final @Reference EventPublisher eventPublisher, //
final @Reference ItemChannelLinkRegistry itemChannelLinkRegistry, //
final @Reference ChannelTypeI18nLocalizationService channelTypeI18nLocalizationService) {
this.eventPublisher = eventPublisher;
this.itemChannelLinkRegistry = itemChannelLinkRegistry;
this.channelTypeI18nLocalizationService = channelTypeI18nLocalizationService;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/**
* Copyright (c) 2010-2024 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.dirigera.internal;

import static org.openhab.binding.dirigera.internal.Constants.*;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.WWWAuthenticationProtocolHandler;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.openhab.binding.dirigera.internal.discovery.DirigeraDiscoveryManager;
import org.openhab.binding.dirigera.internal.handler.DirigeraHandler;
import org.openhab.binding.dirigera.internal.handler.airpurifier.AirPurifierHandler;
import org.openhab.binding.dirigera.internal.handler.blind.BlindHandler;
import org.openhab.binding.dirigera.internal.handler.controller.BlindsControllerHandler;
import org.openhab.binding.dirigera.internal.handler.controller.DoubleShortcutControllerHandler;
import org.openhab.binding.dirigera.internal.handler.controller.LightControllerHandler;
import org.openhab.binding.dirigera.internal.handler.controller.ShortcutControllerHandler;
import org.openhab.binding.dirigera.internal.handler.controller.SoundControllerHandler;
import org.openhab.binding.dirigera.internal.handler.light.ColorLightHandler;
import org.openhab.binding.dirigera.internal.handler.light.DimmableLightHandler;
import org.openhab.binding.dirigera.internal.handler.light.SwitchLightHandler;
import org.openhab.binding.dirigera.internal.handler.light.TemperatureLightHandler;
import org.openhab.binding.dirigera.internal.handler.plug.PowerPlugHandler;
import org.openhab.binding.dirigera.internal.handler.plug.SimplePlugHandler;
import org.openhab.binding.dirigera.internal.handler.plug.SmartPlugHandler;
import org.openhab.binding.dirigera.internal.handler.repeater.RepeaterHandler;
import org.openhab.binding.dirigera.internal.handler.scene.SceneHandler;
import org.openhab.binding.dirigera.internal.handler.sensor.AirQualityHandler;
import org.openhab.binding.dirigera.internal.handler.sensor.ContactSensorHandler;
import org.openhab.binding.dirigera.internal.handler.sensor.MotionLightSensorHandler;
import org.openhab.binding.dirigera.internal.handler.sensor.MotionSensorHandler;
import org.openhab.binding.dirigera.internal.handler.sensor.WaterSensorHandler;
import org.openhab.binding.dirigera.internal.handler.speaker.SpeakerHandler;
import org.openhab.core.i18n.LocationProvider;
import org.openhab.core.i18n.TimeZoneProvider;
import org.openhab.core.net.NetworkAddressService;
import org.openhab.core.storage.Storage;
import org.openhab.core.storage.StorageService;
import org.openhab.core.thing.Bridge;
import org.openhab.core.thing.Thing;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.binding.BaseThingHandlerFactory;
import org.openhab.core.thing.binding.ThingHandler;
import org.openhab.core.thing.binding.ThingHandlerFactory;
import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* The {@link DirigeraHandlerFactory} is responsible for creating things and thing
* handlers.
*
* @author Bernd Weymann - Initial contribution
*/
@NonNullByDefault
@Component(configurationPid = "binding.dirigera", service = ThingHandlerFactory.class)
public class DirigeraHandlerFactory extends BaseThingHandlerFactory {
private final Logger logger = LoggerFactory.getLogger(DirigeraHandlerFactory.class);
private final DirigeraDiscoveryManager discoveryManager;
private final DirigeraCommandProvider commandProvider;
private final TimeZoneProvider timeZoneProvider;
private final LocationProvider locationProvider;
private final Storage<String> bindingStorage;
private final HttpClient insecureClient;

@Activate
public DirigeraHandlerFactory(@Reference StorageService storageService,
final @Reference NetworkAddressService networkService, final @Reference DirigeraDiscoveryManager manager,
final @Reference TimeZoneProvider timeZoneProvider, final @Reference LocationProvider locationProvider,
final @Reference DirigeraCommandProvider commandProvider) {
this.discoveryManager = manager;
this.timeZoneProvider = timeZoneProvider;
this.locationProvider = locationProvider;
this.commandProvider = commandProvider;
this.insecureClient = new HttpClient(new SslContextFactory.Client(true));
insecureClient.setUserAgentField(null);
try {
this.insecureClient.start();
// from https://github.com/jetty-project/jetty-reactive-httpclient/issues/33#issuecomment-777771465
insecureClient.getProtocolHandlers().remove(WWWAuthenticationProtocolHandler.NAME);
} catch (Exception e) {
// catching exception is necessary due to the signature of HttpClient.start()
logger.warn("DIRIGERA FACTORY Failed to start http client: {}", e.getMessage());
throw new IllegalStateException("Could not create HttpClient", e);
}
String ip = networkService.getPrimaryIpv4HostAddress();
if (ip == null) {
logger.info("DIRIGERA FACTORY Cannot find host IP");
ip = "";
} else {
manager.initialize(insecureClient, ip);
}
bindingStorage = storageService.getStorage(BINDING_ID);
}

@Override
public boolean supportsThingType(ThingTypeUID thingTypeUID) {
return SUPPORTED_THING_TYPES_UIDS.contains(thingTypeUID);
}

@Override
protected @Nullable ThingHandler createHandler(Thing thing) {
ThingTypeUID thingTypeUID = thing.getThingTypeUID();
if (THING_TYPE_GATEWAY.equals(thingTypeUID)) {
return new DirigeraHandler((Bridge) thing, insecureClient, bindingStorage, discoveryManager,
timeZoneProvider, locationProvider, commandProvider, bundleContext);
} else if (THING_TYPE_COLOR_LIGHT.equals(thingTypeUID)) {
return new ColorLightHandler(thing, COLOR_LIGHT_MAP);
} else if (THING_TYPE_TEMPERATURE_LIGHT.equals(thingTypeUID)) {
return new TemperatureLightHandler(thing, TEMPERATURE_LIGHT_MAP);
} else if (THING_TYPE_DIMMABLE_LIGHT.equals(thingTypeUID)) {
return new DimmableLightHandler(thing, TEMPERATURE_LIGHT_MAP);
} else if (THING_TYPE_SWITCH_LIGHT.equals(thingTypeUID)) {
return new SwitchLightHandler(thing, TEMPERATURE_LIGHT_MAP);
} else if (THING_TYPE_MOTION_SENSOR.equals(thingTypeUID)) {
return new MotionSensorHandler(thing, MOTION_SENSOR_MAP);
// } else if (THING_TYPE_LIGHT_SENSOR.equals(thingTypeUID)) {
// return new LightSensorHandler(thing, LIGHT_SENSOR_MAP);
} else if (THING_TYPE_MOTION_LIGHT_SENSOR.equals(thingTypeUID)) {
return new MotionLightSensorHandler(thing, MOTION_LIGHT_SENSOR_MAP);
} else if (THING_TYPE_CONTACT_SENSOR.equals(thingTypeUID)) {
return new ContactSensorHandler(thing, CONTACT_SENSOR_MAP);
} else if (THING_TYPE_SIMPLE_PLUG.equals(thingTypeUID)) {
return new SimplePlugHandler(thing, SMART_PLUG_MAP);
} else if (THING_TYPE_POWER_PLUG.equals(thingTypeUID)) {
return new PowerPlugHandler(thing, SMART_PLUG_MAP);
} else if (THING_TYPE_SMART_PLUG.equals(thingTypeUID)) {
return new SmartPlugHandler(thing, SMART_PLUG_MAP);
} else if (THING_TYPE_SPEAKER.equals(thingTypeUID)) {
return new SpeakerHandler(thing, SPEAKER_MAP);
} else if (THING_TYPE_SCENE.equals(thingTypeUID)) {
return new SceneHandler(thing, SCENE_MAP, timeZoneProvider);
} else if (THING_TYPE_REPEATER.equals(thingTypeUID)) {
return new RepeaterHandler(thing, REPEATER_MAP);
} else if (THING_TYPE_LIGHT_CONTROLLER.equals(thingTypeUID)) {
return new LightControllerHandler(thing, LIGHT_CONTROLLER_MAP);
} else if (THING_TYPE_BLIND_CONTROLLER.equals(thingTypeUID)) {
return new BlindsControllerHandler(thing, BLIND_CONTROLLER_MAP);
} else if (THING_TYPE_SOUND_CONTROLLER.equals(thingTypeUID)) {
return new SoundControllerHandler(thing, SOUND_CONTROLLER_MAP);
} else if (THING_TYPE_SINGLE_SHORTCUT_CONTROLLER.equals(thingTypeUID)) {
return new ShortcutControllerHandler(thing, SHORTCUT_CONTROLLER_MAP, bindingStorage);
} else if (THING_TYPE_DOUBLE_SHORTCUT_CONTROLLER.equals(thingTypeUID)) {
return new DoubleShortcutControllerHandler(thing, SHORTCUT_CONTROLLER_MAP, bindingStorage);
} else if (THING_TYPE_AIR_QUALITY.equals(thingTypeUID)) {
return new AirQualityHandler(thing, AIR_QUALITY_MAP);
} else if (THING_TYPE_WATER_SENSOR.equals(thingTypeUID)) {
return new WaterSensorHandler(thing, WATER_SENSOR_MAP);
} else if (THING_TYPE_BLIND.equals(thingTypeUID)) {
return new BlindHandler(thing, BLINDS_MAP);
} else if (THING_TYPE_AIR_PURIFIER.equals(thingTypeUID)) {
return new AirPurifierHandler(thing, AIR_PURIFIER_MAP);
} else {
logger.debug("DIRIGERA FACTORY Request for {} doesn't match {}", thingTypeUID, THING_TYPE_GATEWAY);
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* Copyright (c) 2010-2024 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.dirigera.internal.actions;

import java.util.Optional;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.openhab.binding.dirigera.internal.interfaces.DebugHandler;
import org.openhab.core.automation.annotation.ActionInput;
import org.openhab.core.automation.annotation.ActionOutput;
import org.openhab.core.automation.annotation.RuleAction;
import org.openhab.core.thing.binding.ThingActions;
import org.openhab.core.thing.binding.ThingActionsScope;
import org.openhab.core.thing.binding.ThingHandler;

/**
* {@link DebugActions} which can be performed by any device
*
* @author Bernd Weymann - Initial contribution
*/
@ThingActionsScope(name = "dirigera")
@NonNullByDefault
public class DebugActions implements ThingActions {
private Optional<DebugHandler> thingHandler = Optional.empty();

/**
* Get handler device JSON for debug purposes.
*/
@RuleAction(label = "@text/actionGetJsonLabel", description = "@text/actionGetJsonDescription")
public @ActionOutput(name = "result", label = "Device JSON", type = "java.lang.String") String getJSON() {
if (thingHandler.isPresent()) {
return thingHandler.get().getJSON();
}
return "{}";
}

public static String getJSON(ThingActions actions) {
return ((DebugActions) actions).getJSON();
}

/**
* Get gateway token from everywhere. No need to call it directly from gateway.
*/
@RuleAction(label = "@text/actionGetTokenLabel", description = "@text/actionGetTokenDescription")
public @ActionOutput(name = "result", label = "Token", type = "java.lang.String") String getToken() {
if (thingHandler.isPresent()) {
return thingHandler.get().getToken();
}
return "no token available";
}

public static String getToken(ThingActions actions) {
return ((DebugActions) actions).getToken();
}

/**
* Set specific device into debug mode showing commands and updates on trace info level
*/
@RuleAction(label = "@text/actionSetDebugLabel", description = "@text/actionSetDebugDescription")
public void setDebug(
@ActionInput(name = "debug", label = "@text/actionDebugFlagLabel", description = "@text/actionDebugFlagDescription") boolean debug,
@ActionInput(name = "all", label = "@text/actionDebugFlagForAllLabel", description = "@text/actionDebugFlagForAllDescription") boolean all) {
if (thingHandler.isPresent()) {
thingHandler.get().setDebug(debug, all);
}
}

public static void setDebug(ThingActions actions, boolean debug, boolean all) {
((DebugActions) actions).setDebug(debug, all);
}

@Override
public void setThingHandler(ThingHandler handler) {
if (handler instanceof DebugHandler debugHandler) {
thingHandler = Optional.of(debugHandler);
}
}

@Override
public @Nullable ThingHandler getThingHandler() {
if (thingHandler.isPresent()) {
return thingHandler.get();
}
return null;
}
}
Loading