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

fix: meterType devices missing ccSpecific values #35

Merged
merged 4 commits into from
Nov 30, 2020

Conversation

varet80
Copy link
Collaborator

@varet80 varet80 commented Nov 27, 2020

When a Command Class is type Meter. In some cases is not a sensor. This metric is a Delta in time, or reset parameter for the Sensor.
There Parameters miss the ccSpecific values, which sets the type of sensor. This change fixes this error

@coveralls
Copy link

Pull Request Test Coverage Report for Build 387567036

  • 188 of 472 (39.83%) changed or added relevant lines in 7 files are covered.
  • 29 unchanged lines in 2 files lost coverage.
  • Overall coverage increased (+0.5%) to 28.833%

Changes Missing Coverage Covered Lines Changed/Added Lines %
app.js 0 7 0.0%
lib/ZwaveClient.js 0 30 0.0%
lib/Gateway.js 52 299 17.39%
Files with Coverage Reduction New Missed Lines %
lib/utils.js 1 85.19%
lib/Gateway.js 28 21.68%
Totals Coverage Status
Change from base Build 387238528: 0.5%
Covered Lines: 1827
Relevant Lines: 6463

💛 - Coveralls

@varet80 varet80 changed the base branch from master to feat#hassDiscovery November 27, 2020 18:03
lib/Gateway.js Show resolved Hide resolved
@varet80 varet80 requested a review from robertsLando November 28, 2020 11:21
@varet80
Copy link
Collaborator Author

varet80 commented Nov 28, 2020

I am trying to fix hass discovery for multilevel sensors of temperature
The sensor has unit of measurement and this is a problem. I do not know how to do this in the node part. I spent a bit of time but...could not find it

the hass payload is:

{
  "value_template": "{{ value_json.value }}",
  "device_class": "temperature",
  "state_topic": "zwave2mqtt/Garage/sensorBackSide/49/0/Air_temperature",
  "json_attributes_topic": "zwave2mqtt/Garage/sensorBackSide/49/0/Air_temperature",
  "device": {
    "identifiers": [
      "zwavejs2mqtt_0xcddb486e_node35"
    ],
    "manufacturer": "Shenzhen Neo Electronics Co., Ltd.",
    "model": "PIR Motion Sensor with Temperature Sensor (PD03Z)",
    "name": "Garage-sensorBackSide",
    "sw_version": "3.80"
  },
  "name": "Garage-sensorBackSide_temperature_air",
  "unique_id": "zwavejs2mqtt_0xcddb486e_35-49-0-Air temperature"
}

The payload is:

{
  "id": "35-49-0-Air temperature",
  "nodeId": 35,
  "commandClass": 49,
  "commandClassName": "Multilevel Sensor",
  "endpoint": 0,
  "property": "Air temperature",
  "propertyName": "Air temperature",
  "type": "number",
  "readable": true,
  "writeable": false,
  "label": "Air temperature",
  "ccSpecific": {
    "sensorType": 1,
    "scale": 0
  },
  "genre": "user",
  "unit": "°C",
  "list": false,
  "value": 0,
  "lastUpdate": 1606596275869
}

I think i always knew this is it:

        if (valueId.unit) {
          // https://github.com/zwave-js/node-zwave-js/blob/master/packages/config/config/scales.json
          cfg.discovery_payload.unit_of_measurement = valueId.unit
        }

Patch:

        // Discovered valueId.unit also exists. therefore added both unit and units to be
        // checked, but only one used
        if (valueId.unit) {
          // https://github.com/zwave-js/node-zwave-js/blob/master/packages/config/config/scales.json
          cfg.discovery_payload.unit_of_measurement = valueId.unit
        } else if (valueId.units) {
          cfg.discovery_payload.unit_of_measurement = valueId.unit
        }
I added a change on code and on my other pull request https://github.com/zwave-js/zwavejs2mqtt/pull/36

Copy link
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

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

LGTM

@robertsLando robertsLando merged commit ac4ed9a into feat#hassDiscovery Nov 30, 2020
@robertsLando robertsLando deleted the fix#MeterType-ccSpecific branch November 30, 2020 08:36
robertsLando added a commit that referenced this pull request Nov 30, 2020
* feat: bind target values to current

* feat(wip): hass discovery

* fix: better discovery support

* fix: hass socket apis

* fix: alarmType and meterType mapping

* fix: use commandClasses instead of hardCoded numbers

* refactor: better docs on methods

* fix: converted some values in hass devices.js

* fix: converted some more values in devices.js

* feat: skip discovety flag

* fix: lint issues

* fix: ignore discovery

* fix: converted some more valueIds of devices.json

* fix: lint issues

* fix: push target value in values

* fix: mode_map and fan _mode_map

* fix: allow empty json device

* fix: added ccSpecific to value meta

* fix: setpoints valueIds

* fix: commandclasses import

* fix: set defaiult endpoint to 0

* feat: added ccSpecific

* fix: undefined in num2hex

* fix: use 5.4.1-alpha.0

* fix: probably fix to map template bug

* fix: mode_map template creation

* fix: added brackets to keys

* fix: added comments

* fix: getMappedValuesTemplate check type of value

* fix: lint errors

* docs: fixed hass docs

* docs: migration and why zwavejs

* docs: bitmask and color values

* fix: lint issues

* docs: fix for review

* fix: typo

* fix: lint on readme

* docs: fix

* docs: added some points to why zwavejs section

* fix: payload parse of modes when discovery is enabled

* fix: missing ccSpecific values (#35)

* fix: binary sensors, units and undefined labels (#36)

* fix: lint issues

Co-authored-by: V Aretakis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants