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

[homematic] Validate datapoint values before writing to config #12557

Merged
merged 2 commits into from
Apr 3, 2022

Conversation

maniac103
Copy link
Contributor

HM config datapoint values on some devices can be out of their valid
range in some cases, particularly if they are unused by the device
currently. Since openhab-core now validates attempts to update
configuration by the thing handlers, make sure we always send a valid
configuration even for those affected datapoints.

One example for such behaviour is HmIPW-DRBL4, which has multiple datapoints which depend on each other:

  • POWERUP_JUMPTARGET can have values OFF, ON, OFF_DELAY, ON_DELAY
  • POWERUP_ONDELAY_VALUE, POWERUP_ONDELAY_UNIT are only used if POWERUP_JUMPTARGET has value ON_DELAY
  • likewise, POWERUP_OFFDELAY_VALUE and POWERUP_OFFDELAY_UNIT are only used if POWERUP_JUMPTARGET has value OFF_DELAY
  • if e.g. the POWERUP_JUMPTARGET is OFF, e.g. POWERUP_ONDELAY_VALUE might stay uninitialized by CCU and/or device itself, in which case it may be reported with an invalid value

Fixes the issue reported here

@maniac103 maniac103 requested a review from gerrieg as a code owner April 1, 2022 12:32
@maniac103
Copy link
Contributor Author

@fwolter @MHerbst Please review as well ;-)

HM config datapoint values on some devices can be out of their valid
range in some cases, particularly if they are unused by the device
currently [1]. Since openhab-core now validates attempts to update
configuration by the thing handlers, make sure we always send a valid
configuration even for those affected datapoints.

[1] One example for such behaviour is HmIPW-DRBL4, which has multiple
    datapoints which depend on each other
    - POWERUP_JUMPTARGET can have values OFF, ON, OFF_DELAY, ON_DELAY
    - POWERUP_ONDELAY_VALUE, POWERUP_ONDELAY_UNIT are only used if
      POWERUP_JUMPTARGET has value ON_DELAY
    - likewise, POWERUP_OFFDELAY_VALUE and POWERUP_OFFDELAY_UNIT are
      only used if POWERUP_JUMPTARGET has value OFF_DELAY
    - if e.g. the POWERUP_JUMPTARGET is OFF, e.g. POWERUP_ONDELAY_VALUE
      might stay uninitialized by CCU and/or device itself, in which
      case it may be reported with an invalid value

