-
Notifications
You must be signed in to change notification settings - Fork 521
WWSTCERT-9096 Ct clamp driver wwsm #2552
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
a9d571b
1f2ebee
2112515
cf02dcf
8546844
f7a9dab
a5f9d46
21e07f3
f101e5c
a5d3c87
e04499e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,4 +7,4 @@ lua_libs-api_* | |
| tools/test_output/* | ||
| tools/coverage_output/* | ||
| .DS_Store | ||
| .venv/ | ||
| .venv/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,10 +28,36 @@ zigbeeManufacturer: | |
| manufacturer: ShinaSystem | ||
| model: "PMM-300Z3" | ||
| deviceProfileName: power-meter-consumption-report-sihas | ||
| - id: Chameleon/CT101xxxx | ||
| deviceLabel: Chameleon CT Clamp | ||
| manufacturer: Chameleon Technology | ||
| model: CT101xxxx | ||
| deviceProfileName: ct-clamp | ||
| zigbeeGeneric: | ||
| - id: "genericMeter" | ||
| deviceLabel: Zigbee Meter | ||
| clusters: | ||
| server: | ||
| - 0x0702 #Simple Metering | ||
| deviceProfileName: power-meter | ||
| - id: "ChameleonCTClamp" | ||
| deviceLabel: Zigbee CT | ||
| deviceIdentifiers: | ||
| - 0x000D | ||
| zigbeeProfiles: | ||
| - 0x0104 | ||
| clusters: | ||
| server: | ||
| - 0x0000 #Basic | ||
| - 0x0001 #Power Configuration | ||
| - 0x0002 #Device Temperature Configuration | ||
| - 0x0003 #Identify | ||
| - 0x0019 #Over the Air Bootloading | ||
| - 0x0020 #Poll Control | ||
| - 0x0702 #Simple Metering | ||
| - 0x0B04 #Electrical Measurement | ||
| client: | ||
| - 0x0003 #Identify | ||
| deviceProfileName: ct-clamp | ||
|
|
||
|
|
||
|
Comment on lines
+43
to
+63
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please just include the manufacturer-specific fingerprint |
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since there isn't anything here that makes this device-specific, could you please rename to something like |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| name: ct-clamp | ||
| components: | ||
| - id: main | ||
| capabilities: | ||
| - id: powerMeter | ||
| version: 1 | ||
| - id: energyMeter | ||
| version: 1 | ||
| - id: firmwareUpdate | ||
| version: 1 | ||
| - id: refresh | ||
| version: 1 | ||
| - id: battery | ||
| version: 1 | ||
| - id: temperatureMeasurement | ||
| version: 1 | ||
| categories: | ||
| - name: CurbPowerMeter | ||
|
|
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing copyright/license statement |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| local clusters = require "st.zigbee.zcl.clusters" | ||
| local cluster_base = require "st.zigbee.cluster_base" | ||
| local data_types = require "st.zigbee.data_types" | ||
| local capabilities = require "st.capabilities" | ||
| local log = require "log" | ||
|
|
||
| local TemperatureMeasurement = clusters.DeviceTemperatureConfiguration | ||
| local PowerConfiguration = clusters.PowerConfiguration | ||
|
|
||
| local ZIGBEE_FINGERPRINT = { | ||
| {model = "CT101xxxx" } | ||
| } | ||
|
|
||
| -- temperature: 0.5C, battery level remaining: 1% | ||
| local configuration = { | ||
| { | ||
| cluster = TemperatureMeasurement.ID, | ||
| attribute = TemperatureMeasurement.attributes.CurrentTemperature.ID, | ||
| minimum_interval = 30, | ||
| maximum_interval = 3600, | ||
| data_type = TemperatureMeasurement.attributes.CurrentTemperature.base_type, | ||
| reportable_change = 1 | ||
| }, | ||
| { | ||
| cluster = PowerConfiguration.ID, | ||
| attribute = PowerConfiguration.attributes.BatteryPercentageRemaining.ID, | ||
| minimum_interval = 30, | ||
| maximum_interval = 3600, | ||
| data_type = PowerConfiguration.attributes.BatteryPercentageRemaining.base_type, | ||
| reportable_change = 2 | ||
| } | ||
| } | ||
|
|
||
| local is_chameleon_ct_clamp = function(opts, driver, device) | ||
| for _, fingerprint in ipairs(ZIGBEE_FINGERPRINT) do | ||
| if device:get_model() == fingerprint.model then | ||
| return true | ||
| end | ||
| end | ||
| return false | ||
| end | ||
|
|
||
| local function battery_level_handler(driver, device, value, _zb_rx) | ||
| if type(value.value) == "number" then | ||
| local number = value.value/2 | ||
|
||
| local integer_result = math.floor(number) | ||
| device:emit_event(capabilities.battery.battery(integer_result)) | ||
| else | ||
| log.error("Invalid battery level value received: " .. tostring(value.value)) | ||
| end | ||
| end | ||
|
|
||
| local function temperature_handler(driver, device, value, _zb_rx) | ||
| if type(value.value) == "number" then | ||
| device:emit_event(capabilities.temperatureMeasurement.temperature({ value = value.value, unit = "C" })) | ||
| else | ||
| log.error("Invalid temperature value received: " .. tostring(value.value)) | ||
| end | ||
| end | ||
|
|
||
| local function device_init(driver, device) | ||
| if configuration ~= nil then | ||
| for _, attribute in ipairs(configuration) do | ||
| device:add_configured_attribute(attribute) | ||
| end | ||
| end | ||
|
|
||
| local batt_level = device:get_latest_state("main", capabilities.battery.ID, capabilities.battery.battery.NAME) or nil | ||
| if batt_level == nil then | ||
| device:emit_event(capabilities.battery.battery.normal()) | ||
| end | ||
|
Comment on lines
+68
to
+71
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would expect this to go in |
||
| end | ||
|
|
||
| local function added_handler(self, device) | ||
| device:emit_event(capabilities.temperatureMeasurement.temperature({ value = 0, unit = "C" })) | ||
| device:emit_event(capabilities.battery.battery({value = 0, unit = "%" })) | ||
| end | ||
|
|
||
| local ct_clamp_battery_temperature_handler = { | ||
| NAME = "ct_clamp_battery_temperature_handler", | ||
| zigbee_handlers = { | ||
| attr = { | ||
| [PowerConfiguration.ID] = { | ||
| [PowerConfiguration.attributes.BatteryPercentageRemaining.ID] = battery_level_handler | ||
| }, | ||
| [TemperatureMeasurement.ID] = { | ||
| [TemperatureMeasurement.attributes.CurrentTemperature.ID] = temperature_handler | ||
| } | ||
| } | ||
| }, | ||
| lifecycle_handlers = { | ||
| init = device_init, | ||
| added = added_handler | ||
| }, | ||
| can_handle = is_chameleon_ct_clamp | ||
| } | ||
|
|
||
| return ct_clamp_battery_temperature_handler | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changes to this file should be omitted