Compare commits
39 Commits
Author | SHA1 | Date | |
---|---|---|---|
b51f1f18c9 | |||
f4aa690038 | |||
ff65760628 | |||
17ba628d0b | |||
a7fe9d7279 | |||
b5e7d81d28 | |||
35aadc09cf | |||
af7eeeaf15 | |||
c47895e6bb | |||
3a19253230 | |||
58f467a591 | |||
52bb4bcea7 | |||
3760f36e9f | |||
05cbcdf2dc | |||
dd4cc7635c | |||
bf49abfd44 | |||
566f840012 | |||
d1a8fa449b | |||
1da54f7416 | |||
eb4783c11e | |||
c06d910356 | |||
02871e4d66 | |||
edb59f01b6 | |||
ce30132f5f | |||
64c9020bcb | |||
a22628b0d0 | |||
64d74668cc | |||
e53529b9d4 | |||
ca399a405c | |||
a931ed15f0 | |||
ff35791819 | |||
6bce798689 | |||
317ae9b682 | |||
b5e0c70b1e | |||
bd01c5df3f | |||
8dd8605d73 | |||
beea6c1ee0 | |||
1082ee0d2a | |||
6d395107cb |
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
/.vs
|
||||
/Zway/bin
|
||||
/Zway/obj
|
||||
/packages
|
182
CHANGELOG.md
Normal file
182
CHANGELOG.md
Normal file
@ -0,0 +1,182 @@
|
||||
# Changelog
|
||||
|
||||
## 1.6.1 - 2022-01-20 - Dispose bug in netcore
|
||||
### New Features
|
||||
### Bugfixes
|
||||
* Remove Thread.Abort, cause it's not support in netcore
|
||||
### Changes
|
||||
|
||||
## 1.6.0 - 2022-01-15 - Refactoring is the key
|
||||
### New Features
|
||||
* Using C# 9 Language features now
|
||||
* Add Readme, Contribute and Changelog
|
||||
### Bugfixes
|
||||
### Changes
|
||||
* Modify the HttpClient lib, as it now using the Utility one
|
||||
* Split the ZwayController and move parts to the zway Subclass
|
||||
* Rewrite the names.ini so that only the commandclass is used for names
|
||||
* Codingstyle
|
||||
* Remove Binarys from code
|
||||
* Move project to netcore
|
||||
* Remove the HelperClass and use the one from Utils
|
||||
|
||||
## 1.5.1 - 2018-10-29 - Tiny fix for nullpointer exception
|
||||
### New Features
|
||||
### Bugfixes
|
||||
* Avoid nullpointerexception
|
||||
### Changes
|
||||
|
||||
## 1.5.0 - 2018-09-29 - Throw Exception if 3 times failed to connect to Raspberry server, add 3 new commandlcasses to IgnoredClasses
|
||||
### New Features
|
||||
* Add classes to IgnoreClasses
|
||||
* If a request failed, try again 3 times and then throw the exception to the next level
|
||||
* Catch all data from the time of the last request and calculate backwards.
|
||||
### Bugfixes
|
||||
* Try to fix connectionlost with HttpConnection Class
|
||||
### Changes
|
||||
* Codingstyle
|
||||
|
||||
## 1.4.4 - 2018-06-02 - Ignore Inclusioncontroller
|
||||
### New Features
|
||||
* Add classes to IgnoreClasses
|
||||
### Bugfixes
|
||||
### Changes
|
||||
|
||||
## 1.4.3 - 2018-05-12 - Fixing Issue with Math.Abs(l)
|
||||
### New Features
|
||||
* Add classes to IgnoreClasses
|
||||
### Bugfixes
|
||||
* Using Math.Abs correctly
|
||||
### Changes
|
||||
|
||||
## 1.4.2.0 - 2018-05-10 - Some sensors make wrong measurements near 0 not exactly 0, so ABS(value) >= 0.1 is alse false
|
||||
### New Features
|
||||
* SensorMultilevelSub now can return Lux in Senml
|
||||
* Add classes to IgnoreClasses
|
||||
### Bugfixes
|
||||
* Fixing Senml topic
|
||||
* fixing filter so its not exactly needs 0 for temperatur
|
||||
### Changes
|
||||
|
||||
## 1.4.1.0 - 2018-05-07 - fixing Senml topics and data
|
||||
### New Features
|
||||
### Bugfixes
|
||||
* Fixing Senml topic
|
||||
### Changes
|
||||
|
||||
## 1.4.0.0 - 2018-05-03 - Create Senml Messages for Linksmart
|
||||
### New Features
|
||||
* Add classes to IgnoreClasses
|
||||
* Add Senml output
|
||||
### Bugfixes
|
||||
### Changes
|
||||
* Refactoring
|
||||
|
||||
## 1.3.6.0 - 2018-01-01 - Better levelcheck and Alarmsensor added
|
||||
### New Features
|
||||
* Add CommandClasses AlarmSensor
|
||||
* Remove classes from IgnoreClasses
|
||||
* Add a filter if temperature is near zero and drops rapetly to exact 0
|
||||
### Bugfixes
|
||||
### Changes
|
||||
|
||||
## 1.3.5.3 - 2017-12-25 - Change Level to numeric and create State for Bollean values, because telegraf only parse numeric
|
||||
### New Features
|
||||
* Boolean levels also returned as Int in Json
|
||||
### Bugfixes
|
||||
### Changes
|
||||
|
||||
## 1.3.5.2 - 2017-12-24 - Check to avoid megapeaks in data now also for temperature
|
||||
### New Features
|
||||
* Add a filter for temperature also (if > 50 or < -20 its ignored)
|
||||
### Bugfixes
|
||||
### Changes
|
||||
|
||||
## 1.3.5.1 - 2017-12-23 - Check to avoid megapeaks in Data
|
||||
### New Features
|
||||
* Add a filter for to high values (if W < 3660 its ignored)
|
||||
### Bugfixes
|
||||
### Changes
|
||||
|
||||
## 1.3.5.0 - 2017-12-22 - Add Alarm and SceneControllerConf
|
||||
### New Features
|
||||
* Add CommandClasses Alarm, SceneControllerConf
|
||||
* Add classes to IgnoreClasses
|
||||
### Bugfixes
|
||||
* Avoid nullpointer Exception
|
||||
### Changes
|
||||
|
||||
## 1.3.4.1 - 2017-12-21 - SensorBinary and Fixing
|
||||
### New Features
|
||||
* Add CommandClasses SensorBinary
|
||||
### Bugfixes
|
||||
### Changes
|
||||
* Json Names are now with a Capital letter
|
||||
|
||||
## 1.3.4.0 - 2017-12-19 - Fixing Json Names
|
||||
### New Features
|
||||
### Bugfixes
|
||||
### Changes
|
||||
* Json Names are now with a Capital letter
|
||||
|
||||
## 1.3.3.0 - 2017-12-19 - fixing polling once bug
|
||||
### New Features
|
||||
### Bugfixes
|
||||
* Poll Once was not used
|
||||
### Changes
|
||||
|
||||
## 1.3.2.0 - 2017-12-18 - Forgot some settings, now configuration setting also works again
|
||||
### New Features
|
||||
### Bugfixes
|
||||
* Using Abstract Methods not the Api directly
|
||||
### Changes
|
||||
* Using Int -> Double Cast
|
||||
|
||||
## 1.3.1.0 - 2017-12-17 - Tiny fix for mqtt
|
||||
### New Features
|
||||
### Bugfixes
|
||||
* Using Double instead of Single
|
||||
### Changes
|
||||
|
||||
## 1.3.0.0 - 2017-12-17 - Simpler CommandClass
|
||||
### New Features
|
||||
* Using ACommandClass
|
||||
### Bugfixes
|
||||
### Changes
|
||||
* Refactoring CommandClass, Merge CommandClass and CommandClassSub and Put parts to abstract ACommandClass.
|
||||
* Delete ICommandClass
|
||||
|
||||
# 1.2.0.0 - 2017-12-06 - F4G Faker
|
||||
### New Features
|
||||
* When trigger the update event, pass the class itself also
|
||||
### Bugfixes
|
||||
### Changes
|
||||
|
||||
# 1.1.2.0 - 2017-12-03 - Tiny Fix
|
||||
### New Features
|
||||
### Bugfixes
|
||||
* Meter Class public, so it cann be accessed
|
||||
### Changes
|
||||
|
||||
# 1.1.1.0 - 2017-11-25 - Massive improvement
|
||||
### New Features
|
||||
* Create Interface CommandClass
|
||||
* Add CommandClasses Configuration
|
||||
### Bugfixes
|
||||
### Changes
|
||||
* Refactoring the complete code
|
||||
|
||||
# 1.1.0.0 - 2017-11-20 - First working Version
|
||||
### New Features
|
||||
* Create structure for returned data from api (Devices/Instances/CommandClasses)
|
||||
* Create Pollingthreads
|
||||
* Improve HttpClient
|
||||
* Add CommandClasses Battery, CentralScene, Meter, SensorMultilevel, ThermostatSetPoint, Indicator, SwitchBinary, SwitchMultilevel, ThermostatMode, Wakeup
|
||||
### Bugfixes
|
||||
### Changes
|
||||
|
||||
## 1.0.0.0 - 2017-10-29 - Init
|
||||
### New Features
|
||||
* First release
|
||||
### Bugfixes
|
||||
### Changes
|
92
CONTRIBUTING.md
Normal file
92
CONTRIBUTING.md
Normal file
@ -0,0 +1,92 @@
|
||||
# Contributing
|
||||
|
||||
When contributing to this repository, please first discuss the change you wish to make via issue,
|
||||
email, or any other method with the owners of this repository before making a change.
|
||||
|
||||
Please note we have a code of conduct, please follow it in all your interactions with the project.
|
||||
|
||||
## Pull Request Process
|
||||
|
||||
1. Ensure any install or build dependencies are removed before the end of the layer when doing a
|
||||
build.
|
||||
2. Update the README.md with details of changes to the interface, this includes new environment
|
||||
variables, exposed ports, useful file locations and container parameters.
|
||||
3. Increase the version numbers in any examples files and the README.md to the new version that this
|
||||
Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
|
||||
4. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
|
||||
do not have permission to do that, you may request the second reviewer to merge it for you.
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
### Our Pledge
|
||||
|
||||
In the interest of fostering an open and welcoming environment, we as
|
||||
contributors and maintainers pledge to making participation in our project and
|
||||
our community a harassment-free experience for everyone, regardless of age, body
|
||||
size, disability, ethnicity, gender identity and expression, level of experience,
|
||||
nationality, personal appearance, race, religion, or sexual identity and
|
||||
orientation.
|
||||
|
||||
### Our Standards
|
||||
|
||||
Examples of behavior that contributes to creating a positive environment
|
||||
include:
|
||||
|
||||
* Using welcoming and inclusive language
|
||||
* Being respectful of differing viewpoints and experiences
|
||||
* Gracefully accepting constructive criticism
|
||||
* Focusing on what is best for the community
|
||||
* Showing empathy towards other community members
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery and unwelcome sexual attention or
|
||||
advances
|
||||
* Trolling, insulting/derogatory comments, and personal or political attacks
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as a physical or electronic
|
||||
address, without explicit permission
|
||||
* Other conduct which could reasonably be considered inappropriate in a
|
||||
professional setting
|
||||
|
||||
### Our Responsibilities
|
||||
|
||||
Project maintainers are responsible for clarifying the standards of acceptable
|
||||
behavior and are expected to take appropriate and fair corrective action in
|
||||
response to any instances of unacceptable behavior.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct, or to ban temporarily or
|
||||
permanently any contributor for other behaviors that they deem inappropriate,
|
||||
threatening, offensive, or harmful.
|
||||
|
||||
### Scope
|
||||
|
||||
This Code of Conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community. Examples of
|
||||
representing a project or community include using an official project e-mail
|
||||
address, posting via an official social media account, or acting as an appointed
|
||||
representative at an online or offline event. Representation of a project may be
|
||||
further defined and clarified by project maintainers.
|
||||
|
||||
### Enforcement
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting the project team at git ATTTT blubbfish.net. All
|
||||
complaints will be reviewed and investigated and will result in a response that
|
||||
is deemed necessary and appropriate to the circumstances. The project team is
|
||||
obligated to maintain confidentiality with regard to the reporter of an incident.
|
||||
Further details of specific enforcement policies may be posted separately.
|
||||
|
||||
Project maintainers who do not follow or enforce the Code of Conduct in good
|
||||
faith may face temporary or permanent repercussions as determined by other
|
||||
members of the project's leadership.
|
||||
|
||||
### Attribution
|
||||
|
||||
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
||||
available at [http://contributor-covenant.org/version/1/4][version]
|
||||
|
||||
[homepage]: http://contributor-covenant.org
|
||||
[version]: http://contributor-covenant.org/version/1/4/
|
165
LICENSE
Normal file
165
LICENSE
Normal file
@ -0,0 +1,165 @@
|
||||
GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates
|
||||
the terms and conditions of version 3 of the GNU General Public
|
||||
License, supplemented by the additional permissions listed below.
|
||||
|
||||
0. Additional Definitions.
|
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
||||
General Public License.
|
||||
|
||||
"The Library" refers to a covered work governed by this License,
|
||||
other than an Application or a Combined Work as defined below.
|
||||
|
||||
An "Application" is any work that makes use of an interface provided
|
||||
by the Library, but which is not otherwise based on the Library.
|
||||
Defining a subclass of a class defined by the Library is deemed a mode
|
||||
of using an interface provided by the Library.
|
||||
|
||||
A "Combined Work" is a work produced by combining or linking an
|
||||
Application with the Library. The particular version of the Library
|
||||
with which the Combined Work was made is also called the "Linked
|
||||
Version".
|
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the
|
||||
Corresponding Source for the Combined Work, excluding any source code
|
||||
for portions of the Combined Work that, considered in isolation, are
|
||||
based on the Application, and not on the Linked Version.
|
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the
|
||||
object code and/or source code for the Application, including any data
|
||||
and utility programs needed for reproducing the Combined Work from the
|
||||
Application, but excluding the System Libraries of the Combined Work.
|
||||
|
||||
1. Exception to Section 3 of the GNU GPL.
|
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License
|
||||
without being bound by section 3 of the GNU GPL.
|
||||
|
||||
2. Conveying Modified Versions.
|
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a
|
||||
facility refers to a function or data to be supplied by an Application
|
||||
that uses the facility (other than as an argument passed when the
|
||||
facility is invoked), then you may convey a copy of the modified
|
||||
version:
|
||||
|
||||
a) under this License, provided that you make a good faith effort to
|
||||
ensure that, in the event an Application does not supply the
|
||||
function or data, the facility still operates, and performs
|
||||
whatever part of its purpose remains meaningful, or
|
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of
|
||||
this License applicable to that copy.
|
||||
|
||||
3. Object Code Incorporating Material from Library Header Files.
|
||||
|
||||
The object code form of an Application may incorporate material from
|
||||
a header file that is part of the Library. You may convey such object
|
||||
code under terms of your choice, provided that, if the incorporated
|
||||
material is not limited to numerical parameters, data structure
|
||||
layouts and accessors, or small macros, inline functions and templates
|
||||
(ten or fewer lines in length), you do both of the following:
|
||||
|
||||
a) Give prominent notice with each copy of the object code that the
|
||||
Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
4. Combined Works.
|
||||
|
||||
You may convey a Combined Work under terms of your choice that,
|
||||
taken together, effectively do not restrict modification of the
|
||||
portions of the Library contained in the Combined Work and reverse
|
||||
engineering for debugging such modifications, if you also do each of
|
||||
the following:
|
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that
|
||||
the Library is used in it and that the Library and its use are
|
||||
covered by this License.
|
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
||||
document.
|
||||
|
||||
c) For a Combined Work that displays copyright notices during
|
||||
execution, include the copyright notice for the Library among
|
||||
these notices, as well as a reference directing the user to the
|
||||
copies of the GNU GPL and this license document.
|
||||
|
||||
d) Do one of the following:
|
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this
|
||||
License, and the Corresponding Application Code in a form
|
||||
suitable for, and under terms that permit, the user to
|
||||
recombine or relink the Application with a modified version of
|
||||
the Linked Version to produce a modified Combined Work, in the
|
||||
manner specified by section 6 of the GNU GPL for conveying
|
||||
Corresponding Source.
|
||||
|
||||
1) Use a suitable shared library mechanism for linking with the
|
||||
Library. A suitable mechanism is one that (a) uses at run time
|
||||
a copy of the Library already present on the user's computer
|
||||
system, and (b) will operate properly with a modified version
|
||||
of the Library that is interface-compatible with the Linked
|
||||
Version.
|
||||
|
||||
e) Provide Installation Information, but only if you would otherwise
|
||||
be required to provide such information under section 6 of the
|
||||
GNU GPL, and only to the extent that such information is
|
||||
necessary to install and execute a modified version of the
|
||||
Combined Work produced by recombining or relinking the
|
||||
Application with a modified version of the Linked Version. (If
|
||||
you use option 4d0, the Installation Information must accompany
|
||||
the Minimal Corresponding Source and Corresponding Application
|
||||
Code. If you use option 4d1, you must provide the Installation
|
||||
Information in the manner specified by section 6 of the GNU GPL
|
||||
for conveying Corresponding Source.)
|
||||
|
||||
5. Combined Libraries.
|
||||
|
||||
You may place library facilities that are a work based on the
|
||||
Library side by side in a single library together with other library
|
||||
facilities that are not Applications and are not covered by this
|
||||
License, and convey such a combined library under terms of your
|
||||
choice, if you do both of the following:
|
||||
|
||||
a) Accompany the combined library with a copy of the same work based
|
||||
on the Library, uncombined with any other library facilities,
|
||||
conveyed under the terms of this License.
|
||||
|
||||
b) Give prominent notice with the combined library that part of it
|
||||
is a work based on the Library, and explaining where to find the
|
||||
accompanying uncombined form of the same work.
|
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions
|
||||
of the GNU Lesser General Public License from time to time. Such new
|
||||
versions will be similar in spirit to the present version, but may
|
||||
differ in detail to address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Library as you received it specifies that a certain numbered version
|
||||
of the GNU Lesser General Public License "or any later version"
|
||||
applies to it, you have the option of following the terms and
|
||||
conditions either of that published version or of any later version
|
||||
published by the Free Software Foundation. If the Library as you
|
||||
received it does not specify a version number of the GNU Lesser
|
||||
General Public License, you may choose any version of the GNU Lesser
|
||||
General Public License ever published by the Free Software Foundation.
|
||||
|
||||
If the Library as you received it specifies that a proxy can decide
|
||||
whether future versions of the GNU Lesser General Public License shall
|
||||
apply, that proxy's public statement of acceptance of any version is
|
||||
permanent authorization for you to choose that version for the
|
||||
Library.
|
50
README.md
Normal file
50
README.md
Normal file
@ -0,0 +1,50 @@
|
||||
# BlubbFish.IoT.Zway (Zway)
|
||||
<!-- Short description of the project. -->
|
||||
|
||||
Library that connects to a zway controller device and recieves crawls zwave data. This library contains drivers for a Zwave.me installation. This readme is meant for describing the software library.
|
||||
|
||||
This library is running on every hardware that supports dotnet.
|
||||
|
||||
<!-- A teaser figure may be added here. It is best to keep the figure small (<500KB) and in the same repo -->
|
||||
|
||||
## Getting Started
|
||||
<!-- Instruction to make the project up and running. -->
|
||||
|
||||
The project documentation is available on the [Wiki](https://git.blubbfish.net/vs_projects/Zway/wiki).
|
||||
|
||||
## Usage
|
||||
<!-- Deployment/Installation instructions. If this is software library, change this section to "Usage" and give usage examples -->
|
||||
This software can not run itselfs, cause its a library.
|
||||
|
||||
## Development
|
||||
<!-- Developer instructions. -->
|
||||
* Versioning: Use [SemVer](http://semver.org/) and tag the repository with full version string. E.g. `v1.0.0`
|
||||
|
||||
### Copyright
|
||||
|
||||
This library is under GNU LESSER GENERAL PUBLIC LICENSE Version 3
|
||||
|
||||
### Prerequisite
|
||||
|
||||
If you want to work with this library, please checkout [zway-project](https://git.blubbfish.net/vs/zway-project) with all submodules, to get all dependencies.
|
||||
|
||||
#### Internal
|
||||
* BlubbFish.Utils ([Utils](http://git.blubbfish.net/vs_utils/Utils))
|
||||
* BlubbFish.Utils.IoT.Interfaces ([Iot-Interfaces](http://git.blubbfish.net/vs_utils/Iot-Interfaces))
|
||||
|
||||
#### External
|
||||
* litjson ([Used Fork](https://github.com/blubbfish/litjson), [Original](https://github.com/LitJSON/litjson))
|
||||
|
||||
### Test
|
||||
|
||||
You need to compile he library and use it with a calling agent.
|
||||
|
||||
### Build
|
||||
|
||||
Build it with Visual Studio.
|
||||
|
||||
## Contributing
|
||||
Contributions are welcome.
|
||||
|
||||
Please fork, make your changes, and submit a pull request. For major changes, please open an issue first and discuss it with the other authors.
|
||||
|
34
Zway.sln
34
Zway.sln
@ -1,9 +1,15 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.16
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29806.167
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zway", "Zway\Zway.csproj", "{166258ED-CB3D-43F5-8E8D-3A993B64D022}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Zway", "Zway\Zway.csproj", "{5D565E5E-D1E0-44A3-9817-1AEC07BC2564}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "litjson", "..\Librarys\litjson\litjson\litjson.csproj", "{5FD215BB-458C-462E-A06B-590EFCC559D3}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Iot-Interfaces", "..\Utils\Iot-Interfaces\Iot-Interfaces\Iot-Interfaces.csproj", "{49CE9A50-BBBD-4744-8D7A-CA46D4A6C3F2}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Utils", "..\Utils\Utils\Utils\Utils.csproj", "{7B542A96-636E-4A3C-8528-821EAB734266}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -11,15 +17,27 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{166258ED-CB3D-43F5-8E8D-3A993B64D022}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{166258ED-CB3D-43F5-8E8D-3A993B64D022}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{166258ED-CB3D-43F5-8E8D-3A993B64D022}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{166258ED-CB3D-43F5-8E8D-3A993B64D022}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5D565E5E-D1E0-44A3-9817-1AEC07BC2564}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5D565E5E-D1E0-44A3-9817-1AEC07BC2564}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5D565E5E-D1E0-44A3-9817-1AEC07BC2564}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5D565E5E-D1E0-44A3-9817-1AEC07BC2564}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{5FD215BB-458C-462E-A06B-590EFCC559D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{5FD215BB-458C-462E-A06B-590EFCC559D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5FD215BB-458C-462E-A06B-590EFCC559D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5FD215BB-458C-462E-A06B-590EFCC559D3}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{49CE9A50-BBBD-4744-8D7A-CA46D4A6C3F2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{49CE9A50-BBBD-4744-8D7A-CA46D4A6C3F2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{49CE9A50-BBBD-4744-8D7A-CA46D4A6C3F2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{49CE9A50-BBBD-4744-8D7A-CA46D4A6C3F2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7B542A96-636E-4A3C-8528-821EAB734266}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7B542A96-636E-4A3C-8528-821EAB734266}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7B542A96-636E-4A3C-8528-821EAB734266}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7B542A96-636E-4A3C-8528-821EAB734266}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {2F3A172A-4D52-4191-A84A-675D35B4A292}
|
||||
SolutionGuid = {06743A84-28DD-482E-996D-AA5511FE908F}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -1,59 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
/// <summary>
|
||||
/// 135 = Indicator
|
||||
/// 113 = Alarm
|
||||
/// </summary>
|
||||
class Alarm : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Unklar
|
||||
/// </summary>
|
||||
public Int32 Level { get; private set; }
|
||||
public Int32 AlarmType { get; private set; }
|
||||
/// <summary>
|
||||
/// unklar
|
||||
/// </summary>
|
||||
public String AlarmType { get; private set; }
|
||||
#endregion
|
||||
|
||||
public Alarm(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
this.InitComplex(json);
|
||||
}
|
||||
#region Constructor
|
||||
public Alarm(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) => this.InitComplex(json);
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data") && json["data"].Keys.Contains("V1event") &&
|
||||
json["data"]["V1event"].Keys.Contains("alarmType") && json["data"]["V1event"]["alarmType"].Keys.Contains("value") &&
|
||||
json["data"]["V1event"].Keys.Contains("level") && json["data"]["V1event"]["level"].Keys.Contains("value")) {
|
||||
this.AlarmType = Int32.Parse(json["data"]["V1event"]["alarmType"]["value"].ToString());
|
||||
this.Level = Int32.Parse(json["data"]["V1event"]["level"]["value"].ToString());
|
||||
if(json.ContainsKey("data") &&
|
||||
json["data"].ContainsKey("V1event") &&
|
||||
json["data"].ContainsKey("V1supported") &&
|
||||
json["data"]["V1supported"].ContainsKey("type") &&
|
||||
json["data"]["V1supported"]["type"].ToString() == "bool" &&
|
||||
(Boolean)json["data"]["V1supported"]["value"]) {
|
||||
if(json["data"]["V1event"].ContainsKey("alarmType") &&
|
||||
json["data"]["V1event"]["alarmType"].ContainsKey("value") &&
|
||||
json["data"]["V1event"]["alarmType"]["value"] != null &&
|
||||
json["data"]["V1event"]["alarmType"]["value"].IsInt) {
|
||||
this.AlarmType = json["data"]["V1event"]["alarmType"]["value"].ToString();
|
||||
}
|
||||
if(json["data"]["V1event"].ContainsKey("level") &&
|
||||
json["data"]["V1event"]["level"].ContainsKey("value") &&
|
||||
json["data"]["V1event"]["level"]["value"] != null &&
|
||||
json["data"]["V1event"]["level"]["value"].IsInt) {
|
||||
this.Level = Int32.Parse(json["data"]["V1event"]["level"]["value"].ToString());
|
||||
}
|
||||
} else if(json.ContainsKey("data") && json["data"].IsObject &&
|
||||
json["data"].ContainsKey("8") && json["data"]["8"].IsObject) {
|
||||
if(json["data"]["8"].ContainsKey("typeString") && json["data"]["8"]["typeString"].IsObject &&
|
||||
json["data"]["8"]["typeString"].ContainsKey("value") && json["data"]["8"]["typeString"]["value"] != null && json["data"]["8"]["typeString"]["value"].IsString) {
|
||||
this.AlarmType = json["data"]["8"]["typeString"]["value"].ToString();
|
||||
}
|
||||
if(json["data"]["8"].ContainsKey("status") && json["data"]["8"]["status"].IsObject &&
|
||||
json["data"]["8"]["status"].ContainsKey("value") && json["data"]["8"]["status"]["value"] != null && json["data"]["8"]["status"]["value"].IsInt) {
|
||||
this.Level = Int32.Parse(json["data"]["8"]["status"]["value"].ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
public override String ToString() => "Alarm " + this.Name + " [" + this.Id + "]: " + this.AlarmType + " " + this.Level;
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => new Dictionary<String, Object> {
|
||||
{ "AlarmType", this.AlarmType },
|
||||
{ "Level", this.Level },
|
||||
};
|
||||
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if(match.Groups[4].Value == ".data.V1event") {
|
||||
if (json.Keys.Contains("alarmType") && json["alarmType"].Keys.Contains("value") &&
|
||||
if(json.Keys.Contains("alarmType") && json["alarmType"].Keys.Contains("value") &&
|
||||
json.Keys.Contains("level") && json["level"].Keys.Contains("value") &&
|
||||
this.CheckSetUpdateTime(json)) {
|
||||
this.AlarmType = Int32.Parse(json["alarmType"]["value"].ToString());
|
||||
this.AlarmType = json["alarmType"]["value"].ToString();
|
||||
this.Level = Int32.Parse(json["level"]["value"].ToString());
|
||||
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<Int32, Int32>(this.AlarmType, this.Level), this.LastUpdate, this));
|
||||
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<String, Int32>(this.AlarmType, this.Level), this.LastUpdate, this));
|
||||
}
|
||||
} else if(match.Groups[4].Value == ".data.8") {
|
||||
if(json.ContainsKey("typeString") && json["typeString"].IsObject &&
|
||||
json["typeString"].ContainsKey("value") && json["typeString"]["value"] != null && json["typeString"]["value"].IsString &&
|
||||
json.ContainsKey("status") && json["status"].IsObject &&
|
||||
json["status"].ContainsKey("value") && json["status"]["value"] != null && json["status"]["value"].IsInt &&
|
||||
this.CheckSetUpdateTime(json)) {
|
||||
this.AlarmType = json["typeString"]["value"].ToString();
|
||||
this.Level = Int32.Parse(json["status"]["value"].ToString());
|
||||
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<String, Int32>(this.AlarmType, this.Level), this.LastUpdate, this));
|
||||
}
|
||||
} else {
|
||||
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||
}
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
return "Alarm " + this.Name + " [" + this.Id + "]: " + this.AlarmType + " " + this.Level;
|
||||
}
|
||||
|
||||
internal override void Poll() => this.PollNone();
|
||||
#endregion
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "AlarmType", this.AlarmType },
|
||||
{ "Level", this.Level },
|
||||
};
|
||||
}
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => new List<Senml>() { };
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
72
Zway/Devices/CommandClasses/AlarmSensor.cs
Normal file
72
Zway/Devices/CommandClasses/AlarmSensor.cs
Normal file
@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
/// <summary>
|
||||
/// 50 = Meter
|
||||
/// </summary>
|
||||
public class Alarmsensor : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
#region Constructor
|
||||
public Alarmsensor(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.HasSub = true;
|
||||
this.InitComplex(json, name);
|
||||
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
|
||||
item.Value.Update += this.DeviceUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json, (String device, ReadOnlyDictionary<String, String> descriptions) name) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
JsonData data = json["data"];
|
||||
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
|
||||
foreach (String item in data.Keys) {
|
||||
if (Int32.TryParse(item, out Int32 subid) &&
|
||||
data[item].Keys.Contains("srcId") &&
|
||||
data[item].Keys.Contains("sensorState") &&
|
||||
data[item].Keys.Contains("sensorTime") &&
|
||||
data[item].Keys.Contains("typeString")) {
|
||||
subs.Add(subid, new Alarmsensorsub(data[item], (this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling, name));
|
||||
}
|
||||
}
|
||||
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) => this.Update?.Invoke(this, e);
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if (match.Groups[4].Value.StartsWith(".data.")) {
|
||||
Int32 subid = Int32.Parse(match.Groups[5].Value);
|
||||
if (this.Sub.ContainsKey(subid)) {
|
||||
this.Sub[subid].SetUpdate(json, match);
|
||||
}
|
||||
} else {
|
||||
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||
}
|
||||
}
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
|
||||
|
||||
internal override void Poll() => this.PollSubGlobal();
|
||||
#endregion
|
||||
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => this.ToSenmlListSub();
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,9 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
@ -11,15 +16,31 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
/// 128 = Battery
|
||||
/// </summary>
|
||||
public class Battery : ACommandClass {
|
||||
|
||||
public Double Level { get; private set; }
|
||||
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
public Battery(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
this.InitComplex(json);
|
||||
}
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Batterylevel in Percent
|
||||
/// </summary>
|
||||
public Double Level { get; private set; }
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Battery(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) => this.InitComplex(json);
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data") && json["data"].Keys.Contains("last") && json["data"]["last"].Keys.Contains("value")) {
|
||||
this.Level = Double.Parse(json["data"]["last"]["value"].ToString());
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
public override String ToString() => "Battery " + this.Name + " [" + this.Id + "]: " + this.Level;
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => new Dictionary<String, Object> {
|
||||
{ "Level", this.Level },
|
||||
};
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
Boolean success = false;
|
||||
if (match.Groups[4].Value == ".data") {
|
||||
@ -41,21 +62,11 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data") && json["data"].Keys.Contains("last") && json["data"]["last"].Keys.Contains("value")) {
|
||||
this.Level = Double.Parse(json["data"]["last"]["value"].ToString());
|
||||
}
|
||||
}
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => new List<Senml>() { new SenmlDouble("chargelevel", Senml.Units.Percent, this.Level) };
|
||||
#endregion
|
||||
|
||||
public override String ToString() {
|
||||
return "Battery " + this.Name + " [" + this.Id + "]: " + this.Level;
|
||||
}
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "Level", this.Level },
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,9 @@ using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
@ -14,15 +16,68 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
public class Centralscene : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Combination of Scenes and Modes
|
||||
/// </summary>
|
||||
public ReadOnlyDictionary<Int32, ReadOnlyCollection<Int32>> ValidScenesModes { get; private set; }
|
||||
/// <summary>
|
||||
/// Current active Senes
|
||||
/// </summary>
|
||||
public Int32 Scene { get; private set; }
|
||||
/// <summary>
|
||||
/// Current active mode
|
||||
/// </summary>
|
||||
public Int32 Key { get; private set; }
|
||||
#endregion
|
||||
|
||||
public Centralscene(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
#region Constructor
|
||||
public Centralscene(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.ValidScenesModes = new ReadOnlyDictionary<Int32, ReadOnlyCollection<Int32>>(new Dictionary<Int32, ReadOnlyCollection<Int32>>());
|
||||
this.InitComplex(json);
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
JsonData data = json["data"];
|
||||
if (data.Keys.Contains("sceneSupportedKeyAttributesMask")) {
|
||||
Dictionary<Int32, ReadOnlyCollection<Int32>> scenes = new Dictionary<Int32, ReadOnlyCollection<Int32>>();
|
||||
foreach (String item in data["sceneSupportedKeyAttributesMask"].Keys) {
|
||||
if (Int32.TryParse(item, out Int32 mode) &&
|
||||
data["sceneSupportedKeyAttributesMask"][item].Keys.Contains("value") &&
|
||||
data["sceneSupportedKeyAttributesMask"][item]["value"].IsArray) {
|
||||
JsonData values = data["sceneSupportedKeyAttributesMask"][item]["value"];
|
||||
List<Int32> modes = new List<Int32>();
|
||||
foreach (JsonData value in values) {
|
||||
modes.Add(Int32.Parse(value.ToString()));
|
||||
}
|
||||
scenes.Add(mode, new ReadOnlyCollection<Int32>(modes));
|
||||
}
|
||||
}
|
||||
this.ValidScenesModes = new ReadOnlyDictionary<Int32, ReadOnlyCollection<Int32>>(scenes);
|
||||
if (data.Keys.Contains("currentScene") &&
|
||||
data["currentScene"].Keys.Contains("value") &&
|
||||
data["currentScene"]["value"] != null) {
|
||||
this.Scene = Int32.Parse(data["currentScene"]["value"].ToString());
|
||||
}
|
||||
if (data.Keys.Contains("keyAttribute") &&
|
||||
data["keyAttribute"].Keys.Contains("value") &&
|
||||
data["keyAttribute"]["value"] != null) {
|
||||
this.Key = Int32.Parse(data["keyAttribute"]["value"].ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
public override String ToString() => "CentralScene " + this.Name + " [" + this.Id + "]: " + this.Scene + "-" + this.Key;
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => new Dictionary<String, Object> {
|
||||
{ "Scene", this.Scene },
|
||||
{ "Key", this.Key },
|
||||
};
|
||||
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if (match.Groups[4].Value == ".data.currentScene") {
|
||||
if (json.Keys.Contains("value")) {
|
||||
@ -38,49 +93,11 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
}
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
JsonData data = json["data"];
|
||||
if(data.Keys.Contains("sceneSupportedKeyAttributesMask")) {
|
||||
Dictionary<Int32, ReadOnlyCollection<Int32>> scenes = new Dictionary<Int32, ReadOnlyCollection<Int32>>();
|
||||
foreach (String item in data["sceneSupportedKeyAttributesMask"].Keys) {
|
||||
if (Int32.TryParse(item, out Int32 mode) &&
|
||||
data["sceneSupportedKeyAttributesMask"][item].Keys.Contains("value") &&
|
||||
data["sceneSupportedKeyAttributesMask"][item]["value"].IsArray) {
|
||||
JsonData values = data["sceneSupportedKeyAttributesMask"][item]["value"];
|
||||
List<Int32> modes = new List<Int32>();
|
||||
foreach (JsonData value in values) {
|
||||
modes.Add(Int32.Parse(value.ToString()));
|
||||
}
|
||||
scenes.Add(mode, new ReadOnlyCollection<Int32>(modes));
|
||||
}
|
||||
}
|
||||
this.ValidScenesModes = new ReadOnlyDictionary<Int32, ReadOnlyCollection<Int32>>(scenes);
|
||||
if (data.Keys.Contains("currentScene") &&
|
||||
data["currentScene"].Keys.Contains("value") &&
|
||||
data["currentScene"]["value"] != null) {
|
||||
this.Scene = Int32.Parse(data["currentScene"]["value"].ToString());
|
||||
}
|
||||
if (data.Keys.Contains("keyAttribute") &&
|
||||
data["keyAttribute"].Keys.Contains("value") &&
|
||||
data["keyAttribute"]["value"] != null) {
|
||||
this.Key = Int32.Parse(data["keyAttribute"]["value"].ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
return "CentralScene " + this.Name + " [" + this.Id + "]: " + this.Scene+"-"+this.Key;
|
||||
}
|
||||
|
||||
internal override void Poll() => this.PollNone();
|
||||
#endregion
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "Scene", this.Scene },
|
||||
{ "Key", this.Key },
|
||||
};
|
||||
}
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => new List<Senml>() { new SenmlDouble("scene", Senml.Units.CounterValue, this.Scene), new SenmlDouble("key", Senml.Units.CounterValue, this.Key) };
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
public class Alarmsensorsub : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Int32 Source { get; private set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Int32 Level { get; private set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Int32 Time { get; private set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public String Type { get; private set; }
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Alarmsensorsub(JsonData json, (Int32 device, Int32 instance, Classes commandclass, Int32 sensor) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.IsSub = true;
|
||||
this.InitComplex(json);
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("srcId") && json["srcId"].Keys.Contains("value") &&
|
||||
json.Keys.Contains("sensorState") && json["sensorState"].Keys.Contains("value") &&
|
||||
json.Keys.Contains("sensorTime") && json["sensorTime"].Keys.Contains("value") &&
|
||||
json.Keys.Contains("typeString") && json["typeString"].Keys.Contains("value")) {
|
||||
this.Source = Int32.Parse(json["srcId"]["value"].ToString());
|
||||
this.Level = Int32.Parse(json["sensorState"]["value"].ToString());
|
||||
this.Time = Int32.Parse(json["sensorTime"]["value"].ToString());
|
||||
this.Type = json["typeString"]["value"].ToString();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
public override String ToString() => "AlarmSensor " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Source + " " + this.Level + " " + this.Time + " " + this.Type;
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => new Dictionary<String, Object> {
|
||||
{ "Source", this.Source },
|
||||
{ "Level", this.Level },
|
||||
{ "Time", this.Time },
|
||||
{ "Type", this.Type }
|
||||
};
|
||||
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if (json.Keys.Contains("srcId") && json["srcId"].Keys.Contains("value") &&
|
||||
json.Keys.Contains("sensorState") && json["sensorState"].Keys.Contains("value") &&
|
||||
json.Keys.Contains("sensorTime") && json["sensorTime"].Keys.Contains("value") &&
|
||||
json.Keys.Contains("typeString") && json["typeString"].Keys.Contains("value") &&
|
||||
this.CheckSetUpdateTime(json)) {
|
||||
this.Source = Int32.Parse(json["srcId"]["value"].ToString());
|
||||
this.Level = Int32.Parse(json["sensorState"]["value"].ToString());
|
||||
this.Time = Int32.Parse(json["sensorTime"]["value"].ToString());
|
||||
this.Type = json["typeString"]["value"].ToString();
|
||||
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<Int32, Int32, Int32, String>(this.Source, this.Level, this.Time, this.Type), this.LastUpdate, this));
|
||||
}
|
||||
}
|
||||
|
||||
internal override void Poll() => this.PollNone();
|
||||
#endregion
|
||||
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => new List<Senml>() { };
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,35 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
class Configurationsub : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
private Int64 _level;
|
||||
|
||||
#region Properties
|
||||
private Int64 _level;
|
||||
/// <summary>
|
||||
/// Value of the Configuration Item
|
||||
/// </summary>
|
||||
public Int64 Level {
|
||||
get {
|
||||
return this._level;
|
||||
}
|
||||
get => this._level;
|
||||
set {
|
||||
if (this.Size == 1 && Int16.TryParse(value.ToString(), out Int16 value16)) {
|
||||
this.SetTriple(this.SensorId, value16, 1);
|
||||
if(this.Size == 1 && Int16.TryParse(value.ToString(), out Int16 value16)) {
|
||||
this.SetTriple((this.SensorId, value16, 1));
|
||||
} else if(this.Size == 2 && Int32.TryParse(value.ToString(), out Int32 value32)) {
|
||||
this.SetTriple(this.SensorId, value32, 2);
|
||||
this.SetTriple((this.SensorId, value32, 2));
|
||||
} else if(this.Size == 4) {
|
||||
this.SetTriple(this.SensorId, value, 4);
|
||||
this.SetTriple((this.SensorId, value, 4));
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Size of the Configuration slot
|
||||
/// </summary>
|
||||
public Int32 Size { get; private set; }
|
||||
#endregion
|
||||
|
||||
public Configurationsub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
#region Constructor
|
||||
public Configurationsub(JsonData json, (Int32 device, Int32 instance, Classes commandclass, Int32 sensor) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.IsSub = true;
|
||||
InitComplex(json);
|
||||
this.InitComplex(json);
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
@ -42,8 +53,15 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
this.Size = Int32.Parse(json["size"]["value"].ToString());
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
internal override void Poll() => this.PollSub();
|
||||
#region ACommandClass
|
||||
public override String ToString() => "Configuration " + this.Name + " [" + this.Id + "]: " + this.Level;
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => new Dictionary<String, Object> {
|
||||
{ "Level", this.Level },
|
||||
{ "Size", this.Size },
|
||||
};
|
||||
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if (json.Keys.Contains("val") && json["val"].Keys.Contains("value") && json["val"]["value"] != null &&
|
||||
@ -55,15 +73,11 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
}
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
return "Configuration " + this.Name + " [" + this.Id + "]: " + this.Level;
|
||||
}
|
||||
internal override void Poll() => this.PollSub();
|
||||
#endregion
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "Level", this.Level },
|
||||
{ "Size", this.Size },
|
||||
};
|
||||
}
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => new List<Senml>() { };
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,22 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
public class Metersub : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Type of the Sensor
|
||||
/// </summary>
|
||||
public String Type { get; private set; }
|
||||
/// <summary>
|
||||
/// Actual value of the Sensor
|
||||
/// </summary>
|
||||
public Double Level { get; private set; }
|
||||
/// <summary>
|
||||
/// Scale of the Sensor
|
||||
/// </summary>
|
||||
public String Scale { get; private set; }
|
||||
public Metersub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Metersub(JsonData json, (Int32 device, Int32 instance, Classes commandclass, Int32 sensor) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.HasReset = true;
|
||||
this.IsSub = true;
|
||||
InitComplex(json);
|
||||
this.InitComplex(json);
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
@ -31,6 +48,16 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
this.Scale = json["scaleString"]["value"].ToString();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
public override String ToString() => "Meter " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale;
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => new Dictionary<String, Object> {
|
||||
{ "Level", this.Level },
|
||||
{ "Type", this.Type },
|
||||
{ "Scale", this.Scale },
|
||||
};
|
||||
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if (json.Keys.Contains("val") && json["val"].Keys.Contains("value") &&
|
||||
@ -44,18 +71,18 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
}
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
return "Meter " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale;
|
||||
}
|
||||
|
||||
internal override void Poll() => this.PollNone();
|
||||
#endregion
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "Level", this.Level },
|
||||
{ "Type", this.Type },
|
||||
{ "Scale", this.Scale },
|
||||
};
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() {
|
||||
if (this.Scale == "W") {
|
||||
return new List<Senml>() { new SenmlDouble("power", Senml.Units.Watt, this.Level) };
|
||||
} else if(this.Scale == "kWh") {
|
||||
return new List<Senml>() { new SenmlDouble("consumption", Senml.Units.Joule, this.Level * 1000 * 3.6 * 1000) };
|
||||
}
|
||||
return new List<Senml>() {};
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,20 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
public class Scenecontrollerconfsub : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Int32 Scene { get; private set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Int32 Duration { get; private set; }
|
||||
public Scenecontrollerconfsub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Scenecontrollerconfsub(JsonData json, (Int32 device, Int32 instance, Classes commandclass, Int32 sensor) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.IsSub = true;
|
||||
InitComplex(json);
|
||||
this.InitComplex(json);
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
@ -24,6 +38,15 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
this.Duration = Int32.Parse(json["duration"]["value"].ToString());
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
public override String ToString() => "SceneControllerConf " + this.Name + " [" + this.Id + "]: " + this.Scene + " " + this.Duration;
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => new Dictionary<String, Object> {
|
||||
{ "Scene", this.Scene },
|
||||
{ "Duration", this.Duration }
|
||||
};
|
||||
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if (json.Keys.Contains("scene") && json["scene"].Keys.Contains("value") &&
|
||||
@ -35,17 +58,11 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
}
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
return "SceneControllerConf " + this.Name + " [" + this.Id + "]: " + this.Scene + " " + this.Duration;
|
||||
}
|
||||
|
||||
internal override void Poll() => this.PollSub();
|
||||
#endregion
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "Scene", this.Scene },
|
||||
{ "Duration", this.Duration }
|
||||
};
|
||||
}
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => new List<Senml>() { };
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,20 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
public class Sensorbinarysub : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public String Type { get; private set; }
|
||||
public Boolean Level { get; private set; }
|
||||
public Sensorbinarysub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Boolean State { get; private set; }
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Int32 Level => this.State ? 1 : 0;
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Sensorbinarysub(JsonData json, (Int32 device, Int32 instance, Classes commandclass, Int32 sensor) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.IsSub = true;
|
||||
InitComplex(json);
|
||||
this.InitComplex(json);
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
@ -23,31 +41,35 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
json.Keys.Contains("level") &&
|
||||
json["level"].Keys.Contains("value")) {
|
||||
this.Type = json["sensorTypeString"]["value"].ToString();
|
||||
this.Level = (Boolean)json["level"]["value"];
|
||||
this.State = (Boolean)json["level"]["value"];
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
public override String ToString() => "SensorBinary " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.State.ToString();
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => new Dictionary<String, Object> {
|
||||
{ "State", this.State },
|
||||
{ "Type", this.Type },
|
||||
{ "Level", this.Level }
|
||||
};
|
||||
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if (json.Keys.Contains("level") && json["level"].Keys.Contains("value") &&
|
||||
json.Keys.Contains("sensorTypeString") && json["sensorTypeString"].Keys.Contains("value") &&
|
||||
this.CheckSetUpdateTime(json)) {
|
||||
this.Level = (Boolean)json["level"]["value"];
|
||||
this.State = (Boolean)json["level"]["value"];
|
||||
this.Type = json["sensorTypeString"]["value"].ToString();
|
||||
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<String, Boolean>(this.Type, this.Level), this.LastUpdate, this));
|
||||
this.Update?.Invoke(this, new DeviceUpdateEvent(new Tuple<String, Boolean>(this.Type, this.State), this.LastUpdate, this));
|
||||
}
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
return "SensorBinary " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level.ToString();
|
||||
}
|
||||
|
||||
internal override void Poll() => this.PollNone();
|
||||
#endregion
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "Level", this.Level },
|
||||
{ "Type", this.Type }
|
||||
};
|
||||
}
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => new List<Senml>() { };
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,22 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
public class Sensormultilevelsub : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Type of the Sensor
|
||||
/// </summary>
|
||||
public String Type { get; private set; }
|
||||
/// <summary>
|
||||
/// Level of the sensor
|
||||
/// </summary>
|
||||
public Double Level { get; private set; }
|
||||
/// <summary>
|
||||
/// Scale of the sensor
|
||||
/// </summary>
|
||||
public String Scale { get; private set; }
|
||||
#endregion
|
||||
|
||||
public Sensormultilevelsub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
#region Constructor
|
||||
public Sensormultilevelsub(JsonData json, (Int32 device, Int32 instance, Classes commandclass, Int32 sensor) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.IsSub = true;
|
||||
InitComplex(json);
|
||||
this.InitComplex(json);
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
@ -31,8 +46,27 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
this.Scale = json["scaleString"]["value"].ToString();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
public override String ToString() => "SensorMultilevel " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale;
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => new Dictionary<String, Object> {
|
||||
{ "Level", this.Level },
|
||||
{ "Type", this.Type },
|
||||
{ "Scale", this.Scale },
|
||||
};
|
||||
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if(json.Keys.Contains("val") && json["val"].Keys.Contains("value") && json.Keys.Contains("sensorTypeString") && json["sensorTypeString"].Keys.Contains("value")) {
|
||||
String t = json["sensorTypeString"]["value"].ToString();
|
||||
Double l = Double.Parse(json["val"]["value"].ToString());
|
||||
if (t == "Power" && (l > 3680 || l < 0) ||
|
||||
t == "Temperature" && (l > 65 || l < -25) ||
|
||||
t == "Temperature" && this.Level >= 4 && Math.Abs(l) <= 0.1) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(json.Keys.Contains("val") && json["val"].Keys.Contains("value") &&
|
||||
json.Keys.Contains("sensorTypeString") && json["sensorTypeString"].Keys.Contains("value") &&
|
||||
json.Keys.Contains("scaleString") && json["scaleString"].Keys.Contains("value") &&
|
||||
@ -44,18 +78,20 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
}
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
return "SensorMultilevel " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale;
|
||||
}
|
||||
|
||||
internal override void Poll() => this.PollNone();
|
||||
#endregion
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "Level", this.Level },
|
||||
{ "Type", this.Type },
|
||||
{ "Scale", this.Scale },
|
||||
};
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() {
|
||||
if(this.Scale == "W") {
|
||||
return new List<Senml>() { new SenmlDouble("power", Senml.Units.Watt, this.Level) };
|
||||
} else if(this.Scale == "°C") {
|
||||
return new List<Senml>() { new SenmlDouble("temperatur", Senml.Units.Celsius, this.Level) };
|
||||
} else if(this.Scale == "Lux") {
|
||||
return new List<Senml>() { new SenmlDouble("luminiscence", Senml.Units.Lux, this.Level) };
|
||||
}
|
||||
return new List<Senml>() { };
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,35 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
class Thermostatsetpointsub : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
#region Properties
|
||||
private Double _level;
|
||||
/// <summary>
|
||||
/// Target-Temperatur
|
||||
/// </summary>
|
||||
public Double Level {
|
||||
get {
|
||||
return this._level;
|
||||
}
|
||||
get => this._level;
|
||||
set {
|
||||
if (!this.HasMinMax || (this.HasMinMax && value >= this.TempMin && value <= this.TempMax)) {
|
||||
this.SetTuple(this.SensorId, (Double)Math.Round(value * 2, MidpointRounding.AwayFromZero) / 2);
|
||||
if(!this.HasMinMax || this.HasMinMax && value >= this.TempMin && value <= this.TempMax) {
|
||||
this.SetTuple((this.SensorId, (Double)Math.Round(value * 2, MidpointRounding.AwayFromZero) / 2));
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Scale of the actor
|
||||
/// </summary>
|
||||
public String Scale { get; private set; }
|
||||
/// <summary>
|
||||
/// Maximum Temperatur of the actor
|
||||
/// </summary>
|
||||
public Double TempMax { get; private set; }
|
||||
/// <summary>
|
||||
/// Minimum Temperatur of the actor
|
||||
/// </summary>
|
||||
public Double TempMin { get; private set; }
|
||||
/// <summary>
|
||||
/// Has Maximum and Minimum
|
||||
/// </summary>
|
||||
public Boolean HasMinMax { get; private set; }
|
||||
/// <summary>
|
||||
/// Type of the actor
|
||||
/// </summary>
|
||||
public String Type { get; private set; }
|
||||
#endregion
|
||||
|
||||
public Thermostatsetpointsub(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
#region Constructor
|
||||
public Thermostatsetpointsub(JsonData json, (Int32 device, Int32 instance, Classes commandclass, Int32 sensor) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.IsSub = true;
|
||||
InitComplex(json);
|
||||
this.InitComplex(json);
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
@ -49,6 +70,19 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
this.HasMinMax = false;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
public override String ToString() => "ThermostatSetPoint " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale + " [" + this.TempMin + "," + this.TempMax + "," + this.HasMinMax + "]";
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => new Dictionary<String, Object> {
|
||||
{ "Level", this.Level },
|
||||
{ "Type", this.Type },
|
||||
{ "Scale", this.Scale },
|
||||
{ "TempMax", this.TempMax },
|
||||
{ "TempMin", this.TempMin },
|
||||
{ "HasMinMax", this.HasMinMax },
|
||||
};
|
||||
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
Boolean ret = false;
|
||||
@ -74,21 +108,11 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs {
|
||||
}
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
return "ThermostatSetPoint " + this.Name + " [" + this.Id + "]: " + this.Type + " " + this.Level + "" + this.Scale + " [" + this.TempMin + "," + this.TempMax + "," + this.HasMinMax + "]";
|
||||
}
|
||||
|
||||
internal override void Poll() => this.PollSub();
|
||||
#endregion
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "Level", this.Level },
|
||||
{ "Type", this.Type },
|
||||
{ "Scale", this.Scale },
|
||||
{ "TempMax", this.TempMax },
|
||||
{ "TempMin", this.TempMin },
|
||||
{ "HasMinMax", this.HasMinMax },
|
||||
};
|
||||
}
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => this.Scale == "°C" ? new List<Senml>() { new SenmlDouble("temperatur", Senml.Units.Celsius, this.Level) } : new List<Senml>() { };
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -2,10 +2,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
@ -15,19 +19,16 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
class Configuration : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
public Configuration(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
#region Constructor
|
||||
public Configuration(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.HasSub = true;
|
||||
this.InitComplex(json);
|
||||
this.InitComplex(json, name);
|
||||
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
|
||||
item.Value.Update += this.DeviceUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
||||
this.Update?.Invoke(this, e);
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
private void InitComplex(JsonData json, (String device, ReadOnlyDictionary<String, String> descriptions) name) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
JsonData data = json["data"];
|
||||
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
|
||||
@ -37,13 +38,17 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
data[item].Keys.Contains("val") &&
|
||||
data[item]["val"].Keys.Contains("value") &&
|
||||
data[item]["val"]["value"] != null) {
|
||||
subs.Add(subid, new Configurationsub(data[item], new Tuple<Int32, Int32, Classes, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling));
|
||||
subs.Add(subid, new Configurationsub(data[item], (this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling, name));
|
||||
}
|
||||
}
|
||||
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) => this.Update?.Invoke(this, e);
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if (match.Groups[4].Value.StartsWith(".data.")) {
|
||||
Int32 subid = Int32.Parse(match.Groups[5].Value);
|
||||
@ -58,5 +63,10 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
internal override void Poll() => this.PollPerSub();
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
|
||||
#endregion
|
||||
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => this.ToSenmlListSub();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
@ -11,47 +16,59 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
/// 135 = Indicator
|
||||
/// </summary>
|
||||
class Indicator : ACommandClass {
|
||||
private Boolean _level;
|
||||
|
||||
public override event UpdatedValue Update;
|
||||
public Boolean Level {
|
||||
get {
|
||||
return this._level;
|
||||
}
|
||||
set {
|
||||
this.SetInt(value ? 255 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
public Indicator(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
this.InitComplex(json);
|
||||
#region Properties
|
||||
private Boolean _state;
|
||||
/// <summary>
|
||||
/// Status of the Indicator
|
||||
/// </summary>
|
||||
public Boolean State {
|
||||
get => this._state;
|
||||
set => this.SetInt(value ? 255 : 0);
|
||||
}
|
||||
/// <summary>
|
||||
/// Int-Representation of the Indicator
|
||||
/// </summary>
|
||||
public Int32 Level {
|
||||
get => this.State ? 1 : 0;
|
||||
set => this.State = value == 1;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
public Indicator(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) => this.InitComplex(json);
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data") && json["data"].Keys.Contains("stat") && json["data"]["stat"].Keys.Contains("value")) {
|
||||
this._level = Int32.Parse(json["data"]["stat"]["value"].ToString()) == 255;
|
||||
this._state = Int32.Parse(json["data"]["stat"]["value"].ToString()) == 255;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
public override String ToString() => "Indicator " + this.Name + " [" + this.Id + "]: " + this.State;
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => new Dictionary<String, Object> {
|
||||
{ "State", this.State },
|
||||
{ "Level", this.Level }
|
||||
};
|
||||
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if(match.Groups[4].Value == ".data.stat") {
|
||||
if (json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) {
|
||||
this._level = Int32.Parse(json["value"].ToString()) == 255;
|
||||
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this));
|
||||
this._state = Int32.Parse(json["value"].ToString()) == 255;
|
||||
this.Update?.Invoke(this, new DeviceUpdateEvent(this.State, this.LastUpdate, this));
|
||||
}
|
||||
} else {
|
||||
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public override String ToString() {
|
||||
return "Indicator " + this.Name + " [" + this.Id + "]: " + this.Level;
|
||||
}
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => new List<Senml>() { new SenmlBool("status", Senml.Units.CounterValue, this.State) };
|
||||
#endregion
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "Level", this.Level },
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
@ -15,18 +19,35 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
public class Meter : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
public Meter(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
#region Constructor
|
||||
public Meter(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.HasSub = true;
|
||||
this.InitComplex(json);
|
||||
this.InitComplex(json, name);
|
||||
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
|
||||
item.Value.Update += this.DeviceUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
||||
this.Update?.Invoke(this, e);
|
||||
private void InitComplex(JsonData json, (String device, ReadOnlyDictionary<String, String> descriptions) name) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
JsonData data = json["data"];
|
||||
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
|
||||
foreach (String item in data.Keys) {
|
||||
if (Int32.TryParse(item, out Int32 subid) &&
|
||||
data[item].Keys.Contains("sensorTypeString") &&
|
||||
data[item].Keys.Contains("val") &&
|
||||
data[item].Keys.Contains("scaleString")) {
|
||||
subs.Add(subid, new Metersub(data[item], (this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling, name));
|
||||
}
|
||||
}
|
||||
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) => this.Update?.Invoke(this, e);
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if (match.Groups[4].Value.StartsWith(".data.")) {
|
||||
Int32 subid = Int32.Parse(match.Groups[5].Value);
|
||||
@ -38,24 +59,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
}
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
JsonData data = json["data"];
|
||||
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
|
||||
foreach (String item in data.Keys) {
|
||||
if (Int32.TryParse(item, out Int32 subid) &&
|
||||
data[item].Keys.Contains("sensorTypeString") &&
|
||||
data[item].Keys.Contains("val") &&
|
||||
data[item].Keys.Contains("scaleString")) {
|
||||
subs.Add(subid, new Metersub(data[item], new Tuple<Int32, Int32, Classes, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling));
|
||||
}
|
||||
}
|
||||
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
|
||||
}
|
||||
}
|
||||
|
||||
internal override void Poll() => this.PollSubGlobal();
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
|
||||
#endregion
|
||||
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => this.ToSenmlListSub();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
@ -15,18 +19,34 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
public class Scenecontrollerconf : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
public Scenecontrollerconf(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
#region Constructor
|
||||
public Scenecontrollerconf(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.HasSub = true;
|
||||
this.InitComplex(json);
|
||||
this.InitComplex(json, name);
|
||||
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
|
||||
item.Value.Update += this.DeviceUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
||||
this.Update?.Invoke(this, e);
|
||||
private void InitComplex(JsonData json, (String device, ReadOnlyDictionary<String, String> descriptions) name) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
JsonData data = json["data"];
|
||||
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
|
||||
foreach (String item in data.Keys) {
|
||||
if (Int32.TryParse(item, out Int32 subid) &&
|
||||
data[item].Keys.Contains("scene") &&
|
||||
data[item].Keys.Contains("duration")) {
|
||||
subs.Add(subid, new Scenecontrollerconfsub(data[item], (this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling, name));
|
||||
}
|
||||
}
|
||||
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) => this.Update?.Invoke(this, e);
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if (match.Groups[4].Value.StartsWith(".data.")) {
|
||||
Int32 subid = Int32.Parse(match.Groups[5].Value);
|
||||
@ -37,24 +57,14 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||
}
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
JsonData data = json["data"];
|
||||
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
|
||||
foreach (String item in data.Keys) {
|
||||
if (Int32.TryParse(item, out Int32 subid) &&
|
||||
data[item].Keys.Contains("scene") &&
|
||||
data[item].Keys.Contains("duration")) {
|
||||
subs.Add(subid, new Scenecontrollerconfsub(data[item], new Tuple<Int32, Int32, Classes, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling));
|
||||
}
|
||||
}
|
||||
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal override void Poll() => this.PollPerSub();
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
|
||||
#endregion
|
||||
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => this.ToSenmlListSub();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
@ -15,18 +19,34 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
public class Sensorbinary : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
public Sensorbinary(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
#region Constructor
|
||||
public Sensorbinary(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.HasSub = true;
|
||||
this.InitComplex(json);
|
||||
this.InitComplex(json, name);
|
||||
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
|
||||
item.Value.Update += this.DeviceUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
||||
this.Update?.Invoke(this, e);
|
||||
private void InitComplex(JsonData json, (String device, ReadOnlyDictionary<String, String> descriptions) name) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
JsonData data = json["data"];
|
||||
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
|
||||
foreach (String item in data.Keys) {
|
||||
if (Int32.TryParse(item, out Int32 subid) &&
|
||||
data[item].Keys.Contains("sensorTypeString") &&
|
||||
data[item].Keys.Contains("level")) {
|
||||
subs.Add(subid, new Sensorbinarysub(data[item], (this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling, name));
|
||||
}
|
||||
}
|
||||
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) => this.Update?.Invoke(this, e);
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if (match.Groups[4].Value.StartsWith(".data.")) {
|
||||
Int32 subid = Int32.Parse(match.Groups[5].Value);
|
||||
@ -37,24 +57,14 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||
}
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
JsonData data = json["data"];
|
||||
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
|
||||
foreach (String item in data.Keys) {
|
||||
if (Int32.TryParse(item, out Int32 subid) &&
|
||||
data[item].Keys.Contains("sensorTypeString") &&
|
||||
data[item].Keys.Contains("level")) {
|
||||
subs.Add(subid, new Sensorbinarysub(data[item], new Tuple<Int32, Int32, Classes, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling));
|
||||
}
|
||||
}
|
||||
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal override void Poll() => this.PollSubGlobal();
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
|
||||
#endregion
|
||||
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => this.ToSenmlListSub();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
@ -15,18 +19,35 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
public class Sensormultilevel : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
public Sensormultilevel(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
#region Constructor
|
||||
public Sensormultilevel(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.HasSub = true;
|
||||
this.InitComplex(json);
|
||||
this.InitComplex(json, name);
|
||||
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
|
||||
item.Value.Update += this.DeviceUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
||||
this.Update?.Invoke(this, e);
|
||||
private void InitComplex(JsonData json, (String device, ReadOnlyDictionary<String, String> descriptions) name) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
JsonData data = json["data"];
|
||||
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
|
||||
foreach (String item in data.Keys) {
|
||||
if (Int32.TryParse(item, out Int32 subid) &&
|
||||
data[item].Keys.Contains("sensorTypeString") &&
|
||||
data[item].Keys.Contains("val") &&
|
||||
data[item].Keys.Contains("scaleString")) {
|
||||
subs.Add(subid, new Sensormultilevelsub(data[item], (this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling, name));
|
||||
}
|
||||
}
|
||||
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) => this.Update?.Invoke(this, e);
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if (match.Groups[4].Value.StartsWith(".data.")) {
|
||||
Int32 subid = Int32.Parse(match.Groups[5].Value);
|
||||
@ -38,24 +59,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
}
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
JsonData data = json["data"];
|
||||
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
|
||||
foreach (String item in data.Keys) {
|
||||
if (Int32.TryParse(item, out Int32 subid) &&
|
||||
data[item].Keys.Contains("sensorTypeString") &&
|
||||
data[item].Keys.Contains("val") &&
|
||||
data[item].Keys.Contains("scaleString")) {
|
||||
subs.Add(subid, new Sensormultilevelsub(data[item], new Tuple<Int32, Int32, Classes, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling));
|
||||
}
|
||||
}
|
||||
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
|
||||
}
|
||||
}
|
||||
|
||||
internal override void Poll() => this.PollSubGlobal();
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
|
||||
#endregion
|
||||
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => this.ToSenmlListSub();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
@ -11,48 +16,58 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
/// 37 = SwitchBinary
|
||||
/// </summary>
|
||||
public class Switchbinary : ACommandClass {
|
||||
private Boolean _level;
|
||||
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
public Boolean Level {
|
||||
get {
|
||||
return this._level;
|
||||
}
|
||||
set {
|
||||
this.SetInt(value ? 255 : 0);
|
||||
}
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Int representation of Boolean
|
||||
/// </summary>
|
||||
public Int32 Level {
|
||||
get => this.State ? 1 : 0;
|
||||
set => this.State = value == 1;
|
||||
}
|
||||
private Boolean _state;
|
||||
/// <summary>
|
||||
/// State if Switch is activated
|
||||
/// </summary>
|
||||
public Boolean State {
|
||||
get => this._state;
|
||||
set => this.SetInt(value ? 255 : 0);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public Switchbinary(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
this.InitComplex(json);
|
||||
#region Constructor
|
||||
public Switchbinary(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) => this.InitComplex(json);
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data") && json["data"].Keys.Contains("level") && json["data"]["level"].Keys.Contains("value") && json["data"]["level"]["value"].IsBoolean) {
|
||||
this._state = (Boolean)json["data"]["level"]["value"];
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
public override String ToString() => "SwitchBinary " + this.Name + " [" + this.Id + "]: " + this.State;
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => new Dictionary<String, Object> {
|
||||
{ "State", this.State },
|
||||
{ "Level", this.Level }
|
||||
};
|
||||
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if(match.Groups[4].Value == ".data.level") {
|
||||
if (json.Keys.Contains("value") && json["value"].IsBoolean && this.CheckSetUpdateTime(json)) {
|
||||
this._level = (Boolean)json["value"];
|
||||
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this));
|
||||
this._state = (Boolean)json["value"];
|
||||
this.Update?.Invoke(this, new DeviceUpdateEvent(this.State, this.LastUpdate, this));
|
||||
}
|
||||
} else {
|
||||
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data") && json["data"].Keys.Contains("level") && json["data"]["level"].Keys.Contains("value") && json["data"]["level"]["value"].IsBoolean) {
|
||||
this._level = (Boolean)json["data"]["level"]["value"];
|
||||
}
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
return "SwitchBinary " + this.Name + " [" + this.Id + "]: " + this.Level;
|
||||
}
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "Level", this.Level }
|
||||
};
|
||||
}
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => new List<Senml>() { new SenmlBool("state", Senml.Units.CounterValue, this.State) };
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
@ -11,24 +16,39 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
/// 38 = SwitchMultilevel
|
||||
/// </summary>
|
||||
public class Switchmultilevel : ACommandClass {
|
||||
private Int32 _level;
|
||||
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
#region Properties
|
||||
private Int32 _level;
|
||||
/// <summary>
|
||||
/// Level of thw Switch
|
||||
/// </summary>
|
||||
public Int32 Level {
|
||||
get {
|
||||
return this._level;
|
||||
}
|
||||
get => this._level;
|
||||
set {
|
||||
if(value == 0 || (value > 0 && value <= 99) || value == 255) {
|
||||
this.SetTuple(value, 0);
|
||||
if(value == 0 || value > 0 && value <= 99 || value == 255) {
|
||||
this.SetTuple((value, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public Switchmultilevel(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
this.InitComplex(json);
|
||||
#region Constructor
|
||||
public Switchmultilevel(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) => this.InitComplex(json);
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data") && json["data"].Keys.Contains("level") && json["data"]["level"].Keys.Contains("value")) {
|
||||
this._level = Int32.Parse(json["data"]["level"]["value"].ToString());
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
public override String ToString() => "SwitchMultilevel " + this.Name + " [" + this.Id + "]: " + this.Level;
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => new Dictionary<String, Object> {
|
||||
{ "Level", this.Level }
|
||||
};
|
||||
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if(match.Groups[4].Value == ".data.level") {
|
||||
@ -41,21 +61,10 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data") && json["data"].Keys.Contains("level") && json["data"]["level"].Keys.Contains("value")) {
|
||||
this._level = Int32.Parse(json["data"]["level"]["value"].ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public override String ToString() {
|
||||
return "SwitchMultilevel " + this.Name + " [" + this.Id + "]: " + this.Level;
|
||||
}
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "Level", this.Level }
|
||||
};
|
||||
}
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => new List<Senml>() { new SenmlDouble("state", Senml.Units.Percent, (Double)this.Level / 255) };
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -2,9 +2,13 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
@ -12,36 +16,33 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
/// 64 = ThermostatMode
|
||||
/// </summary>
|
||||
public class Thermostatmode : ACommandClass {
|
||||
private Int32 _level;
|
||||
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
#region Properties
|
||||
/// <summary>
|
||||
/// Allowd Modes
|
||||
/// </summary>
|
||||
public ReadOnlyDictionary<Int32, String> ValidModes { get; private set; }
|
||||
private Int32 _level;
|
||||
/// <summary>
|
||||
/// Actual mode
|
||||
/// </summary>
|
||||
public Int32 Level {
|
||||
get { return this._level; }
|
||||
get => this._level;
|
||||
set {
|
||||
if (this.ValidModes.ContainsKey(value)) {
|
||||
if(this.ValidModes.ContainsKey(value)) {
|
||||
this.SetInt(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public Thermostatmode(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
#region Constructor
|
||||
public Thermostatmode(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.ValidModes = new ReadOnlyDictionary<Int32, String>(new Dictionary<Int32, String>());
|
||||
this.InitComplex(json);
|
||||
}
|
||||
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if(match.Groups[4].Value == ".data.mode") {
|
||||
if(json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) {
|
||||
this._level = Int32.Parse(json["value"].ToString());
|
||||
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this));
|
||||
}
|
||||
} else {
|
||||
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||
}
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
JsonData data = json["data"];
|
||||
@ -60,10 +61,10 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public override String ToString() {
|
||||
return "ThermostatMode " + this.Name + " [" + this.Id + "]: " + this.ValidModes[this.Level];
|
||||
}
|
||||
#region ACommandClass
|
||||
public override String ToString() => "ThermostatMode " + this.Name + " [" + this.Id + "]: " + this.ValidModes[this.Level];
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
Dictionary<String, String> modes = new Dictionary<String, String>();
|
||||
@ -76,5 +77,21 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
};
|
||||
return json;
|
||||
}
|
||||
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if(match.Groups[4].Value == ".data.mode") {
|
||||
if(json.Keys.Contains("value") && this.CheckSetUpdateTime(json)) {
|
||||
this._level = Int32.Parse(json["value"].ToString());
|
||||
this.Update?.Invoke(this, new DeviceUpdateEvent(this.Level, this.LastUpdate, this));
|
||||
}
|
||||
} else {
|
||||
Helper.WriteError("Kenne in " + this.Name + " [" + this.Id + "] " + match.Groups[4].Value + " nicht!");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => new List<Senml>() { new SenmlDouble("mode", Senml.Units.CounterValue, this.Level) };
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,14 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Devices.CommandClasses.CommandClassSubs;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
@ -15,18 +19,35 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
public class Thermostatsetpoint : ACommandClass {
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
public Thermostatsetpoint(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
#region Constructor
|
||||
public Thermostatsetpoint(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) {
|
||||
this.HasSub = true;
|
||||
this.InitComplex(json);
|
||||
this.InitComplex(json, name);
|
||||
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
|
||||
item.Value.Update += this.DeviceUpdate;
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
||||
this.Update?.Invoke(this, e);
|
||||
private void InitComplex(JsonData json, (String device, ReadOnlyDictionary<String, String> descriptions) name) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
JsonData data = json["data"];
|
||||
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
|
||||
foreach (String item in data.Keys) {
|
||||
if (Int32.TryParse(item, out Int32 subid) &&
|
||||
data[item].Keys.Contains("modeName") &&
|
||||
data[item].Keys.Contains("val") &&
|
||||
data[item].Keys.Contains("deviceScaleString")) {
|
||||
subs.Add(subid, new Thermostatsetpointsub(data[item], (this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling, name));
|
||||
}
|
||||
}
|
||||
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) => this.Update?.Invoke(this, e);
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
if (match.Groups[4].Value.StartsWith(".data.")) {
|
||||
Int32 subid = Int32.Parse(match.Groups[5].Value);
|
||||
@ -38,24 +59,13 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
}
|
||||
}
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
JsonData data = json["data"];
|
||||
Dictionary<Int32, ACommandClass> subs = new Dictionary<Int32, ACommandClass>();
|
||||
foreach (String item in data.Keys) {
|
||||
if (Int32.TryParse(item, out Int32 subid) &&
|
||||
data[item].Keys.Contains("modeName") &&
|
||||
data[item].Keys.Contains("val") &&
|
||||
data[item].Keys.Contains("deviceScaleString")) {
|
||||
subs.Add(subid, new Thermostatsetpointsub(data[item], new Tuple<Int32, Int32, Classes, Int32>(this.DeviceId, this.Instance, this.Commandclass, subid), this.http, this.Polling));
|
||||
}
|
||||
}
|
||||
this.Sub = new ReadOnlyDictionary<Int32, ACommandClass>(subs);
|
||||
}
|
||||
}
|
||||
|
||||
internal override void Poll() => this.PollPerSub();
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => this.ToDictionarySub();
|
||||
#endregion
|
||||
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => this.ToSenmlListSub();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
@ -11,38 +14,36 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
/// 132 = Wakeup
|
||||
/// </summary>
|
||||
class Wakeup : ACommandClass {
|
||||
private Int32 _interval;
|
||||
private Int32 _againstNode;
|
||||
|
||||
public override event UpdatedValue Update;
|
||||
|
||||
#region Properties
|
||||
private Int32 _interval;
|
||||
public Int32 Interval {
|
||||
get {
|
||||
return this._interval;
|
||||
}
|
||||
get => this._interval;
|
||||
set {
|
||||
if(value >= this.WakeupMin && value <= this.WakeupMax) {
|
||||
this.SetTuple(value, this.AgainstNode);
|
||||
this.SetTuple((value, this.AgainstNode));
|
||||
}
|
||||
}
|
||||
}
|
||||
public Int32 AgainstNode { get {
|
||||
return this._againstNode;
|
||||
}
|
||||
set {
|
||||
this.SetTuple(this.Interval, value);
|
||||
}
|
||||
private Int32 _againstNode;
|
||||
public Int32 AgainstNode {
|
||||
get => this._againstNode;
|
||||
set => this.SetTuple((this.Interval, value));
|
||||
}
|
||||
public Int32 WakeupMin { get; private set; }
|
||||
public Int32 WakeupMax { get; private set; }
|
||||
public Boolean HasMinMax { get; private set; }
|
||||
public Boolean HasMinMaxState { get; private set; }
|
||||
public Int32 HasMinMaxLevel => this.HasMinMaxState ? 1 : 0;
|
||||
public Int32 WakeupDefault { get; private set; }
|
||||
public Boolean HasDefault { get; private set; }
|
||||
public Boolean HasDefaultState { get; private set; }
|
||||
public Int32 HasDefaultLevel => this.HasDefaultState ? 1 : 0;
|
||||
public DateTime LastWakeup { get; private set; }
|
||||
public DateTime LastSleep { get; private set; }
|
||||
#endregion
|
||||
|
||||
public Wakeup(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) : base(json, id, http, polling) {
|
||||
this.InitComplex(json);
|
||||
}
|
||||
#region Constructor
|
||||
public Wakeup(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) : base(id, http, polling, name) => this.InitComplex(json);
|
||||
|
||||
private void InitComplex(JsonData json) {
|
||||
if (json.Keys.Contains("data")) {
|
||||
@ -53,19 +54,19 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
if (data.Keys.Contains("nodeId") && data["nodeId"].Keys.Contains("value")) {
|
||||
this._againstNode = Int32.Parse(data["nodeId"]["value"].ToString());
|
||||
}
|
||||
this.HasMinMax = false;
|
||||
this.HasMinMaxState = false;
|
||||
if (data.Keys.Contains("min") && data["min"].Keys.Contains("value") && data["min"]["value"] != null) {
|
||||
this.WakeupMin = Int32.Parse(data["min"]["value"].ToString());
|
||||
this.HasMinMax = true;
|
||||
this.HasMinMaxState = true;
|
||||
}
|
||||
if (data.Keys.Contains("max") && data["max"].Keys.Contains("value") && data["max"]["value"] != null) {
|
||||
this.WakeupMax = Int32.Parse(data["max"]["value"].ToString());
|
||||
this.HasMinMax = true;
|
||||
this.HasMinMaxState = true;
|
||||
}
|
||||
this.HasDefault = false;
|
||||
this.HasDefaultState = false;
|
||||
if (data.Keys.Contains("default") && data["default"].Keys.Contains("value") && data["default"]["value"] != null) {
|
||||
this.WakeupDefault = Int32.Parse(data["default"]["value"].ToString());
|
||||
this.HasDefault = true;
|
||||
this.HasDefaultState = true;
|
||||
}
|
||||
if (data.Keys.Contains("lastWakeup") && data["lastWakeup"].Keys.Contains("value") && data["lastWakeup"]["value"] != null) {
|
||||
this.LastWakeup = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(data["lastWakeup"]["value"].ToString())).DateTime.ToLocalTime();
|
||||
@ -75,6 +76,24 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ACommandClass
|
||||
public override String ToString() => "Wakeup " + this.Name + " [" + this.Id + "]: " + this.LastWakeup + "-" + this.LastSleep + " " + this.Interval + " [" + this.WakeupMin + "," + this.WakeupMax + "," + this.WakeupDefault + "," + this.AgainstNode + "]";
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() => new Dictionary<String, Object> {
|
||||
{ "Interval", this.Interval },
|
||||
{ "AgainstNode", this.AgainstNode },
|
||||
{ "WakeupMin", this.WakeupMin },
|
||||
{ "WakeupMax", this.WakeupMax },
|
||||
{ "HasMinMaxState", this.HasMinMaxState },
|
||||
{ "HasMinMaxLevel", this.HasMinMaxLevel },
|
||||
{ "WakeupDefault", this.WakeupDefault },
|
||||
{ "HasDefaultState", this.HasDefaultState },
|
||||
{ "HasDefaultLevel", this.HasDefaultLevel },
|
||||
{ "LastWakeup", this.LastWakeup.ToString() },
|
||||
{ "LastSleep", this.LastSleep.ToString() }
|
||||
};
|
||||
|
||||
internal override void SetUpdate(JsonData json, Match match) {
|
||||
Boolean success = false;
|
||||
@ -97,22 +116,22 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
this._againstNode = Int32.Parse(json["nodeId"]["value"].ToString());
|
||||
success = true;
|
||||
}
|
||||
this.HasMinMax = false;
|
||||
this.HasMinMaxState = false;
|
||||
if (json.Keys.Contains("min") && json["min"].Keys.Contains("value") && json["min"]["value"] != null) {
|
||||
this.WakeupMin = Int32.Parse(json["min"]["value"].ToString());
|
||||
success = true;
|
||||
this.HasMinMax = true;
|
||||
this.HasMinMaxState = true;
|
||||
}
|
||||
if (json.Keys.Contains("max") && json["max"].Keys.Contains("value") && json["max"]["value"] != null) {
|
||||
this.WakeupMax = Int32.Parse(json["max"]["value"].ToString());
|
||||
success = true;
|
||||
this.HasMinMax = true;
|
||||
this.HasMinMaxState = true;
|
||||
}
|
||||
this.HasDefault = false;
|
||||
this.HasDefaultState = false;
|
||||
if (json.Keys.Contains("default") && json["default"].Keys.Contains("value") && json["default"]["value"] != null) {
|
||||
this.WakeupDefault = Int32.Parse(json["default"]["value"].ToString());
|
||||
success = true;
|
||||
this.HasDefault = true;
|
||||
this.HasDefaultState = true;
|
||||
}
|
||||
if (json.Keys.Contains("lastWakeup") && json["lastWakeup"].Keys.Contains("value") && json["lastWakeup"]["value"] != null) {
|
||||
this.LastWakeup = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(json["lastWakeup"]["value"].ToString())).DateTime.ToLocalTime();
|
||||
@ -129,23 +148,10 @@ namespace BlubbFish.IoT.Zway.Devices.CommandClasses {
|
||||
this.Update?.Invoke(this, new DeviceUpdateEvent(0, this.LastUpdate, this));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
public override String ToString() {
|
||||
return "Wakeup " + this.Name + " [" + this.Id + "]: " + this.LastWakeup + "-" + this.LastSleep + " " + this.Interval + " [" + this.WakeupMin + "," + this.WakeupMax + "," + this.WakeupDefault + "," + this.AgainstNode + "]";
|
||||
}
|
||||
|
||||
public override Dictionary<String, Object> ToDictionary() {
|
||||
return new Dictionary<String, Object> {
|
||||
{ "Interval", this.Interval },
|
||||
{ "AgainstNode", this.AgainstNode },
|
||||
{ "WakeupMin", this.WakeupMin },
|
||||
{ "WakeupMax", this.WakeupMax },
|
||||
{ "HasMinMax", this.HasMinMax },
|
||||
{ "WakeupDefault", this.WakeupDefault },
|
||||
{ "HasDefault", this.HasDefault },
|
||||
{ "LastWakeup", this.LastWakeup.ToString() },
|
||||
{ "LastSleep", this.LastSleep.ToString() }
|
||||
};
|
||||
}
|
||||
#region ISenml
|
||||
protected override List<Senml> ToSenmlList() => new List<Senml>() { };
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -2,13 +2,15 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices {
|
||||
public class Device {
|
||||
private Boolean polling;
|
||||
private readonly Boolean polling;
|
||||
|
||||
public delegate void UpdatedDevice(Object sender, DeviceUpdateEvent e);
|
||||
public event UpdatedDevice Update;
|
||||
@ -18,15 +20,21 @@ namespace BlubbFish.IoT.Zway.Devices {
|
||||
public ReadOnlyDictionary<Int32, Instance> Instances { get; private set; }
|
||||
public DateTime LastUpdate { get; private set; }
|
||||
|
||||
private Device(JsonData json, Tuple<Int32> id, HttpConnection http, Boolean polling) {
|
||||
this.Id = id.Item1;
|
||||
private Device(JsonData json, Int32 id, HttpConnection http, Boolean polling, ReadOnlyDictionary<String, ReadOnlyDictionary<String, String>> names) {
|
||||
this.Id = id;
|
||||
this.polling = polling;
|
||||
this.CreateInstances(json["instances"], http);
|
||||
if (json["data"].Keys.Contains("givenName") && json["data"]["givenName"].Keys.Contains("value")) {
|
||||
this.Name = json["data"]["givenName"]["value"].ToString();
|
||||
} else {
|
||||
this.Name = "Unknown";
|
||||
|
||||
Int32 ManufacturerId = json["data"].ContainsKey("manufacturerId") && json["data"]["manufacturerId"].IsObject && json["data"]["manufacturerId"].ContainsKey("value") && json["data"]["manufacturerId"]["value"] != null && json["data"]["manufacturerId"]["value"].IsInt ? (Int32)json["data"]["manufacturerId"]["value"] : 0;
|
||||
Int32 ProductType = json["data"].ContainsKey("manufacturerProductType") && json["data"]["manufacturerProductType"].IsObject && json["data"]["manufacturerProductType"].ContainsKey("value") && json["data"]["manufacturerProductType"]["value"] != null && json["data"]["manufacturerProductType"]["value"].IsInt ? (Int32)json["data"]["manufacturerProductType"]["value"] : 0;
|
||||
Int32 ProductId = json["data"].ContainsKey("manufacturerProductId") && json["data"]["manufacturerProductId"].IsObject && json["data"]["manufacturerProductId"].ContainsKey("value") && json["data"]["manufacturerProductId"]["value"] != null && json["data"]["manufacturerProductId"]["value"].IsInt ? (Int32)json["data"]["manufacturerProductId"]["value"] : 0;
|
||||
ReadOnlyDictionary<String, String> descriptions = new ReadOnlyDictionary<String, String>(new Dictionary<String, String>());
|
||||
if(names.ContainsKey(ManufacturerId + "-" + ProductType + "-" + ProductId)) {
|
||||
descriptions = names[ManufacturerId + "-" + ProductType + "-" + ProductId];
|
||||
}
|
||||
this.Name = json["data"].Keys.Contains("givenName") && json["data"]["givenName"].Keys.Contains("value") ? json["data"]["givenName"]["value"].ToString() : "Unknown";
|
||||
|
||||
this.CreateInstances(json["instances"], http, descriptions);
|
||||
|
||||
foreach (KeyValuePair<Int32, Instance> item in this.Instances) {
|
||||
item.Value.Update += this.InstanceUpdate;
|
||||
}
|
||||
@ -46,14 +54,12 @@ namespace BlubbFish.IoT.Zway.Devices {
|
||||
}
|
||||
}
|
||||
|
||||
private void InstanceUpdate(Object sender, DeviceUpdateEvent e) {
|
||||
this.Update?.Invoke(this, e);
|
||||
}
|
||||
private void InstanceUpdate(Object sender, DeviceUpdateEvent e) => this.Update?.Invoke(this, e);
|
||||
|
||||
private void CreateInstances(JsonData json, HttpConnection http) {
|
||||
private void CreateInstances(JsonData json, HttpConnection http, ReadOnlyDictionary<String, String> names) {
|
||||
Dictionary<Int32, Instance> instances = new Dictionary<Int32, Instance>();
|
||||
foreach (String instanceid in json.Keys) {
|
||||
Instance i = Instance.CreateInstance(json[instanceid], new Tuple<Int32, Int32>(this.Id, Int32.Parse(instanceid)), http, this.polling);
|
||||
Instance i = Instance.CreateInstance(json[instanceid], (this.Id, Int32.Parse(instanceid)), http, this.polling, (this.Name, names));
|
||||
if (i != null) {
|
||||
instances.Add(Int32.Parse(instanceid), i);
|
||||
}
|
||||
@ -61,18 +67,9 @@ namespace BlubbFish.IoT.Zway.Devices {
|
||||
this.Instances = new ReadOnlyDictionary<Int32, Instance>(instances);
|
||||
}
|
||||
|
||||
internal static Device CreateDevice(JsonData json, Tuple<Int32> id, HttpConnection http, Boolean polling) {
|
||||
if(json.Keys.Contains("instances") &&
|
||||
json["instances"].Count > 0 &&
|
||||
json.Keys.Contains("data") && id.Item1 != 1) {
|
||||
return new Device(json, id, http, polling);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
internal static Device CreateDevice(JsonData json, Int32 id, HttpConnection http, Boolean polling, ReadOnlyDictionary<String, ReadOnlyDictionary<String, String>> names) => json.Keys.Contains("instances") && json["instances"].Count > 0 && json.Keys.Contains("data") && id != 1 ? new Device(json, id, http, polling, names) : null;
|
||||
|
||||
public override String ToString() {
|
||||
return this.Name+"_"+this.Id+" ["+this.Instances.Count+"]";
|
||||
}
|
||||
public override String ToString() => this.Name + "_" + this.Id + " [" + this.Instances.Count + "]";
|
||||
|
||||
internal void SetUpdate(JsonData json, Match match) {
|
||||
if (match.Groups[2].Value == "data.lastReceived") {
|
||||
|
@ -1,16 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
using BlubbFish.IoT.Zway.Devices.CommandClasses;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Devices {
|
||||
public class Instance {
|
||||
private DateTime nextwakeup;
|
||||
private Boolean polling;
|
||||
private readonly Boolean polling;
|
||||
private readonly String instanceName;
|
||||
private readonly String deviceName;
|
||||
|
||||
public delegate void UpdatedInstance(Object sender, DeviceUpdateEvent e);
|
||||
public event UpdatedInstance Update;
|
||||
@ -19,33 +23,27 @@ namespace BlubbFish.IoT.Zway.Devices {
|
||||
public Int32 InstanceId { get; }
|
||||
public ReadOnlyDictionary<ACommandClass.Classes, ACommandClass> CommandClasses { get; private set; }
|
||||
|
||||
private Instance(JsonData json, Tuple<Int32, Int32> id, HttpConnection http, Boolean polling) {
|
||||
this.DeviceId = id.Item1;
|
||||
this.InstanceId = id.Item2;
|
||||
private Instance(JsonData json, (Int32 device, Int32 instance) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) {
|
||||
this.DeviceId = id.device;
|
||||
this.InstanceId = id.instance;
|
||||
this.polling = polling;
|
||||
this.CreateInstances(json["commandClasses"], http);
|
||||
this.instanceName = name.descriptions.ContainsKey(this.InstanceId.ToString()) ? name.descriptions[this.InstanceId.ToString()] : "";
|
||||
this.deviceName = name.device;
|
||||
this.CreateClasses(json["commandClasses"], http, name);
|
||||
foreach (KeyValuePair<ACommandClass.Classes, ACommandClass> item in this.CommandClasses) {
|
||||
item.Value.Update += this.ClassUpdate;
|
||||
}
|
||||
this.MakePolltimer();
|
||||
}
|
||||
|
||||
private void MakePolltimer() {
|
||||
if(this.CommandClasses.ContainsKey(ACommandClass.Classes.Wakeup)) {
|
||||
this.nextwakeup = ((Wakeup)this.CommandClasses[ACommandClass.Classes.Wakeup]).LastWakeup.AddSeconds(((Wakeup)this.CommandClasses[ACommandClass.Classes.Wakeup]).Interval).AddSeconds(-20);
|
||||
} else {
|
||||
this.nextwakeup = DateTime.Now.AddSeconds(60);
|
||||
}
|
||||
}
|
||||
private void MakePolltimer() => this.nextwakeup = this.CommandClasses.ContainsKey(ACommandClass.Classes.Wakeup) ? ((Wakeup)this.CommandClasses[ACommandClass.Classes.Wakeup]).LastWakeup.AddSeconds(((Wakeup)this.CommandClasses[ACommandClass.Classes.Wakeup]).Interval).AddSeconds(-20) : DateTime.Now.AddSeconds(60);
|
||||
|
||||
private void ClassUpdate(Object sender, DeviceUpdateEvent e) {
|
||||
this.Update?.Invoke(this, e);
|
||||
}
|
||||
private void ClassUpdate(Object sender, DeviceUpdateEvent e) => this.Update?.Invoke(this, e);
|
||||
|
||||
private void CreateInstances(JsonData json, HttpConnection http) {
|
||||
private void CreateClasses(JsonData json, HttpConnection http, (String device, ReadOnlyDictionary<String, String> descriptions) name) {
|
||||
Dictionary<ACommandClass.Classes, ACommandClass> commands = new Dictionary<ACommandClass.Classes, ACommandClass>();
|
||||
foreach (String commandid in json.Keys) {
|
||||
ACommandClass c = ACommandClass.CreateInstance(json[commandid], new Tuple<Int32, Int32, ACommandClass.Classes>(this.DeviceId, this.InstanceId, (ACommandClass.Classes)Int32.Parse(commandid)), http, this.polling);
|
||||
ACommandClass c = ACommandClass.CreateClass(json[commandid], (this.DeviceId, this.InstanceId, (ACommandClass.Classes)Int32.Parse(commandid)), http, this.polling, name);
|
||||
if (c != null) {
|
||||
commands.Add((ACommandClass.Classes)Int32.Parse(commandid), c);
|
||||
}
|
||||
@ -53,18 +51,9 @@ namespace BlubbFish.IoT.Zway.Devices {
|
||||
this.CommandClasses = new ReadOnlyDictionary<ACommandClass.Classes, ACommandClass>(commands);
|
||||
}
|
||||
|
||||
internal static Instance CreateInstance(JsonData json, Tuple<Int32, Int32> id, HttpConnection http, Boolean polling) {
|
||||
if (json.Keys.Contains("commandClasses") &&
|
||||
json["commandClasses"].Count > 0 &&
|
||||
json.Keys.Contains("data")) {
|
||||
return new Instance(json, id, http, polling);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
internal static Instance CreateInstance(JsonData json, (Int32 device, Int32 instance) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) => json.Keys.Contains("commandClasses") && json["commandClasses"].Count > 0 && json.Keys.Contains("data") ? new Instance(json, id, http, polling, name) : null;
|
||||
|
||||
public override String ToString() {
|
||||
return "Instance: " + this.DeviceId + "-" + this.InstanceId + " [" + this.CommandClasses.Count + "]";
|
||||
}
|
||||
public override String ToString() => "Instance "+this.deviceName+""+(this.instanceName != ""?" ["+ this.instanceName +"]":"") +": " + this.DeviceId + "-" + this.InstanceId + " [" + this.CommandClasses.Count + "]";
|
||||
|
||||
internal void Poll() {
|
||||
if(DateTime.Now > this.nextwakeup) {
|
||||
|
@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Events {
|
||||
public class DeviceUpdateEvent : EventArgs {
|
||||
|
@ -2,12 +2,18 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using BlubbFish.IoT.Zway.lib.Zway;
|
||||
using BlubbFish.Utils;
|
||||
using BlubbFish.Utils.IoT.Interfaces;
|
||||
using BlubbFish.Utils.IoT.Interfaces.Language;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.Interfaces {
|
||||
public abstract class ACommandClass {
|
||||
public abstract class ACommandClass : IMqtt, ISenml {
|
||||
protected HttpConnection http;
|
||||
|
||||
public delegate void UpdatedValue(Object sender, DeviceUpdateEvent e);
|
||||
@ -20,24 +26,31 @@ namespace BlubbFish.IoT.Zway.Interfaces {
|
||||
SceneActivation = 43,
|
||||
SwitchColor = 51,
|
||||
MeterPulse = 53,
|
||||
MeterTableMonitor = 61,
|
||||
ThermostatOperatingState = 66,
|
||||
ClimateControlSchedule = 70,
|
||||
CRC16 = 86,
|
||||
AssociationGroupInformation = 89,
|
||||
DeviceResetLocally = 90,
|
||||
ZWavePlusInfo = 94,
|
||||
MultiChannel = 96,
|
||||
DoorLock = 98,
|
||||
BarrierOperator = 102,
|
||||
ManufacturerSpecific = 114,
|
||||
PowerLevel = 115,
|
||||
InclusionController = 116,
|
||||
Protection = 117,
|
||||
NodeNaming = 119,
|
||||
FirmwareUpdate = 122,
|
||||
Clock = 129,
|
||||
Association = 133,
|
||||
Version = 134,
|
||||
Proprietary = 136,
|
||||
TimeParameters = 139,
|
||||
MultiChannelAssociation = 142,
|
||||
MultiCmd = 143,
|
||||
Security = 152,
|
||||
AlarmSensor = 156 //
|
||||
SimpleAVControl = 148,
|
||||
Security = 152
|
||||
}
|
||||
|
||||
public enum Classes : Int32 {
|
||||
@ -54,9 +67,11 @@ namespace BlubbFish.IoT.Zway.Interfaces {
|
||||
Alarm = 113,
|
||||
Battery = 128,
|
||||
Wakeup = 132,
|
||||
Indicator = 135
|
||||
Indicator = 135,
|
||||
AlarmSensor = 156
|
||||
}
|
||||
|
||||
#region Properties
|
||||
public Int32 DeviceId { get; }
|
||||
public Int32 Instance { get; }
|
||||
public Classes Commandclass { get; }
|
||||
@ -70,14 +85,14 @@ namespace BlubbFish.IoT.Zway.Interfaces {
|
||||
public Boolean HasSub { get; protected set; }
|
||||
public Boolean IsSub { get; protected set; }
|
||||
public Boolean HasReset { get; protected set; }
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
protected ACommandClass(JsonData json, Tuple<Int32, Int32, Classes, Int32> id, HttpConnection http, Boolean polling) {
|
||||
this.DeviceId = id.Item1;
|
||||
this.Instance = id.Item2;
|
||||
this.Commandclass = id.Item3;
|
||||
this.SensorId = id.Item4;
|
||||
protected ACommandClass((Int32 device, Int32 instance, Classes commandclass, Int32 sensor) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) {
|
||||
this.DeviceId = id.device;
|
||||
this.Instance = id.instance;
|
||||
this.Commandclass = id.commandclass;
|
||||
this.SensorId = id.sensor;
|
||||
this.http = http;
|
||||
this.LastUpdate = DateTime.Now;
|
||||
this.Polling = polling;
|
||||
@ -85,15 +100,12 @@ namespace BlubbFish.IoT.Zway.Interfaces {
|
||||
this.HasReset = false;
|
||||
this.IsSub = false;
|
||||
this.Id = this.DeviceId + "-" + this.Instance + "-" + (Int32)this.Commandclass + "-" + this.SensorId;
|
||||
if (ZwayController.namelist.ContainsKey(this.Id)) {
|
||||
this.Name = ZwayController.namelist[this.Id];
|
||||
}
|
||||
this.Name = name.descriptions.ContainsKey(this.Instance + "-" + (Int32)this.Commandclass + "-" + this.SensorId) ? name.device + " " + name.descriptions[this.Instance + "-" + (Int32)this.Commandclass + "-" + this.SensorId] : name.device + " " + this.Instance + "-" + this.Commandclass;
|
||||
}
|
||||
|
||||
protected ACommandClass(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) {
|
||||
this.DeviceId = id.Item1;
|
||||
this.Instance = id.Item2;
|
||||
this.Commandclass = id.Item3;
|
||||
protected ACommandClass((Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) {
|
||||
this.DeviceId = id.device;
|
||||
this.Instance = id.instance;
|
||||
this.Commandclass = id.commandclass;
|
||||
this.http = http;
|
||||
this.LastUpdate = DateTime.Now;
|
||||
this.Polling = polling;
|
||||
@ -101,67 +113,53 @@ namespace BlubbFish.IoT.Zway.Interfaces {
|
||||
this.HasReset = false;
|
||||
this.IsSub = false;
|
||||
this.Id = this.DeviceId + "-" + this.Instance + "-" + (Int32)this.Commandclass;
|
||||
if (ZwayController.namelist.ContainsKey(this.Id)) {
|
||||
this.Name = ZwayController.namelist[this.Id];
|
||||
}
|
||||
this.Name = name.descriptions.ContainsKey(this.Instance + "-" + (Int32)this.Commandclass) ? name.device + " " + name.descriptions[this.Instance + "-" + (Int32)this.Commandclass] : name.device + " " + this.Instance + "-" + this.Commandclass;
|
||||
}
|
||||
|
||||
internal static ACommandClass CreateInstance(JsonData json, Tuple<Int32, Int32, Classes> id, HttpConnection http, Boolean polling) {
|
||||
if (json.Keys.Contains("name") &&
|
||||
internal static ACommandClass CreateClass(JsonData json, (Int32 device, Int32 instance, Classes commandclass) id, HttpConnection http, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) {
|
||||
if (json.Keys.Contains("name") &&
|
||||
json.Keys.Contains("data") &&
|
||||
json["data"].Keys.Contains("supported") &&
|
||||
json["data"]["supported"].Keys.Contains("value") &&
|
||||
Boolean.Parse(json["data"]["supported"]["value"].ToString()) &&
|
||||
!Enum.IsDefined(typeof(IgnoredClasses), (Int32)id.Item3) && Enum.IsDefined(typeof(Classes), id.Item3)) {
|
||||
String name = id.Item3.ToString();
|
||||
String objectName = "BlubbFish.IoT.Zway.Devices.CommandClasses." + name[0].ToString().ToUpper() + name.Substring(1).ToLower();
|
||||
return GetInstanceConcrete(objectName, json, http, id, polling);
|
||||
!Enum.IsDefined(typeof(IgnoredClasses), (Int32)id.commandclass) && Enum.IsDefined(typeof(Classes), id.commandclass)) {
|
||||
String objectName = "BlubbFish.IoT.Zway.Devices.CommandClasses." + id.commandclass.ToString().ToUpperLower();
|
||||
return GetInstanceConcrete(objectName, json, http, id, polling, name);
|
||||
}
|
||||
if (!Enum.IsDefined(typeof(IgnoredClasses), (Int32)id.Item3) && !Enum.IsDefined(typeof(Classes), id.Item3)) {
|
||||
Helper.WriteError("CommandClass " + id.Item3 + " not exist.");
|
||||
if (!Enum.IsDefined(typeof(IgnoredClasses), (Int32)id.commandclass) && !Enum.IsDefined(typeof(Classes), id.commandclass)) {
|
||||
Helper.WriteError("CommandClass " + id.commandclass + " not exist. (" + id.device + ", " + id.instance + ")");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ACommandClass GetInstanceConcrete(String objectName, JsonData json, HttpConnection http, Tuple<Int32, Int32, Classes> id, Boolean polling) {
|
||||
Type t = null;
|
||||
private static ACommandClass GetInstanceConcrete(String objectName, JsonData json, HttpConnection http, (Int32 device, Int32 instance, Classes commandclass) id, Boolean polling, (String device, ReadOnlyDictionary<String, String> descriptions) name) {
|
||||
try {
|
||||
t = Type.GetType(objectName, true);
|
||||
Type t = Type.GetType(objectName, true);
|
||||
return (ACommandClass)t.GetConstructor(new Type[] { typeof(JsonData), typeof((Int32 device, Int32 instance, Classes commandclass)), typeof(HttpConnection), typeof(Boolean), typeof((String device, ReadOnlyDictionary<String, String> descriptions)) }).Invoke(new Object[] { json, id, http, polling, name });
|
||||
} catch (TypeLoadException) {
|
||||
Console.Error.WriteLine("Konnte Type " + objectName + " nicht laden!");
|
||||
return null;
|
||||
}
|
||||
return (ACommandClass)t.GetConstructor(new Type[] { typeof(JsonData), typeof(Tuple<Int32, Int32, Classes>), typeof(HttpConnection), typeof(Boolean) }).Invoke(new Object[] { json, id, http, polling });
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Polling
|
||||
|
||||
internal virtual void Poll() {
|
||||
if (this.Polling || this.PollOnce) {
|
||||
this.PollOnce = false;
|
||||
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Get()");
|
||||
this.http.GetVoid("/ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Get()");
|
||||
}
|
||||
}
|
||||
|
||||
protected void PollNone() {
|
||||
this.PollOnce = false;
|
||||
}
|
||||
|
||||
protected void PollNone() => this.PollOnce = false;
|
||||
protected void PollSub() {
|
||||
if (this.Polling || this.PollOnce) {
|
||||
this.PollOnce = false;
|
||||
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Get(" + this.SensorId + ")");
|
||||
this.http.GetVoid("/ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Get(" + this.SensorId + ")");
|
||||
}
|
||||
}
|
||||
|
||||
protected void PollPerSub() {
|
||||
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
|
||||
item.Value.Poll();
|
||||
}
|
||||
}
|
||||
|
||||
protected void PollSubGlobal() {
|
||||
Boolean poll = false;
|
||||
Boolean pollonce = false;
|
||||
@ -174,26 +172,15 @@ namespace BlubbFish.IoT.Zway.Interfaces {
|
||||
}
|
||||
}
|
||||
if (poll || pollonce) {
|
||||
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Get()");
|
||||
this.http.GetVoid("/ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Get()");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region SetValues
|
||||
|
||||
protected void SetInt(Int32 value) {
|
||||
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Set(" + value + ")");
|
||||
}
|
||||
|
||||
protected void SetTuple(Double value1, Double value2) {
|
||||
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Set(" + value1 + "," + value2 + ")");
|
||||
}
|
||||
|
||||
protected void SetTriple(Double v1, Double v2, Double v3) {
|
||||
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Set(" + v1 + "," + v2 + "," + v3 + ")");
|
||||
}
|
||||
|
||||
protected void SetInt(Int32 value) => this.http.GetVoid("/ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Set(" + value + ")");
|
||||
protected void SetTuple((Double, Double) value) => this.http.GetVoid("/ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Set(" + value.Item1 + "," + value.Item2 + ")");
|
||||
protected void SetTriple((Double, Double, Double) value) => this.http.GetVoid("/ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Set(" + value.Item1 + "," + value.Item2 + "," + value.Item3 + ")");
|
||||
protected Boolean CheckSetUpdateTime(JsonData json) {
|
||||
if (json.Keys.Contains("updateTime") && (json["updateTime"].IsInt || json["updateTime"].IsLong)) {
|
||||
DateTime newdate = DateTimeOffset.FromUnixTimeSeconds(Int64.Parse(json["updateTime"].ToString())).ToLocalTime().DateTime;
|
||||
@ -207,31 +194,14 @@ namespace BlubbFish.IoT.Zway.Interfaces {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Reset() {
|
||||
if (this.HasReset) {
|
||||
this.http.GetVoid("ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Reset()");
|
||||
this.http.GetVoid("/ZWave.zway/Run/devices[" + this.DeviceId + "].instances[" + this.Instance + "].commandClasses[" + ((Int32)this.Commandclass).ToString() + "].Reset()");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Output
|
||||
|
||||
public String MqttTopic() {
|
||||
return this.DeviceId + "/" + this.Instance + "/" + ((Int32)this.Commandclass).ToString() + (this.IsSub ? "/" + this.SensorId : "");
|
||||
}
|
||||
|
||||
public String ToJson() {
|
||||
Dictionary<String, Object> json = this.ToDictionary();
|
||||
json.Add("LastUpdate", this.LastUpdate.ToString());
|
||||
json.Add("Name", this.Name);
|
||||
json.Add("Commandclass", this.Commandclass.ToString());
|
||||
return JsonMapper.ToJson(json);
|
||||
}
|
||||
|
||||
public abstract Dictionary<String, Object> ToDictionary();
|
||||
|
||||
#region InternalHelper
|
||||
protected Dictionary<String, Object> ToDictionarySub() {
|
||||
Dictionary<String, Object> json = new Dictionary<String, Object>();
|
||||
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
|
||||
@ -239,9 +209,46 @@ namespace BlubbFish.IoT.Zway.Interfaces {
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
protected List<Senml> ToSenmlListSub() {
|
||||
List<Senml> list = new List<Senml>();
|
||||
foreach (KeyValuePair<Int32, ACommandClass> item in this.Sub) {
|
||||
list.AddRange(item.Value.ToSenmlList());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IMqtt
|
||||
public String MqttTopic() => this.DeviceId + "/" + this.Instance + "/" + ((Int32)this.Commandclass).ToString() + (this.IsSub ? "/" + this.SensorId : "");
|
||||
public String ToJson() {
|
||||
Dictionary<String, Object> json = this.ToDictionary();
|
||||
json.Add("LastUpdate", this.LastUpdate.ToString());
|
||||
json.Add("Name", this.Name);
|
||||
json.Add("Commandclass", this.Commandclass.ToString());
|
||||
return JsonMapper.ToJson(json);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ISenml
|
||||
public String SenmlTopic() => "LS/v2/ZGW/";
|
||||
public String ToSenml() {
|
||||
List<Senml> l = this.ToSenmlList();
|
||||
if(l.Count == 0) {
|
||||
return null;
|
||||
}
|
||||
Dictionary<String, Object> json = new Dictionary<String, Object> {
|
||||
{ "e", l },
|
||||
{ "bn", this.DeviceId + "/" + this.Instance + "/" + ((Int32)this.Commandclass).ToString() + (this.IsSub ? "/" + this.SensorId : "") + "/" },
|
||||
{ "bt", ((DateTimeOffset)this.LastUpdate).ToUnixTimeSeconds() }
|
||||
};
|
||||
return JsonMapper.ToJson(json);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Abstract
|
||||
protected abstract List<Senml> ToSenmlList();
|
||||
public abstract Dictionary<String, Object> ToDictionary();
|
||||
internal abstract void SetUpdate(JsonData json, Match match);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -1,36 +0,0 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die einer Assembly zugeordnet sind.
|
||||
[assembly: AssemblyTitle("Zway")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("Zway")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017 - 22.12.2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
||||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("166258ed-cb3d-43f5-8e8d-3a993b64d022")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
||||
// indem Sie "*" wie unten gezeigt eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.3.5.0")]
|
||||
[assembly: AssemblyFileVersion("1.3.5.0")]
|
128
Zway/Zway.csproj
128
Zway/Zway.csproj
@ -1,81 +1,67 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{166258ED-CB3D-43F5-8E8D-3A993B64D022}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<RootNamespace>BlubbFish.IoT.Zway</RootNamespace>
|
||||
<AssemblyName>Zway</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PackageId>Zway.IoT.BlubbFish</PackageId>
|
||||
<Version>1.6.1</Version>
|
||||
<NeutralLanguage>de-DE</NeutralLanguage>
|
||||
<Description>Library that speaks with zwave module/server</Description>
|
||||
<Authors>BlubbFish</Authors>
|
||||
<Company>BlubbFish</Company>
|
||||
<Copyright>Copyright © 2017 - 20.01.2022</Copyright>
|
||||
<PackageLicenseFile>LICENCE</PackageLicenseFile>
|
||||
<PackageProjectUrl>https://git.blubbfish.net/vs_projects/Zway</PackageProjectUrl>
|
||||
<RepositoryUrl>https://git.blubbfish.net/vs_projects/Zway.git</RepositoryUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageReleaseNotes>
|
||||
1.6.1 - 2022-01-20 - Dispose bug in netcore
|
||||
1.6.0 - 2022-01-15 - Refactoring is the key
|
||||
1.5.1 - 2018-10-29 - Tiny fix for nullpointer exception
|
||||
1.5.0 - 2018-09-29 - Throw Exception if 3 times failed to connect to Raspberry server, add 3 new commandlcasses to IgnoredClasses
|
||||
1.4.4 - 2018-06-02 - Ignore Inclusioncontroller
|
||||
1.4.3 - 2018-05-12 - Fixing Issue with Math.Abs(l)
|
||||
1.4.2.0 - 2018-05-10 - Some sensors make wrong measurements near 0 not exactly 0, so ABS(value) >= 0.1 is alse false
|
||||
1.4.1.0 - 2018-05-07 - fixing Senml topics and data
|
||||
1.4.0.0 - 2018-05-03 - Create Senml Messages for Linksmart
|
||||
1.3.6.0 - 2018-01-01 - Better levelcheck and Alarmsensor added
|
||||
1.3.5.3 - 2017-12-25 - Change Level to numeric and create State for Bollean values, because telegraf only parse numeric
|
||||
1.3.5.2 - 2017-12-24 - Check to avoid megapeaks in data now also for temperature
|
||||
1.3.5.1 - 2017-12-23 - Check to avoid megapeaks in Data
|
||||
1.3.5.0 - 2017-12-22 - Add Alarm and SceneControllerConf
|
||||
1.3.4.1 - 2017-12-21 - SensorBinary and Fixing
|
||||
1.3.4.0 - 2017-12-19 - Fixing Json Names
|
||||
1.3.3.0 - 2017-12-19 - fixing polling once bug
|
||||
1.3.2.0 - 2017-12-18 - Forgot some settings, now configuration setting also works again
|
||||
1.3.1.0 - 2017-12-17 - Tiny fix for mqtt
|
||||
1.3.0.0 - 2017-12-17 - Simpler CommandClass
|
||||
1.2.0.0 - 2017-12-06 - F4G Faker
|
||||
1.1.2.0 - 2017-12-03 - Tiny Fix
|
||||
1.1.1.0 - 2017-11-25 - Massive improvement
|
||||
1.1.0.0 - 2017-11-20 - First working Version
|
||||
1.0.0.0 - 2017-10-29 - Init
|
||||
</PackageReleaseNotes>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="LitJson, Version=0.9.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\IoT-Bot\packages\LitJson.0.9.0\lib\LitJson.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
<ProjectReference Include="..\..\Librarys\litjson\litjson\litjson.csproj" />
|
||||
<ProjectReference Include="..\..\Utils\Iot-Interfaces\Iot-Interfaces\Iot-Interfaces.csproj" />
|
||||
<ProjectReference Include="..\..\Utils\Utils\Utils\Utils.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Devices\CommandClasses\Alarm.cs" />
|
||||
<Compile Include="Devices\CommandClasses\Battery.cs" />
|
||||
<Compile Include="Devices\CommandClasses\CommandClassSubs\Configurationsub.cs" />
|
||||
<Compile Include="Devices\CommandClasses\CommandClassSubs\SceneControllerConfSub.cs" />
|
||||
<Compile Include="Devices\CommandClasses\CommandClassSubs\SensorBinarySub.cs" />
|
||||
<Compile Include="Devices\CommandClasses\CommandClassSubs\ThermostatSetPointSub.cs" />
|
||||
<Compile Include="Devices\CommandClasses\Configuration.cs" />
|
||||
<Compile Include="Devices\CommandClasses\Indicator.cs" />
|
||||
<Compile Include="Devices\CommandClasses\Meter.cs" />
|
||||
<Compile Include="Devices\CommandClasses\CommandClassSubs\MeterSub.cs" />
|
||||
<Compile Include="Devices\CommandClasses\CommandClassSubs\SensorMultilevelSub.cs" />
|
||||
<Compile Include="Devices\CommandClasses\SceneControllerConf.cs" />
|
||||
<Compile Include="Devices\CommandClasses\SensorBinary.cs" />
|
||||
<Compile Include="Devices\CommandClasses\Wakeup.cs" />
|
||||
<Compile Include="Devices\Device.cs" />
|
||||
<Compile Include="Interfaces\ACommandClass.cs" />
|
||||
<Compile Include="Devices\Instance.cs" />
|
||||
<Compile Include="Devices\CommandClasses\CentralScene.cs" />
|
||||
<Compile Include="Devices\CommandClasses\SensorMultilevel.cs" />
|
||||
<Compile Include="Devices\CommandClasses\SwitchBinary.cs" />
|
||||
<Compile Include="Devices\CommandClasses\ThermostatMode.cs" />
|
||||
<Compile Include="Devices\CommandClasses\SwitchMultilevel.cs" />
|
||||
<Compile Include="Devices\CommandClasses\ThermostatSetPoint.cs" />
|
||||
<Compile Include="Events\DeviceUpdateEvent.cs" />
|
||||
<Compile Include="Exceptions\ZwayExceptions.cs" />
|
||||
<Compile Include="lib\Helper.cs" />
|
||||
<Compile Include="lib\HttpClient.cs" />
|
||||
<Compile Include="ZwayController.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Content Include="../CHANGELOG.md" />
|
||||
<Content Include="../CONTRIBUTING.md" />
|
||||
<Content Include="../LICENSE" />
|
||||
<Content Include="../README.md" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
|
||||
</Project>
|
||||
|
@ -1,193 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
|
||||
using BlubbFish.IoT.Zway.Devices;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.IoT.Zway.lib;
|
||||
using LitJson;
|
||||
using BlubbFish.Utils;
|
||||
|
||||
namespace BlubbFish.IoT.Zway {
|
||||
public class ZwayController : IDisposable {
|
||||
private HttpConnection http;
|
||||
private Thread updatethread;
|
||||
private Thread pollthread;
|
||||
public static ReadOnlyDictionary<String, String> namelist;
|
||||
private Boolean polling;
|
||||
private ZwayBoard zwayboard;
|
||||
private Boolean _IsInit = false;
|
||||
|
||||
public delegate void DataUpdate(Object sender, DeviceUpdateEvent e);
|
||||
public event DataUpdate Update;
|
||||
public event DataUpdate Recieved;
|
||||
|
||||
public ReadOnlyDictionary<Int32, Device> Devices { get; private set; }
|
||||
|
||||
public ZwayController(String server, String user, String pass, Dictionary<String, String> names, Boolean enablePoll = true) {
|
||||
namelist = new ReadOnlyDictionary<String, String>(names);
|
||||
this.polling = enablePoll;
|
||||
this.Connect(server, user, pass);
|
||||
}
|
||||
|
||||
public ZwayController(Dictionary<String, String> settings, Dictionary<String, String> names, Boolean enablePoll = true) {
|
||||
namelist = new ReadOnlyDictionary<String, String>(names);
|
||||
this.polling = enablePoll;
|
||||
this.Connect(settings["server"], settings["user"], settings["pass"]);
|
||||
}
|
||||
|
||||
private void Connect(String server, String user, String pass) {
|
||||
this.http = new HttpConnection(server, user, pass);
|
||||
CultureInfo info = new CultureInfo("de-DE");
|
||||
info.NumberFormat.NumberDecimalSeparator = ".";
|
||||
CultureInfo.DefaultThreadCurrentCulture = info;
|
||||
CultureInfo.DefaultThreadCurrentUICulture = info;
|
||||
Thread.CurrentThread.CurrentCulture = info;
|
||||
Thread.CurrentThread.CurrentUICulture = info;
|
||||
this.CreateDevices(this.http.GetJson("ZWaveAPI/Run/devices"));
|
||||
this.updatethread = new Thread(this.Updater);
|
||||
this.updatethread.Start();
|
||||
this.pollthread = new Thread(this.Poll);
|
||||
this.pollthread.Start();
|
||||
foreach (KeyValuePair<Int32, Device> item in this.Devices) {
|
||||
item.Value.Update += this.DeviceUpdate;
|
||||
public ZwayController(Dictionary<String, String> settings, Dictionary<String, ReadOnlyDictionary<String, String>> names, Boolean enablePoll = true) {
|
||||
try {
|
||||
Console.WriteLine("BlubbFish.IoT.Zway.ZwayController.Construct()");
|
||||
this.zwayboard = ZwayBoard.GetInstance(settings, new ReadOnlyDictionary<String, ReadOnlyDictionary<String, String>>(names), enablePoll);
|
||||
this.zwayboard.Connect();
|
||||
this.zwayboard.Update += this.DeviceUpdate;
|
||||
this._IsInit = true;
|
||||
} catch(Exception e) {
|
||||
Helper.WriteError("Error while Loading BlubbFish.IoT.Zway.ZwayController.ZwayController: " + e.Message + "\n\n" + e.StackTrace);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) {
|
||||
this.Update?.Invoke(sender, e);
|
||||
}
|
||||
public ACommandClass GetCommandClass(String id) => this.zwayboard.GetCommandClass(id);
|
||||
public ReadOnlyDictionary<Int32, Device> Devices => this.zwayboard.Devices;
|
||||
|
||||
private void Poll() {
|
||||
CultureInfo info = new CultureInfo("de-DE");
|
||||
info.NumberFormat.NumberDecimalSeparator = ".";
|
||||
CultureInfo.DefaultThreadCurrentCulture = info;
|
||||
CultureInfo.DefaultThreadCurrentUICulture = info;
|
||||
Thread.CurrentThread.CurrentCulture = info;
|
||||
Thread.CurrentThread.CurrentUICulture = info;
|
||||
while(true) {
|
||||
foreach (KeyValuePair<Int32, Device> item in this.Devices) {
|
||||
item.Value.Poll();
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
|
||||
public ACommandClass GetCommandClass(String id) {
|
||||
String[] addr = id.Split('-');
|
||||
if (addr.Length == 3 || addr.Length == 4) {
|
||||
return this.GetCommandClass(Int32.Parse(addr[0]), Int32.Parse(addr[1]), (ACommandClass.Classes)Int32.Parse(addr[2]), (addr.Length == 4 ? Int32.Parse(addr[3]) : -1));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ACommandClass GetCommandClass(Int32 deviceid, Int32 instanceid, ACommandClass.Classes classid, Int32 subcid = -1) {
|
||||
if(this.Devices.ContainsKey(deviceid) && this.Devices[deviceid].Instances.ContainsKey(instanceid) && this.Devices[deviceid].Instances[instanceid].CommandClasses.ContainsKey(classid)) {
|
||||
ACommandClass commandclass = this.Devices[deviceid].Instances[instanceid].CommandClasses[classid];
|
||||
if(subcid == -1) {
|
||||
return commandclass;
|
||||
}
|
||||
if (commandclass != null) {
|
||||
if(commandclass.HasSub) {
|
||||
if(commandclass.Sub.ContainsKey(subcid)) {
|
||||
return commandclass.Sub[subcid];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void Updater() {
|
||||
CultureInfo info = new CultureInfo("de-DE");
|
||||
info.NumberFormat.NumberDecimalSeparator = ".";
|
||||
CultureInfo.DefaultThreadCurrentCulture = info;
|
||||
CultureInfo.DefaultThreadCurrentUICulture = info;
|
||||
Thread.CurrentThread.CurrentCulture = info;
|
||||
Thread.CurrentThread.CurrentUICulture = info;
|
||||
while (true) {
|
||||
Int64 date = ((DateTimeOffset)DateTime.Now.AddSeconds(-2)).ToUnixTimeSeconds();
|
||||
JsonData notifications = this.http.GetJson("ZWave.zway/Data/"+date);
|
||||
foreach (String item in notifications.Keys) {
|
||||
Match match = new Regex("^devices\\.([0-9]+)\\.instances\\.([0-9]+)\\.commandClasses\\.([0-9]+)(\\.data\\.([0-9]+)|\\.data\\.[a-z].*|\\.data)$", RegexOptions.IgnoreCase).Match(item);
|
||||
if(match.Success) {
|
||||
Int32 deviceid = Int32.Parse(match.Groups[1].Value);
|
||||
Int32 instanceid = Int32.Parse(match.Groups[2].Value);
|
||||
ACommandClass.Classes commandid = (ACommandClass.Classes)Int32.Parse(match.Groups[3].Value);
|
||||
if (this.Devices.ContainsKey(deviceid) && this.Devices[deviceid].Instances.ContainsKey(instanceid) && this.Devices[deviceid].Instances[instanceid].CommandClasses.ContainsKey(commandid)) {
|
||||
this.Devices[deviceid].Instances[instanceid].CommandClasses[commandid].SetUpdate(notifications[item], match);
|
||||
}
|
||||
} /*else {
|
||||
if(item.StartsWith("controller.")) { }
|
||||
else if(item == "updateTime") { }
|
||||
else {
|
||||
match = new Regex("^devices\\.([0-9]+)\\.(data.*)", RegexOptions.IgnoreCase).Match(item);
|
||||
if(!match.Success) {
|
||||
|
||||
}
|
||||
}
|
||||
}*/
|
||||
match = new Regex("^devices\\.([0-9]+)\\.(data.*)", RegexOptions.IgnoreCase).Match(item);
|
||||
if(match.Success) {
|
||||
Int32 deviceid = Int32.Parse(match.Groups[1].Value);
|
||||
if (this.Devices.ContainsKey(deviceid)) {
|
||||
this.Devices[deviceid].SetUpdate(notifications[item], match);
|
||||
}
|
||||
}
|
||||
}
|
||||
Thread.Sleep(1500);
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateDevices(JsonData json) {
|
||||
Dictionary<Int32, Device> devices = new Dictionary<Int32, Device>();
|
||||
foreach (String deviceid in json.Keys) {
|
||||
Device d = Device.CreateDevice(json[deviceid], new Tuple<Int32>(Int32.Parse(deviceid)), this.http, this.polling);
|
||||
if (d != null) {
|
||||
devices.Add(Int32.Parse(deviceid), d);
|
||||
}
|
||||
}
|
||||
this.Devices = new ReadOnlyDictionary<Int32, Device>(devices);
|
||||
}
|
||||
|
||||
public Dictionary<String, ACommandClass> GetCommandClasses(ACommandClass.Classes classes) {
|
||||
Dictionary<String, ACommandClass> ret = new Dictionary<String, ACommandClass>();
|
||||
foreach (KeyValuePair<Int32, Device> device in this.Devices) {
|
||||
foreach (KeyValuePair<Int32, Instance> instance in device.Value.Instances) {
|
||||
foreach (KeyValuePair<ACommandClass.Classes, ACommandClass> commandclass in instance.Value.CommandClasses) {
|
||||
if (commandclass.Key == classes) {
|
||||
ret.Add(commandclass.Value.Id, commandclass.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#region IDisposable Support
|
||||
private Boolean disposedValue = false;
|
||||
|
||||
protected virtual void Dispose(Boolean disposing) {
|
||||
if (!this.disposedValue) {
|
||||
if (disposing) {
|
||||
this.updatethread.Abort();
|
||||
this.pollthread.Abort();
|
||||
}
|
||||
this.updatethread = null;
|
||||
this.pollthread = null;
|
||||
this.Devices = null;
|
||||
this.disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
~ZwayController() {
|
||||
Dispose(false);
|
||||
}
|
||||
private void DeviceUpdate(Object sender, DeviceUpdateEvent e) => this.Recieved?.Invoke(sender, e);
|
||||
|
||||
public void Dispose() {
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
if(this._IsInit) {
|
||||
Console.WriteLine("BlubbFish.IoT.Zway.ZwayController.Dispose()");
|
||||
this._IsInit = false;
|
||||
this.zwayboard.Dispose();
|
||||
this.zwayboard = null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.lib {
|
||||
class Helper {
|
||||
internal static void WriteError(String text) {
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.Error.WriteLine("ERROR: "+text);
|
||||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.lib {
|
||||
public class HttpConnection {
|
||||
private String auth;
|
||||
private String server;
|
||||
private Object getLock = new Object();
|
||||
|
||||
internal HttpConnection(String server, String user, String pass) {
|
||||
this.auth = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(user + ":" + pass));
|
||||
this.server = "http://" + server + ":8083/";
|
||||
this.Init();
|
||||
}
|
||||
|
||||
private void Init() {
|
||||
this.GetString("ZAutomation/api/v1/status");
|
||||
}
|
||||
|
||||
internal JsonData GetJson(String v) {
|
||||
String text = this.GetString(v);
|
||||
if(text == null) {
|
||||
return new JsonData();
|
||||
}
|
||||
try {
|
||||
return JsonMapper.ToObject(text);
|
||||
} catch(Exception) {
|
||||
return new JsonData();
|
||||
}
|
||||
}
|
||||
|
||||
internal void GetVoid(String v) {
|
||||
this.GetString(v, false);
|
||||
}
|
||||
|
||||
private String GetString(String v, Boolean withoutput = true) {
|
||||
String ret = null;
|
||||
lock (this.getLock) {
|
||||
HttpWebRequest request = WebRequest.CreateHttp(this.server + v);
|
||||
request.Timeout = 5000;
|
||||
request.Headers.Add(HttpRequestHeader.Authorization, this.auth);
|
||||
try {
|
||||
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
|
||||
if (response.StatusCode == HttpStatusCode.Unauthorized) {
|
||||
Console.Error.WriteLine("Benutzer oder Passwort falsch!");
|
||||
throw new Exceptions.ConnectionException("Benutzer oder Passwort falsch!");
|
||||
}
|
||||
if (withoutput) {
|
||||
StreamReader reader = new StreamReader(response.GetResponseStream());
|
||||
ret = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Helper.WriteError("Konnte keine Verbindung zum Razzbery Server herstellen. Resource: \"" + this.server + v + "\" Fehler: " + e.Message);
|
||||
return null;
|
||||
//throw new Exceptions.ConnectionException("Konnte keine Verbindung zum Razzbery Server herstellen: " + e.Message);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
61
Zway/lib/Zway/HttpClient.cs
Normal file
61
Zway/lib/Zway/HttpClient.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using BlubbFish.Utils;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.lib.Zway {
|
||||
public class HttpConnection {
|
||||
private readonly HttpEndpoint http;
|
||||
|
||||
internal HttpConnection(String server, String user, String pass) {
|
||||
this.http = new HttpEndpoint("http://" + server, ("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes(user + ":" + pass))));
|
||||
this.Init();
|
||||
}
|
||||
|
||||
private void Init() => this.http.RequestString("/ZAutomation/api/v1/status", "", false).Wait();
|
||||
|
||||
internal async Task<JsonData> GetJson(String v) {
|
||||
String text = null;
|
||||
for (Int32 i = 0; i < 3; i++) {
|
||||
try {
|
||||
text = await this.http.RequestString(v);
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
Helper.WriteError(e.Message);
|
||||
if(i==2) {
|
||||
throw;
|
||||
}
|
||||
System.Threading.Thread.Sleep(30000);
|
||||
}
|
||||
}
|
||||
if(text == null) {
|
||||
return new JsonData();
|
||||
}
|
||||
try {
|
||||
return JsonMapper.ToObject(text);
|
||||
} catch(Exception) {
|
||||
return new JsonData();
|
||||
}
|
||||
}
|
||||
|
||||
internal async void GetVoid(String address) {
|
||||
for (Int32 i = 0; i < 3; i++) {
|
||||
try {
|
||||
_ = await this.http.RequestString(address, "", false);
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
Helper.WriteError(e.Message);
|
||||
if (i == 2) {
|
||||
throw;
|
||||
}
|
||||
System.Threading.Thread.Sleep(30000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
168
Zway/lib/Zway/Zway.cs
Normal file
168
Zway/lib/Zway/Zway.cs
Normal file
@ -0,0 +1,168 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
|
||||
using BlubbFish.IoT.Zway.Devices;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
|
||||
using LitJson;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.lib.Zway {
|
||||
class Zway : ZwayBoard {
|
||||
private HttpConnection http;
|
||||
private Thread updatethread;
|
||||
private Boolean updatethreadRunning = false;
|
||||
private Thread pollthread;
|
||||
private Boolean pollthreadRunning = false;
|
||||
|
||||
#region abstract functions
|
||||
public Zway(Dictionary<String, String> settings, ReadOnlyDictionary<String, ReadOnlyDictionary<String, String>> names, Boolean enablePoll) : base(settings, names, enablePoll) {
|
||||
}
|
||||
public override void Connect() {
|
||||
this.http = new HttpConnection(this.config["server"], this.config["user"], this.config["pass"]);
|
||||
CultureInfo info = new CultureInfo("de-DE");
|
||||
info.NumberFormat.NumberDecimalSeparator = ".";
|
||||
CultureInfo.DefaultThreadCurrentCulture = info;
|
||||
CultureInfo.DefaultThreadCurrentUICulture = info;
|
||||
Thread.CurrentThread.CurrentCulture = info;
|
||||
Thread.CurrentThread.CurrentUICulture = info;
|
||||
this.CreateDevices(this.http.GetJson("/ZWaveAPI/Run/devices").Result);
|
||||
this.updatethread = new Thread(this.Updater);
|
||||
this.updatethreadRunning = true;
|
||||
this.updatethread.Start();
|
||||
this.pollthread = new Thread(this.Poll);
|
||||
this.pollthreadRunning = true;
|
||||
this.pollthread.Start();
|
||||
foreach(KeyValuePair<Int32, Device> item in this.Devices) {
|
||||
item.Value.Update += this.DeviceUpdate;
|
||||
}
|
||||
}
|
||||
public override void Dispose() {
|
||||
this.updatethreadRunning = false;
|
||||
while(this.updatethread != null && this.updatethread.IsAlive) {
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
this.updatethread = null;
|
||||
|
||||
this.pollthreadRunning = false;
|
||||
while(this.pollthread != null && this.pollthread.IsAlive) {
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
this.pollthread = null;
|
||||
|
||||
this.Devices = null;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Threaded runners
|
||||
private void Updater() {
|
||||
CultureInfo info = new CultureInfo("de-DE");
|
||||
info.NumberFormat.NumberDecimalSeparator = ".";
|
||||
CultureInfo.DefaultThreadCurrentCulture = info;
|
||||
CultureInfo.DefaultThreadCurrentUICulture = info;
|
||||
Thread.CurrentThread.CurrentCulture = info;
|
||||
Thread.CurrentThread.CurrentUICulture = info;
|
||||
DateTime lastRequest = DateTime.Now.AddSeconds(-2);
|
||||
while(this.updatethreadRunning) {
|
||||
Int64 date = ((DateTimeOffset)lastRequest).ToUnixTimeSeconds();
|
||||
lastRequest = DateTime.Now;
|
||||
JsonData notifications = this.http.GetJson("/ZWave.zway/Data/" + date).Result;
|
||||
foreach(String item in notifications.Keys) {
|
||||
Match match = new Regex("^devices\\.([0-9]+)\\.instances\\.([0-9]+)\\.commandClasses\\.([0-9]+)(\\.data\\.([0-9]+)|\\.data\\.[a-z].*|\\.data)$", RegexOptions.IgnoreCase).Match(item);
|
||||
if(match.Success) {
|
||||
Int32 deviceid = Int32.Parse(match.Groups[1].Value);
|
||||
Int32 instanceid = Int32.Parse(match.Groups[2].Value);
|
||||
ACommandClass.Classes commandid = (ACommandClass.Classes)Int32.Parse(match.Groups[3].Value);
|
||||
if(this.Devices.ContainsKey(deviceid) && this.Devices[deviceid].Instances.ContainsKey(instanceid) && this.Devices[deviceid].Instances[instanceid].CommandClasses.ContainsKey(commandid)) {
|
||||
this.Devices[deviceid].Instances[instanceid].CommandClasses[commandid].SetUpdate(notifications[item], match);
|
||||
}
|
||||
} /*else {
|
||||
if(item.StartsWith("controller.")) { }
|
||||
else if(item == "updateTime") { }
|
||||
else {
|
||||
match = new Regex("^devices\\.([0-9]+)\\.(data.*)", RegexOptions.IgnoreCase).Match(item);
|
||||
if(!match.Success) {
|
||||
|
||||
}
|
||||
}
|
||||
}*/
|
||||
match = new Regex("^devices\\.([0-9]+)\\.(data.*)", RegexOptions.IgnoreCase).Match(item);
|
||||
if(match.Success) {
|
||||
Int32 deviceid = Int32.Parse(match.Groups[1].Value);
|
||||
if(this.Devices.ContainsKey(deviceid)) {
|
||||
this.Devices[deviceid].SetUpdate(notifications[item], match);
|
||||
}
|
||||
}
|
||||
}
|
||||
Thread.Sleep(1500);
|
||||
}
|
||||
}
|
||||
private void Poll() {
|
||||
CultureInfo info = new CultureInfo("de-DE");
|
||||
info.NumberFormat.NumberDecimalSeparator = ".";
|
||||
CultureInfo.DefaultThreadCurrentCulture = info;
|
||||
CultureInfo.DefaultThreadCurrentUICulture = info;
|
||||
Thread.CurrentThread.CurrentCulture = info;
|
||||
Thread.CurrentThread.CurrentUICulture = info;
|
||||
while(this.pollthreadRunning) {
|
||||
foreach(KeyValuePair<Int32, Device> item in this.Devices) {
|
||||
item.Value.Poll();
|
||||
}
|
||||
Thread.Sleep(1000);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region External functions
|
||||
public override ACommandClass GetCommandClass(String id) {
|
||||
String[] addr = id.Split('-');
|
||||
return addr.Length == 3 || addr.Length == 4 ? this.GetCommandClass(Int32.Parse(addr[0]), Int32.Parse(addr[1]), (ACommandClass.Classes)Int32.Parse(addr[2]), addr.Length == 4 ? Int32.Parse(addr[3]) : -1) : null;
|
||||
}
|
||||
public Dictionary<String, ACommandClass> GetCommandClasses(ACommandClass.Classes classes) {
|
||||
Dictionary<String, ACommandClass> ret = new Dictionary<String, ACommandClass>();
|
||||
foreach(KeyValuePair<Int32, Device> device in this.Devices) {
|
||||
foreach(KeyValuePair<Int32, Instance> instance in device.Value.Instances) {
|
||||
foreach(KeyValuePair<ACommandClass.Classes, ACommandClass> commandclass in instance.Value.CommandClasses) {
|
||||
if(commandclass.Key == classes) {
|
||||
ret.Add(commandclass.Value.Id, commandclass.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Internal functions
|
||||
private void CreateDevices(JsonData json) {
|
||||
Dictionary<Int32, Device> devices = new Dictionary<Int32, Device>();
|
||||
foreach(String deviceid in json.Keys) {
|
||||
Device d = Device.CreateDevice(json[deviceid], Int32.Parse(deviceid), this.http, this.polling, this.names);
|
||||
if(d != null) {
|
||||
devices.Add(Int32.Parse(deviceid), d);
|
||||
}
|
||||
}
|
||||
this.Devices = new ReadOnlyDictionary<Int32, Device>(devices);
|
||||
}
|
||||
private ACommandClass GetCommandClass(Int32 deviceid, Int32 instanceid, ACommandClass.Classes classid, Int32 subcid = -1) {
|
||||
if(this.Devices.ContainsKey(deviceid) && this.Devices[deviceid].Instances.ContainsKey(instanceid) && this.Devices[deviceid].Instances[instanceid].CommandClasses.ContainsKey(classid)) {
|
||||
ACommandClass commandclass = this.Devices[deviceid].Instances[instanceid].CommandClasses[classid];
|
||||
if(subcid == -1) {
|
||||
return commandclass;
|
||||
}
|
||||
if(commandclass != null) {
|
||||
if(commandclass.HasSub) {
|
||||
if(commandclass.Sub.ContainsKey(subcid)) {
|
||||
return commandclass.Sub[subcid];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
57
Zway/lib/ZwayBoard.cs
Normal file
57
Zway/lib/ZwayBoard.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
|
||||
using BlubbFish.IoT.Zway.Devices;
|
||||
using BlubbFish.IoT.Zway.Events;
|
||||
using BlubbFish.IoT.Zway.Interfaces;
|
||||
using BlubbFish.Utils;
|
||||
|
||||
namespace BlubbFish.IoT.Zway.lib {
|
||||
public abstract class ZwayBoard : IDisposable {
|
||||
protected Dictionary<String, String> config;
|
||||
protected Boolean polling;
|
||||
protected ReadOnlyDictionary<String, ReadOnlyDictionary<String, String>> names;
|
||||
|
||||
public delegate void DataUpdate(Object sender, DeviceUpdateEvent e);
|
||||
public event DataUpdate Update;
|
||||
|
||||
public ReadOnlyDictionary<Int32, Device> Devices {
|
||||
get; protected set;
|
||||
}
|
||||
|
||||
#region Constructor and deconstructor
|
||||
protected ZwayBoard(Dictionary<String, String> settings, ReadOnlyDictionary<String, ReadOnlyDictionary<String, String>> names, Boolean enablePoll) {
|
||||
this.config = settings;
|
||||
this.names = names;
|
||||
this.polling = enablePoll;
|
||||
}
|
||||
public static ZwayBoard GetInstance(Dictionary<String, String> settings, ReadOnlyDictionary<String, ReadOnlyDictionary<String, String>> names, Boolean enablePoll) {
|
||||
if(settings.Count == 0) {
|
||||
throw new ArgumentException("Missing block [zway] in settingsfile");
|
||||
} else if(!settings.ContainsKey("type")) {
|
||||
throw new ArgumentException("Missing type for [zway] in settingsfile");
|
||||
}
|
||||
String object_sensor = "BlubbFish.IoT.Zway.lib." + settings["type"].ToUpperLower() + "." + settings["type"].ToUpperLower();
|
||||
try {
|
||||
Type t = Type.GetType(object_sensor, true);
|
||||
return (ZwayBoard)t.GetConstructor(new Type[] { typeof(Dictionary<String, String>), typeof(ReadOnlyDictionary<String, ReadOnlyDictionary<String, String>>), typeof(Boolean) }).Invoke(new Object[] { settings, names, enablePoll });
|
||||
} catch(TypeLoadException) {
|
||||
throw new ArgumentException("Configuration: " + settings["type"] + " is not a ZwayBoard");
|
||||
} catch(FileNotFoundException) {
|
||||
throw new Exception("Driver " + object_sensor + " could not load!");
|
||||
}
|
||||
|
||||
}
|
||||
public abstract void Dispose();
|
||||
#endregion
|
||||
|
||||
#region External
|
||||
public abstract void Connect();
|
||||
public abstract ACommandClass GetCommandClass(String id);
|
||||
#endregion
|
||||
|
||||
protected void DeviceUpdate(Object sender, DeviceUpdateEvent e) => this.Update?.Invoke(sender, e);
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="LitJson" version="0.9.0" targetFramework="net461" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user