Signed-off-by: Danny Baumann <dannybaumann@web.de>
@jlaur jlaur added the bug An unexpected problem or unintended behavior of an add-on label Apr 2, 2022
@@ -140,8 +140,7 @@ private void doInitializeInBackground() throws GatewayNotAvailableException, Hom
loadHomematicChannelValues(channel);
for (HmDatapoint dp : channel.getDatapoints()) {
if (dp.getParamsetType() == HmParamsetType.MASTER) {
config.put(MetadataUtils.getParameterName(dp),
dp.isEnumType() ? dp.getOptionValue() : dp.getValue());
config.put(MetadataUtils.getParameterName(dp), getValueForConfiguration(dp));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As getValueForConfiguration can retrun null, I am not sure whether this config entry should be set to null, or not set at all ?
I am even not sure if this is valid to set a null value for a config parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only case under which getValueForConfiguration() returns null is if the datapoint holds a null value. In that case I'd say that writing null into the config is correct.
The places I checked that care about the keys present in the map (those that call containsKey() and keySet() seem to be able to deal with null values being present. Not sure about e.g. the UI, but given the previous code put null values in this case (value being null) as well, I guess it should be fine.

Signed-off-by: Danny Baumann <dannybaumann@web.de>
Copy link
Contributor

@lolodomo lolodomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lolodomo lolodomo merged commit 28ce7eb into openhab:main Apr 3, 2022
@lolodomo lolodomo added this to the 3.3 milestone Apr 3, 2022
NickWaterton pushed a commit to NickWaterton/openhab-addons that referenced this pull request Apr 27, 2022
…ab#12557)

* [homematic] Validate datapoint values before writing to config

HM config datapoint values on some devices can be out of their valid
range in some cases, particularly if they are unused by the device
currently [1]. Since openhab-core now validates attempts to update
configuration by the thing handlers, make sure we always send a valid
configuration even for those affected datapoints.

[1] One example for such behaviour is HmIPW-DRBL4, which has multiple
    datapoints which depend on each other
    - POWERUP_JUMPTARGET can have values OFF, ON, OFF_DELAY, ON_DELAY
    - POWERUP_ONDELAY_VALUE, POWERUP_ONDELAY_UNIT are only used if
      POWERUP_JUMPTARGET has value ON_DELAY
    - likewise, POWERUP_OFFDELAY_VALUE and POWERUP_OFFDELAY_UNIT are
      only used if POWERUP_JUMPTARGET has value OFF_DELAY
    - if e.g. the POWERUP_JUMPTARGET is OFF, e.g. POWERUP_ONDELAY_VALUE
      might stay uninitialized by CCU and/or device itself, in which
      case it may be reported with an invalid value

Signed-off-by: Danny Baumann <dannybaumann@web.de>
Signed-off-by: Nick Waterton <n.waterton@outlook.com>
@openhab-bot
Copy link
Collaborator

This pull request has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-3-3-milestone-discussion/132715/130

andan67 pushed a commit to andan67/openhab-addons that referenced this pull request Nov 6, 2022
…ab#12557)

* [homematic] Validate datapoint values before writing to config

HM config datapoint values on some devices can be out of their valid
range in some cases, particularly if they are unused by the device
currently [1]. Since openhab-core now validates attempts to update
configuration by the thing handlers, make sure we always send a valid
configuration even for those affected datapoints.

[1] One example for such behaviour is HmIPW-DRBL4, which has multiple
    datapoints which depend on each other
    - POWERUP_JUMPTARGET can have values OFF, ON, OFF_DELAY, ON_DELAY
    - POWERUP_ONDELAY_VALUE, POWERUP_ONDELAY_UNIT are only used if
      POWERUP_JUMPTARGET has value ON_DELAY
    - likewise, POWERUP_OFFDELAY_VALUE and POWERUP_OFFDELAY_UNIT are
      only used if POWERUP_JUMPTARGET has value OFF_DELAY
    - if e.g. the POWERUP_JUMPTARGET is OFF, e.g. POWERUP_ONDELAY_VALUE
      might stay uninitialized by CCU and/or device itself, in which
      case it may be reported with an invalid value

Signed-off-by: Danny Baumann <dannybaumann@web.de>
andrasU pushed a commit to andrasU/openhab-addons that referenced this pull request Nov 12, 2022
…ab#12557)

* [homematic] Validate datapoint values before writing to config

HM config datapoint values on some devices can be out of their valid
range in some cases, particularly if they are unused by the device
currently [1]. Since openhab-core now validates attempts to update
configuration by the thing handlers, make sure we always send a valid
configuration even for those affected datapoints.

[1] One example for such behaviour is HmIPW-DRBL4, which has multiple
    datapoints which depend on each other
    - POWERUP_JUMPTARGET can have values OFF, ON, OFF_DELAY, ON_DELAY
    - POWERUP_ONDELAY_VALUE, POWERUP_ONDELAY_UNIT are only used if
      POWERUP_JUMPTARGET has value ON_DELAY
    - likewise, POWERUP_OFFDELAY_VALUE and POWERUP_OFFDELAY_UNIT are
      only used if POWERUP_JUMPTARGET has value OFF_DELAY
    - if e.g. the POWERUP_JUMPTARGET is OFF, e.g. POWERUP_ONDELAY_VALUE
      might stay uninitialized by CCU and/or device itself, in which
      case it may be reported with an invalid value

Signed-off-by: Danny Baumann <dannybaumann@web.de>
Signed-off-by: Andras Uhrin <andras.uhrin@gmail.com>
psmedley pushed a commit to psmedley/openhab-addons that referenced this pull request Feb 23, 2023
…ab#12557)

* [homematic] Validate datapoint values before writing to config

HM config datapoint values on some devices can be out of their valid
range in some cases, particularly if they are unused by the device
currently [1]. Since openhab-core now validates attempts to update
configuration by the thing handlers, make sure we always send a valid
configuration even for those affected datapoints.

[1] One example for such behaviour is HmIPW-DRBL4, which has multiple
    datapoints which depend on each other
    - POWERUP_JUMPTARGET can have values OFF, ON, OFF_DELAY, ON_DELAY
    - POWERUP_ONDELAY_VALUE, POWERUP_ONDELAY_UNIT are only used if
      POWERUP_JUMPTARGET has value ON_DELAY
    - likewise, POWERUP_OFFDELAY_VALUE and POWERUP_OFFDELAY_UNIT are
      only used if POWERUP_JUMPTARGET has value OFF_DELAY
    - if e.g. the POWERUP_JUMPTARGET is OFF, e.g. POWERUP_ONDELAY_VALUE
      might stay uninitialized by CCU and/or device itself, in which
      case it may be reported with an invalid value

Signed-off-by: Danny Baumann <dannybaumann@web.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An unexpected problem or unintended behavior of an add-on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants