Skip to content

Commit

Permalink
[FIXED #67] param discoveryByActivation changed to boolean. Improved …
Browse files Browse the repository at this point in the history
…Javadoc.
  • Loading branch information
mvalla committed Apr 3, 2019
1 parent 6717491 commit a80401b
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@
<required>false</required>
</parameter>

<parameter name="discoveryByActivation" type="text">
<parameter name="discoveryByActivation" type="boolean">
<label>Discovery By Activation</label>
<description>Discover BUS devices when they are activated (also when a device scan is not active)</description>
<description>Discover BUS devices when they are activated (also when a device scan is not active) (default: false)</description>
<required>false</required>
<default>false</default>
</parameter>

</config-description>
Expand Down
13 changes: 7 additions & 6 deletions addons/binding/org.openhab.binding.openwebnet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ To add a gateway manually using PaperUI: go to *Inbox > "+" > OpenWebNet > click
Parameters for configuration:
- `host` : IP address / hostname of the BUS/SCS gateway (*mandatory*)
- `host` : IP address / hostname of the BUS/SCS gateway (String, *mandatory*)
- Example: `192.168.1.35`
- `port` : port (*optional*, default: `20000`)
- `passwd` : gateway password (*required* for gateways that have a password set. Default: `12345`)
- `port` : port (int, *optional*, default: `20000`)
- `passwd` : gateway password (String, *required* for gateways that have a password set. Default: `12345`)
- Example: `abcde` or `12345`
- if the BUS/SCS gateway is configured to accept connections from the openHAB computer IP address, no password should be required
- in all other cases, a password must be set. This includes gateways that have been discovered and added from Inbox that without a password settings will not become ONLINE
- `discoveryByActivation` : **=EXPERIMENTAL=** discover BUS devices when they are activated also when a device scan is not currently active (*optional*, default: `false`)
- `discoveryByActivation`: discover BUS devices when they are activated also when a device scan is not currently active (boolean, *optional*, default: `false`)
Alternatively the BUS/SCS Gateway thing can be configured using the `.things` file, see `openwebnet.things` example [below](#full-example).
Expand Down Expand Up @@ -295,7 +295,7 @@ You will need to add tags manually for items created using PaperUI when Simple M
### openwebnet.things:
```xtend
Bridge openwebnet:bus_gateway:mybridge "MyHOMEServer1" [ host="192.168.1.35", passwd="abcde" ] {
Bridge openwebnet:bus_gateway:mybridge "MyHOMEServer1" [ host="192.168.1.35", passwd="abcde", port=20000, discoveryByActivation=false ] {
bus_on_off_switch LR_switch "Living Room Light" [ where="51" ]
bus_dimmer LR_dimmer "Living Room Dimmer" [ where="25#4#01" ]
bus_dimmer LR_dalidimmer "Living Room Dali-Dimmer" [ where="0311#4#01" ]
Expand Down Expand Up @@ -430,8 +430,9 @@ See: https://github.com/mvalla/openhab2-addons/issues/14

## Changelog

**v2.5.0.M3 =IN PROGRESS=** - dd/mm/2019
**v2.5.0.M3 =IN PROGRESS=** - dd/04/2019
- [FIX #30] manually configured things are now ignored during auto-discovery
- [FIX #67] param discoveryByActivation changed to boolean
- [FIX #74] Updated README with energy example
- [FIX #77] Zigbee bridge: serial port as config parameter
- checked licence headers & javadocs. Improved logging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected void handleChannelCommand(ChannelUID channel, Command command) {
/**
* Handles Automation Rollershutter command (UP/DOWN, STOP/MOVE, PERCENT xx%)
*
* @param command
* @param command the command to handle
*/
private void handleShutterCommand(Command command) {
calibrating = CALIBRATION_INACTIVE; // cancel calibration if we receive a command
Expand Down Expand Up @@ -195,7 +195,7 @@ private void handleShutterCommand(Command command) {
/**
* Handles Automation Percent command
*
* @param command
* @param command the command to handle
*/
private void handlePercentCommand(PercentType command) {
int percent = command.intValue();
Expand Down Expand Up @@ -274,6 +274,8 @@ protected void handleMessage(BaseOpenMessage msg) {

/**
* Updates automation device state based on an Automation message received from OWN network
*
* @param msg the Automation message
*/
private void updateAutomationState(Automation msg) {
logger.debug("==OWN:AutomationHandler== updateAutomationState() - msg={} what={}", msg, msg.getWhat());
Expand Down Expand Up @@ -360,8 +362,7 @@ private void updateStateInt(int newState) {
}

/**
* update positionEst based on movement time and current internalState
*
* Updates positionEst based on movement time and current internalState
*/
private void updatePosition() {
int newPos = POSITION_UNKNOWN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class OpenWebNetBridgeHandler extends ConfigStatusBridgeHandler implement
private static final int GATEWAY_ONLINE_TIMEOUT = 20; // (sec) Time to wait for the gateway to become connected
private static final int CONFIG_GATEWAY_DEFAULT_PORT = 20000;
private static final String CONFIG_GATEWAY_DEFAULT_PASSWD = "12345";
private static final boolean CONFIG_GATEWAY_DEFAULT_DISCVERY_ACTIVATION = false;

public final static Set<ThingTypeUID> SUPPORTED_THING_TYPES = OpenWebNetBindingConstants.BRIDGE_SUPPORTED_THING_TYPES;

Expand All @@ -87,8 +88,10 @@ public class OpenWebNetBridgeHandler extends ConfigStatusBridgeHandler implement
public OpenWebNetDeviceDiscoveryService deviceDiscoveryService;
private boolean searchingGatewayDevices = false; // devices search is in progress on gateway
private boolean scanIsActive = false; // a device scan has been activated by OpenWebNetDeviceDiscoveryService;
private boolean discoveryByActivation = false; // discover BUS devices when they are activated also when a device
// scan is not active
private boolean discoveryByActivation = CONFIG_GATEWAY_DEFAULT_DISCVERY_ACTIVATION; // discover BUS devices when
// they are activated also when
// a device
// scan is not active
@Nullable
private OpenNewDeviceListener deviceDiscoveryListener = null;

Expand Down Expand Up @@ -179,6 +182,7 @@ private void initBusGateway() {
Object portConfig = getConfig().get(CONFIG_PROPERTY_PORT);
if (portConfig != null) {
port = ((BigDecimal) portConfig).intValue();
// TODO handle case parameter is not a number
}
String passwd = (String) (getConfig().get(CONFIG_PROPERTY_PASSWD));
if (passwd == null) {
Expand All @@ -190,10 +194,20 @@ private void initBusGateway() {
} else {
passwdMasked = "******";
}
String discoveryConfig = (String) getConfig().get(CONFIG_PROPERTY_DISCOVERY_ACTIVATION);
if (discoveryConfig != null && discoveryConfig.equalsIgnoreCase("true")) {
discoveryByActivation = true;
Object discoveryConfig = getConfig().get(CONFIG_PROPERTY_DISCOVERY_ACTIVATION);
if (discoveryConfig != null) {
if (discoveryConfig instanceof java.lang.Boolean) {
discoveryByActivation = (boolean) getConfig().get(CONFIG_PROPERTY_DISCOVERY_ACTIVATION);
logger.debug("==OWN== discoveryByActivation={}", discoveryByActivation);
} else {
logger.warn(
"==OWN== invalid discoveryByActivation parameter value (should be true/false). Keeping current value={}.",
discoveryByActivation);
}
}
// if (discoveryConfig != null && discoveryConfig.equalsIgnoreCase("true")) {
// discoveryByActivation = true;
// }
logger.debug("==OWN== Creating new BUS gateway with config properties: {}:{}, pwd={}", host, port,
passwdMasked);
gateway = OpenWebNet.gatewayBus(host, port, passwd);
Expand Down Expand Up @@ -323,8 +337,8 @@ private void discoverByActivation(BaseOpenMessage baseMsg) {
/**
* Register a device ThingHandler to this BridgHandler
*
* @param String ownId device OpenWebNet id
* @param OpenWebNetThingHandler thingHandler to register
* @param ownId the device OpenWebNet id
* @param thingHandler the thing handler to be registered
*/
protected void registerDevice(String ownId, OpenWebNetThingHandler thingHandler) {
if (registeredDevices.containsKey(ownId)) {
Expand All @@ -338,7 +352,7 @@ protected void registerDevice(String ownId, OpenWebNetThingHandler thingHandler)
/**
* Un-register a device from this bridge handler
*
* @param ownId device OpenWebNet id
* @param ownId the device OpenWebNet id
*/
protected void unregisterDevice(String ownId) {
if (registeredDevices.remove(ownId) != null) {
Expand All @@ -351,9 +365,8 @@ protected void unregisterDevice(String ownId) {
/**
* Get a ThingHandler for a device associated to this BridgeHandler, based on ownID
*
* @param String ownId OpenWebNet id for device
* @returns OpenWebNetThingHandler handler for the device, or null if the device is not associated with this
* BridgeHanldler
* @param ownId OpenWebNet id for device
* @returns an handler for the device, or null if the device is not associated with this BridgeHanldler
*/
private @Nullable OpenWebNetThingHandler getDevice(String ownId) {
return registeredDevices.get(ownId);
Expand Down Expand Up @@ -408,7 +421,7 @@ public void onConnected() {
logger.info("==OWN== ------------------- CONNECTED to ZigBee gateway - USB port: {}",
((OpenGatewayZigBee) gateway).getConnectedPort());
} else {
logger.info("==OWN== ------------------- CONNECTED to BUS gateway - {}:{}",
logger.info("==OWN== ------------------- CONNECTED to BUS gateway '{}' ({}:{})", thing.getUID(),
((OpenGatewayBus) gateway).getHost(), ((OpenGatewayBus) gateway).getPort());
// update gw model
if (properties.get(PROPERTY_MODEL) != ((OpenGatewayBus) gateway).getModelName()) {
Expand All @@ -430,7 +443,7 @@ public void onConnected() {
}
if (propertiesChanged) {
updateProperties(properties);
logger.info("==OWN== properties updated for {}", getThing().getBridgeUID());
logger.info("==OWN== properties updated for '{}'", thing.getUID());
}
updateStatus(ThingStatus.ONLINE);
}
Expand Down Expand Up @@ -500,30 +513,32 @@ public void onReconnected() {
}

/**
* Return a ownId string (=WHO.WHERE) from a deviceWhere thing config parameter and ThingHandler.
* In case of ZigBee gateway, ownId=Z.ADDR
* Return a ownId string (=WHO.WHERE) from a deviceWhere thing config parameter and its handler.
*
* @param String deviceWhere
* @param OpenWebNetThingHandler thing handler
* @return ownId string
* @param deviceWhere
* @param handler the thing handler
* @return the ownId
*/
protected String ownIdFromDeviceWhere(String deviceWhere, OpenWebNetThingHandler handler) {
if (isBusGateway) {
return handler.ownIdPrefix() + "." + deviceWhere;
} else {
return "Z" + "." + deviceWhere;
}
return handler.ownIdPrefix() + "." + deviceWhere;
}

/**
* Returns a ownId string (=WHO.WHERE) from a WHERE address and WHO
*
* @param where the WHERE address
* @param who the WHO
* @return the ownId
*/
public String ownIdFromWhoWhere(String where, String who) {
return who + "." + normalizeWhere(where);
}

/**
* Return a ownId string (=WHO.WHERE) from a BaseOpenMessage
*
* @param BaseOpenMessage baseMsg message
* @return ownId String
* @param baseMsg the message
* @return the ownId String
*/
private String ownIdFromMessage(BaseOpenMessage baseMsg) {
return baseMsg.getWho().value() + "." + normalizeWhere(baseMsg.getWhere());
Expand All @@ -533,8 +548,8 @@ private String ownIdFromMessage(BaseOpenMessage baseMsg) {
* Transform a WHERE string address into a Thing id string based on bridge type (BUS/ZigBee).
* '#' in WHERE are changed to 'h'
*
* @param String where WHERE address
* @return String thing Id
* @param where the WHERE address
* @return the thing Id
*/
public String thingIdFromWhere(String where) {
return normalizeWhere(where).replace('#', 'h'); // '#' cannot be used in ThingUID;
Expand All @@ -543,30 +558,31 @@ public String thingIdFromWhere(String where) {
// @formatter:off
/**
*
* deviceWhere (DevAddrParam)
* TYPE WHERE normalizeWhere ownId ThingID
* deviceWhere
* (DevAddrParam)
* TYPE WHERE normalizeWhere() ownId ThingID
* ---------------------------------------------------------------
* Zigbee 789309801#9 7893098 Z.7893098 7893098 (*)
* Switch 51 51 1.51 51
* Dimmer 25#4#01 25#4#01 1.25#4#01 25h4h01 (*)
* Autom 93 93 2.93 93
* Thermo #1 or 1 1 4.1 1 (*)
* TempSen 500 500 4.500 500
* Energy 51 51 18.51 51
* CEN 51 51 15.51 51
* CEN+ 212 212 25.212 212
* DryContact 399 399 25.399 399
* Zigbee 789309801#9 7893098 1.7893098 7893098
* Switch 51 51 1.51 51
* Dimmer 25#4#01 25#4#01 1.25#4#01 25h4h01
* Autom 93 93 2.93 93
* Thermo #1 or 1 1 4.1 1
* TempSen 500 500 4.500 500
* Energy 51 51 18.51 51
* CEN 51 51 15.51 51
* CEN+ 212 212 25.212 212
* DryContact 399 399 25.399 399
*
* METHOD CALLED FROM CALLING
* ------ ----------- -------
* - OpenWebNetDeviceDiscoveryService new discovery result --> deviceWhere = normalizeWhere()
* - ThingHandler.initialize --> ownId = ownIdFromDeviceWhere()
* - public normalizeWhere() locally and OpenWebNetDeviceDiscoveryService --> getAddrFromWhere
* - public getAddrFromWhere --> remove last 4
* - OpenWebNetDeviceDiscoveryService new discovery result --> deviceWhere = normalizeWhere()
* - ThingHandler.initialize --> ownId = ownIdFromDeviceWhere()
* - public normalizeWhere() locally and OpenWebNetDeviceDiscoveryService --> getAddrFromWhere()
* - public getAddrFromWhere() --> remove last 4
* - protected ownIdFromDeviceWhere() ThingHandler.initialize --> ownIdPrefix() + "." + deviceWhere
* - private ownIdFromMessage() onMessage()
* - public thingIdFromWhere() OpenWebNetDeviceDiscoveryService --> normalizeWhere().replace(#)
* - private ownIdFromMessage() onMessage()
* - public thingIdFromWhere() OpenWebNetDeviceDiscoveryService --> normalizeWhere().replace(#)
*/
/*
public enum TEST {
Expand Down Expand Up @@ -609,7 +625,10 @@ private boolean testTransformations() {
*/

/**
* Normalise a WHERE string for Thermo and Zigbee devices
* Normalize a WHERE address for Thermo and Zigbee devices
*
* @param where the WHERE address
* @return the normalized WHERE
*/
public String normalizeWhere(String where) {
String str = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ protected void handleMessage(BaseOpenMessage msg) {

/**
* Updates energy power state based on a EnergyManagement message received from the OWN network
*
* @param msg the EnergyManagement message received
*/
private void updateActivePower(EnergyManagement msg) {
logger.debug("==OWN:EnergyHandler== updateActivePower() for thing: {}", thing.getUID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ protected void handleChannelCommand(ChannelUID channel, Command command) {
}

/**
* Handles Lighting switch command
* Handles Lighting switch command for a channel
*
* @param channel
* @param command
* @param channel the channel
* @param command the command
*/
private void handleSwitchCommand(ChannelUID channel, Command command) {
logger.debug("==OWN:LightingHandler== handleSwitchCommand() (command={} - channel={})", command, channel);
Expand All @@ -122,7 +122,7 @@ private void handleSwitchCommand(ChannelUID channel, Command command) {
/**
* Handles Lighting brightness command (ON, OFF, xx%, INCREASE, DECREASE)
*
* @param command
* @param command the command
*/
private void handleBrightnessCommand(Command command) {
logger.debug("==OWN:LightingHandler== handleBrightnessCommand() (command={})", command);
Expand Down Expand Up @@ -219,6 +219,8 @@ protected void handleMessage(BaseOpenMessage msg) {

/**
* Updates light state based on a OWN Lighting message received
*
* @param msg the Lighting message received
*/
private void updateLightState(Lighting msg) {
logger.debug("==OWN:LightingHandler== updateLightState() for thing: {}", thing.getUID());
Expand All @@ -232,6 +234,8 @@ private void updateLightState(Lighting msg) {

/**
* Updates on/off state based on a OWN Lighting message received
*
* @param msg the Lighting message received
*/
private void updateLightOnOffState(Lighting msg) {
String channelID;
Expand All @@ -257,6 +261,8 @@ private void updateLightOnOffState(Lighting msg) {

/**
* Updates brightness level based on a OWN Lighting message received
*
* @param msg the Lighting message received
*/
private synchronized void updateLightBrightnessState(Lighting msg) {
final String channel = CHANNEL_BRIGHTNESS;
Expand Down Expand Up @@ -360,9 +366,9 @@ private int percentToLevel(int percent) {
}

/**
* Returns a WHERE address (string) based on bridge type and unit (optional)
* Returns a WHERE address based on bridge type and unit (optional)
*
* @param unit device unit
* @param unit the device unit
**/
protected String toWhere(String unit) {
logger.debug("==OWN:LightingHandler== toWhere(unit) ownId={}", ownId);
Expand All @@ -376,7 +382,7 @@ protected String toWhere(String unit) {
/**
* Returns a WHERE address based on channel
*
* @param channel channel
* @param channel the channel
**/
protected String toWhere(ChannelUID channel) {
logger.debug("==OWN:LightingHandler== toWhere(ChannelUID) ownId={}", ownId);
Expand Down
Loading

0 comments on commit a80401b

Please sign in to comment.