-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sihas energy monitor for wwst (#578)
* wwst(sihas_energy) * Fix indents * Change electrical divisor units from 1000 to 1 * Device profile and other changes 1. Adding power-meter-consumption-report-sihas 2. powerConsumptionReport should be updated every 15 minutes. 3. Applying ENERGY_METER_OFFSET value. * Add variable declaration Add variable declaration * Deleting unnecessary variables Deleting unnecessary variables * update configuration report update configuration report * Convert identation to Spaces . * Changed the decimal point from 5 digits to 3 digits(W) * Modified warning code * Adding some tests for shinasys * Updating tests for shinasys * Update init.lua Removed unnecessary calculation (math.floor). * Removed lines with only whitespace * Update test_zigbee_power_meter_consumption_report_sihas.lua Update test code for powerConsumptionReport * Update test_zigbee_power_meter_consumption_report_sihas.lua
- Loading branch information
Showing
4 changed files
with
268 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
drivers/SmartThings/zigbee-power-meter/profiles/power-meter-consumption-report-sihas.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
name: power-meter-consumption-report-sihas | ||
components: | ||
- id: main | ||
capabilities: | ||
- id: powerMeter | ||
version: 1 | ||
- id: energyMeter | ||
version: 1 | ||
- id: powerConsumptionReport | ||
version: 1 | ||
- id: firmwareUpdate | ||
version: 1 | ||
- id: refresh | ||
version: 1 | ||
categories: | ||
- name: CurbPowerMeter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
...rtThings/zigbee-power-meter/src/test/test_zigbee_power_meter_consumption_report_sihas.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
-- Copyright 2022 SmartThings | ||
-- | ||
-- Licensed under the Apache License, Version 2.0 (the "License"); | ||
-- you may not use this file except in compliance with the License. | ||
-- You may obtain a copy of the License at | ||
-- | ||
-- http://www.apache.org/licenses/LICENSE-2.0 | ||
-- | ||
-- Unless required by applicable law or agreed to in writing, software | ||
-- distributed under the License is distributed on an "AS IS" BASIS, | ||
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
-- See the License for the specific language governing permissions and | ||
-- limitations under the License. | ||
|
||
-- Mock out globals | ||
local test = require "integration_test" | ||
local clusters = require "st.zigbee.zcl.clusters" | ||
local ElectricalMeasurement = clusters.ElectricalMeasurement | ||
local SimpleMetering = clusters.SimpleMetering | ||
local capabilities = require "st.capabilities" | ||
local zigbee_test_utils = require "integration_test.zigbee_test_utils" | ||
local t_utils = require "integration_test.utils" | ||
|
||
local mock_device = test.mock_device.build_test_zigbee_device( | ||
{ | ||
profile = t_utils.get_profile_definition("power-meter-consumption-report-sihas.yml"), | ||
zigbee_endpoints = { | ||
[1] = { | ||
id = 1, | ||
model = "PMM-300Z2", | ||
server_clusters = {SimpleMetering.ID, ElectricalMeasurement.ID} | ||
} | ||
} | ||
} | ||
) | ||
|
||
zigbee_test_utils.prepare_zigbee_env_info() | ||
local function test_init() | ||
test.mock_device.add_test_device(mock_device) | ||
zigbee_test_utils.init_noop_health_check_timer() | ||
end | ||
|
||
test.set_test_init_function(test_init) | ||
|
||
test.register_message_test( | ||
"ActivePower Report should be handled. Sensor value is in W, capability attribute value is in hectowatts", | ||
{ | ||
{ | ||
channel = "zigbee", | ||
direction = "receive", | ||
message = { mock_device.id, ElectricalMeasurement.attributes.ACPowerDivisor:build_test_attr_report(mock_device, 0x01) } | ||
}, | ||
{ | ||
channel = "zigbee", | ||
direction = "receive", | ||
message = { mock_device.id, ElectricalMeasurement.attributes.ActivePower:build_test_attr_report(mock_device, | ||
27) }, | ||
}, | ||
{ | ||
channel = "capability", | ||
direction = "send", | ||
message = mock_device:generate_test_message("main", capabilities.powerMeter.power({ value = 27.0, unit = "W" })) | ||
} | ||
} | ||
) | ||
|
||
test.register_coroutine_test( | ||
"SimpleMetering event should be handled by powerConsumptionReport capability", | ||
function() | ||
test.timer.__create_and_queue_test_time_advance_timer(15*60, "oneshot") | ||
-- #1 : 15 minutes have passed | ||
test.mock_time.advance_time(15*60) | ||
test.socket.zigbee:__queue_receive({ | ||
mock_device.id, | ||
SimpleMetering.attributes.CurrentSummationDelivered:build_test_attr_report(mock_device,1500) | ||
}) | ||
test.socket.capability:__expect_send( | ||
mock_device:generate_test_message("main", capabilities.powerConsumptionReport.powerConsumption({energy = 1500.0, deltaEnergy = 0.0 })) | ||
) | ||
test.socket.capability:__expect_send( | ||
mock_device:generate_test_message("main", capabilities.energyMeter.energy({value = 1.5, unit = "kWh"})) | ||
) | ||
-- #2 : Not even 15 minutes passed | ||
test.wait_for_events() | ||
test.mock_time.advance_time(1*60) | ||
test.socket.zigbee:__queue_receive({ | ||
mock_device.id, | ||
SimpleMetering.attributes.CurrentSummationDelivered:build_test_attr_report(mock_device,1700) | ||
}) | ||
test.socket.capability:__expect_send( | ||
mock_device:generate_test_message("main", capabilities.energyMeter.energy({value = 1.7, unit = "kWh"})) | ||
) | ||
-- #3 : 15 minutes have passed | ||
test.wait_for_events() | ||
test.mock_time.advance_time(14*60) | ||
test.socket.zigbee:__queue_receive({ | ||
mock_device.id, | ||
SimpleMetering.attributes.CurrentSummationDelivered:build_test_attr_report(mock_device,2000) | ||
}) | ||
test.socket.capability:__expect_send( | ||
mock_device:generate_test_message("main", capabilities.powerConsumptionReport.powerConsumption({energy = 2000.0, deltaEnergy = 500.0 })) | ||
) | ||
test.socket.capability:__expect_send( | ||
mock_device:generate_test_message("main", capabilities.energyMeter.energy({value = 2.0, unit = "kWh"})) | ||
) | ||
end | ||
) | ||
|
||
test.register_coroutine_test( | ||
"lifecycle configure event should configure device", | ||
function () | ||
test.socket.zigbee:__set_channel_ordering("relaxed") | ||
test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" }) | ||
test.socket.zigbee:__expect_send({ | ||
mock_device.id, | ||
SimpleMetering.attributes.InstantaneousDemand:read(mock_device) | ||
}) | ||
test.socket.zigbee:__expect_send({ | ||
mock_device.id, | ||
SimpleMetering.attributes.CurrentSummationDelivered:read(mock_device) | ||
}) | ||
test.socket.zigbee:__expect_send({ | ||
mock_device.id, | ||
ElectricalMeasurement.attributes.ActivePower:read(mock_device) | ||
}) | ||
test.socket.zigbee:__expect_send({ | ||
mock_device.id, | ||
zigbee_test_utils.build_bind_request(mock_device, | ||
zigbee_test_utils.mock_hub_eui, | ||
SimpleMetering.ID) | ||
}) | ||
test.socket.zigbee:__expect_send({ | ||
mock_device.id, | ||
SimpleMetering.attributes.InstantaneousDemand:configure_reporting(mock_device, 5, 300, 1) | ||
}) | ||
test.socket.zigbee:__expect_send({ | ||
mock_device.id, | ||
SimpleMetering.attributes.CurrentSummationDelivered:configure_reporting(mock_device, 5, 300, 1) | ||
}) | ||
test.socket.zigbee:__expect_send({ | ||
mock_device.id, | ||
zigbee_test_utils.build_bind_request(mock_device, | ||
zigbee_test_utils.mock_hub_eui, | ||
ElectricalMeasurement.ID) | ||
}) | ||
test.socket.zigbee:__expect_send({ | ||
mock_device.id, | ||
ElectricalMeasurement.attributes.ActivePower:configure_reporting(mock_device, 0, 65535, 1) | ||
}) | ||
mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" }) | ||
end | ||
) | ||
|
||
test.run_registered_tests() |