pax_global_header00006660000000000000000000000064150054353550014517gustar00rootroot0000000000000052 comment=d7bb9c1b4b77ccb95155e45998562fb48c7e9904 pyRFXtrx-0.32.0/000077500000000000000000000000001500543535500133475ustar00rootroot00000000000000pyRFXtrx-0.32.0/.coveragerc000066400000000000000000000005431500543535500154720ustar00rootroot00000000000000[run] source = RFXtrx [report] # Regexes for lines to exclude from consideration exclude_lines = # Have to re-enable the standard pragma pragma: no cover # Don't complain about missing debug-only code: def __repr__ # Don't complain if tests don't hit defensive assertion code: raise AssertionError raise NotImplementedError pyRFXtrx-0.32.0/.coveralls.yml000066400000000000000000000001061500543535500161370ustar00rootroot00000000000000service_name: travis-pro repo_token: aydGEftUBLbUoSTGsSUHdyvHHj9NC4ykdpyRFXtrx-0.32.0/.github/000077500000000000000000000000001500543535500147075ustar00rootroot00000000000000pyRFXtrx-0.32.0/.github/workflows/000077500000000000000000000000001500543535500167445ustar00rootroot00000000000000pyRFXtrx-0.32.0/.github/workflows/python-publish.yml000066400000000000000000000015151500543535500224560ustar00rootroot00000000000000# This workflows will upload a Python Package using Twine when a release is created # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries name: Upload Python Package on: release: types: [created] jobs: deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Set up Python uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies run: | python -m pip install --upgrade pip pip install setuptools wheel twine - name: Build and publish env: TWINE_USERNAME: __token__ TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} run: | python setup.py sdist bdist_wheel twine upload dist/* pyRFXtrx-0.32.0/.github/workflows/test-and-lint.yml000066400000000000000000000010661500543535500221550ustar00rootroot00000000000000name: Python package on: - push - pull_request jobs: build: runs-on: ubuntu-latest strategy: matrix: python-version: ['3.9', '3.10', '3.11', '3.12', '3.13'] steps: - uses: actions/checkout@v1 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | python -m pip install --upgrade pip python -m pip install tox tox-gh-actions - name: Test with tox run: toxpyRFXtrx-0.32.0/.gitignore000066400000000000000000000005451500543535500153430ustar00rootroot00000000000000*.py[cod] __pycache__ # C extensions *.so # Packages *.egg *.egg-info dist build eggs parts bin var sdist develop-eggs .installed.cfg lib lib64 # Generated documentation docs # Installer logs pip-log.txt # Unit test / coverage reports .coverage .tox nosetests.xml # Translations *.mo # Mr Developer .mr.developer.cfg .project .pydevproject .settings pyRFXtrx-0.32.0/.travis.yml000066400000000000000000000006541500543535500154650ustar00rootroot00000000000000sudo: false matrix: fast_finish: true include: - python: '3.4' env: TOXENV=py34 - python: '3.5' env: TOXENV=py35 - python: '3.6' env: TOXENV=py36 - python: '3.5' env: TOXENV=lint - python: "nightly" env: TOXENV=py36 allow_failures: - python: 'nightly' cache: directories: - "$HOME/.cache/pip" install: pip install -U tox coveralls language: python script: tox after_success: coveralls pyRFXtrx-0.32.0/COPYING.txt000066400000000000000000001173071500543535500152310ustar00rootroot00000000000000This file is part of pyRFXtrx, a Python library to communicate with the RFXtrx family of devices from http://www.rfxcom.com/ See https://github.com/woudt/pyRFXtrx for the latest version. This file contains the GNU LGPL license, under which pyRFXtrx is released. As the GNU LGPL references the GNU GPL, the latter is included after the first in this document. =============================================================================== GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. 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. =============================================================================== GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU 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 Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS pyRFXtrx-0.32.0/Dockerfile000066400000000000000000000004111500543535500153350ustar00rootroot00000000000000FROM python:3.4 RUN mkdir -p /usr/src/app WORKDIR /usr/src/app COPY requirements.txt requirements.txt RUN pip3 install --no-cache-dir -r requirements.txt # Copy source COPY . . RUN python setup.py install ENTRYPOINT [ "python" ] CMD [ "examples/receive.py" ] pyRFXtrx-0.32.0/MANIFEST.in000066400000000000000000000003631500543535500151070ustar00rootroot00000000000000include AUTHORS.rst include CONTRIBUTING.rst include HISTORY.rst include LICENSE include README.rst recursive-include tests * recursive-exclude * __pycache__ recursive-exclude * *.py[co] recursive-include docs *.rst conf.py Makefile make.batpyRFXtrx-0.32.0/README.rst000066400000000000000000000024601500543535500150400ustar00rootroot00000000000000========== pyRFXtrx |Build Status| |Coverage Status| ========== A Python library to communicate with the RFXtrx family of devices from http://www.rfxcom.com/. Works with http://www.home-assistant.io Using ===== Instally via pip :: $ pip install -U pyRFXtrx After that, see the examples in the examples directory Licensing ========= pyRFXtrx is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. pyRFXtrx is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with pyRFXtrx. See the file COPYING.txt in the distribution. If not, see . .. |Build Status| image:: https://travis-ci.org/Danielhiversen/pyRFXtrx.svg?branch=master :target: https://travis-ci.org/Danielhiversen/pyRFXtrx .. |Coverage Status| image:: https://img.shields.io/coveralls/Danielhiversen/pyRFXtrx.svg :target: https://coveralls.io/r/Danielhiversen/pyRFXtrx?branch=master pyRFXtrx-0.32.0/RFXtrx/000077500000000000000000000000001500543535500145445ustar00rootroot00000000000000pyRFXtrx-0.32.0/RFXtrx/__init__.py000066400000000000000000001257671500543535500166770ustar00rootroot00000000000000# This file is part of pyRFXtrx, a Python library to communicate with # the RFXtrx family of devices from http://www.rfxcom.com/ # See https://github.com/Danielhiversen/pyRFXtrx for the latest version. # # Copyright (C) 2012 Edwin Woudt # # pyRFXtrx is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # pyRFXtrx is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with pyRFXtrx. See the file COPYING.txt in the distribution. # If not, see . """ This module provides the base implementation for pyRFXtrx """ # pylint: disable=R0903, invalid-name # pylint: disable= too-many-lines import functools import glob import socket import threading import logging from contextlib import suppress from time import sleep import serial from . import lowlevel _LOGGER = logging.getLogger(__name__) ############################################################################### # RFXtrxDevice class ############################################################################### class RFXtrxDevice: """ Superclass for all devices """ def __init__(self, pkt): self.packettype = pkt.packettype self.subtype = pkt.subtype self.type_string = pkt.type_string self.id_string = pkt.id_string self.known_to_be_dimmable = False self.known_to_be_rollershutter = False def __eq__(self, other): if self.packettype != other.packettype: return False if self.subtype != other.subtype: return False return self.id_string == other.id_string def __str__(self): return "{0} type='{1}' id='{2}'".format( type(self), self.type_string, self.id_string) ############################################################################### # SwitchDevice class ############################################################################### class RollerTrolDevice(RFXtrxDevice): """ Concrete class for a roller device """ def __init__(self, pkt): super().__init__(pkt) if isinstance(pkt, lowlevel.RollerTrol): self.known_to_be_rollershutter = True self.id_combined = pkt.id_combined self.unitcode = pkt.unitcode self.cmndseqnbr = 0 self.COMMANDS = lowlevel.RollerTrol.COMMANDS def send_command(self, transport, command): """ Send a command using the given transport """ pkt = lowlevel.RollerTrol() pkt.set_transmit( self.subtype, self.cmndseqnbr, self.id_combined, self.unitcode, command ) self.cmndseqnbr = (self.cmndseqnbr + 1) % 5 transport.send(pkt.data) def send_close(self, transport): """ Send a 'Close' command using the given transport """ self.send_command(transport, 0x01) def send_open(self, transport): """ Send an 'Open' command using the given transport """ self.send_command(transport, 0x00) def send_stop(self, transport): """ Send a 'Stop' command using the given transport """ self.send_command(transport, 0x02) class DDxxxxDevice(RFXtrxDevice): """ Concrete class for a DDxxxx device """ def __init__(self, pkt): super().__init__(pkt) if isinstance(pkt, lowlevel.DDxxxx): self.known_to_be_rollershutter = True self.id_combined = pkt.id_combined self.unitcode = pkt.unitcode self.cmndseqnbr = 0 self.COMMANDS = lowlevel.DDxxxx.COMMANDS def send_command( self, transport, command, percent: int = 0, angle: int = 0): """ Send a command using the given transport """ pkt = lowlevel.DDxxxx() pkt.set_transmit( self.subtype, self.cmndseqnbr, self.id_combined, self.unitcode, command, percent, angle ) self.cmndseqnbr = (self.cmndseqnbr + 1) % 5 transport.send(pkt.data) def send_up(self, transport): """ Send an 'Open' command using the given transport """ self.send_command(transport, lowlevel.DDxxxx.CMD_UP) def send_down(self, transport): """ Send a 'Close' command using the given transport """ self.send_command(transport, lowlevel.DDxxxx.CMD_DOWN) def send_stop(self, transport): """ Send a 'Stop' command using the given transport """ self.send_command(transport, lowlevel.DDxxxx.CMD_STOP) def send_p2(self, transport): """ Send a 'P2' command using the given transport """ self.send_command(transport, lowlevel.DDxxxx.CMD_P2) def send_percent(self, transport, percent: int): """ Send a 'Percent' command using the given transport """ self.send_command( transport, lowlevel.DDxxxx.CMD_PERCENT, percent=percent ) def send_angle(self, transport, angle: int): """ Send a 'Angle' command using the given transport """ self.send_command(transport, lowlevel.DDxxxx.CMD_ANGLE, angle=angle) def send_percent_angle(self, transport, percent: int, angle: int): """ Send a 'Angle' command using the given transport """ self.send_command( transport, lowlevel.DDxxxx.CMD_PERCENT_ANGLE, percent=percent, angle=angle ) class RfyDevice(RFXtrxDevice): """ Concrete class for a roller device """ def __init__(self, pkt): super().__init__(pkt) if isinstance(pkt, lowlevel.Rfy): self.known_to_be_rollershutter = True self.id_combined = pkt.id_combined self.unitcode = pkt.unitcode self.cmndseqnbr = 0 self.COMMANDS = lowlevel.Rfy.COMMANDS def send_command(self, transport, command): """ Send a command using the given transport """ pkt = lowlevel.Rfy() pkt.set_transmit( self.subtype, self.cmndseqnbr, self.id_combined, self.unitcode, command ) self.cmndseqnbr = (self.cmndseqnbr + 1) % 5 transport.send(pkt.data) def send_close(self, transport): """ Send a 'Close' command using the given transport """ self.send_command(transport, 0x03) def send_open(self, transport): """ Send an 'Open' command using the given transport """ self.send_command(transport, 0x01) def send_stop(self, transport): """ Send a 'Stop' command using the given transport """ self.send_command(transport, 0x00) def send_on(self, transport): """ Send an 'Enable Sun Automation' command """ self.send_command(transport, 0x13) def send_off(self, transport): """ Send an 'Disable Sun Automation' command """ self.send_command(transport, 0x14) def send_up05sec(self, transport): """ Send a '0.5 Seconds Up' command """ self.send_command(transport, 0x0F) def send_down05sec(self, transport): """ Send a '0.5 Seconds Down' command """ self.send_command(transport, 0x10) def send_up2sec(self, transport): """ Send a '2 Seconds Up' command """ self.send_command(transport, 0x11) def send_down2sec(self, transport): """ Send a '2 Seconds Down' command """ self.send_command(transport, 0x12) class FunkDevice(RFXtrxDevice): """ Concrete class for a control device """ def __init__(self, pkt): super().__init__(pkt) if isinstance(pkt, lowlevel.Funkbus): self.id_combined = pkt.id_combined self.groupcode = pkt.groupcode self.target = pkt.target self.COMMANDS = lowlevel.Funkbus.COMMANDS def send_command(self, transport, command, param, duration): """ Send a command using the given transport """ pkt = lowlevel.Funkbus() pkt.set_transmit(self.subtype, 0, self.id_combined, self.groupcode, param if command in [0x00, 0x01, 0x04] else 0x00, command, duration) transport.send(pkt.data) def send_onoff(self, transport, turn_on): """ Send on 'On' or 'Off' command using the given transport """ self.send_command(transport, 0x01 if turn_on else 0x00, self.target, 0x00) def send_on(self, transport): """ Send an 'On' command using the given transport """ self.send_onoff(transport, True) def send_off(self, transport): """ Send an 'Off' command using the given transport """ self.send_onoff(transport, False) def send_dim(self, transport, duration): """ Send a 'Dim' command using the given transport """ self.send_command(transport, 0x00, self.target, duration + 1) def send_bright(self, transport, duration): """ Send a 'Bright' command using the given transport """ self.send_command(transport, 0x01, self.target, duration + 1) def send_alloff(self, transport): """ Send an 'All OFF' command using the given transport """ self.send_command(transport, 0x02, 0x00, 0x03) def send_allon(self, transport): """ Send a 'All ON' command using the given transport """ self.send_command(transport, 0x03, 0x00, 0x03) def send_setscene(self, transport, scene): """ Send a 'Scene' command using the given transport """ self.send_command(transport, 0x04, scene, 0x01) def send_masterdim(self, transport, duration): """ Send a 'Master Dim' command using the given transport """ self.send_command(transport, 0x05, 0x00, duration + 1) def send_masterbright(self, transport, duration): """ Send a 'Bright' command using the given transport """ self.send_command(transport, 0x06, 0x00, duration + 1) class LightingDevice(RFXtrxDevice): """ Concrete class for a control device """ # pylint: disable=too-many-instance-attributes def __init__(self, pkt): super().__init__(pkt) if isinstance(pkt, lowlevel.Lighting1): self.housecode = pkt.housecode self.unitcode = pkt.unitcode self.COMMANDS = lowlevel.Lighting1.COMMANDS if isinstance(pkt, lowlevel.Lighting2): self.id_combined = pkt.id_combined self.unitcode = pkt.unitcode self.COMMANDS = lowlevel.Lighting2.COMMANDS if isinstance(pkt, lowlevel.Lighting3): self.system = pkt.system self.channel = pkt.channel self.COMMANDS = lowlevel.Lighting3.COMMANDS if isinstance(pkt, lowlevel.Lighting4): self.cmd = pkt.cmd self.pulse = pkt.pulse self.COMMANDS = lowlevel.Lighting4.COMMANDS if isinstance(pkt, lowlevel.Lighting5): self.id_combined = pkt.id_combined self.unitcode = pkt.unitcode if self.subtype == 0x00: self.COMMANDS = lowlevel.Lighting5.COMMANDS_00 elif self.subtype == 0x01: self.COMMANDS = lowlevel.Lighting5.COMMANDS_01 elif self.subtype in (0x02, 0x04, 0x0F): self.COMMANDS = lowlevel.Lighting5.COMMANDS_02_04_0F elif self.subtype == 0x03: self.COMMANDS = lowlevel.Lighting5.COMMANDS_03 else: self.COMMANDS = lowlevel.Lighting5.COMMANDS_XX if isinstance(pkt, lowlevel.Lighting6): self.id_combined = pkt.id_combined self.groupcode = pkt.groupcode self.unitcode = pkt.unitcode self.cmndseqnbr = 0 self.COMMANDS = lowlevel.Lighting6.COMMANDS def send_command(self, transport, command): """ Send an ommand using the given transport """ if self.packettype == 0x10: # Lighting1 pkt = lowlevel.Lighting1() pkt.set_transmit(self.subtype, 0, self.housecode, self.unitcode, command) transport.send(pkt.data) elif self.packettype == 0x11: # Lighting2 pkt = lowlevel.Lighting2() pkt.set_transmit(self.subtype, 0, self.id_combined, self.unitcode, command, 0x00) transport.send(pkt.data) elif self.packettype == 0x12: # Lighting3 pkt = lowlevel.Lighting3() pkt.set_transmit(self.subtype, 0, self.system, self.channel, command) transport.send(pkt.data) elif self.packettype == 0x13: # Lighting4 pkt = lowlevel.Lighting4() code = self.cmd & ~1 code |= command pkt.set_transmit(self.subtype, 0, code, self.pulse) transport.send(pkt.data) elif self.packettype == 0x14: # Lighting5 pkt = lowlevel.Lighting5() pkt.set_transmit(self.subtype, 0, self.id_combined, self.unitcode, command, 0x00) transport.send(pkt.data) elif self.packettype == 0x15: # Lighting6 pkt = lowlevel.Lighting6() pkt.set_transmit(self.subtype, 0, self.id_combined, self.groupcode, self.unitcode, command, self.cmndseqnbr) self.cmndseqnbr = (self.cmndseqnbr + 1) % 5 transport.send(pkt.data) def send_onoff(self, transport, turn_on): """ Send an 'On' or 'Off' command using the given transport """ if self.packettype == 0x10: # Lighting1 self.send_command(transport, turn_on and 0x01 or 0x00) elif self.packettype == 0x11: # Lighting2 self.send_command(transport, turn_on and 0x01 or 0x00) elif self.packettype == 0x12: # Lighting3 self.send_command(transport, turn_on and 0x10 or 0x1a) elif self.packettype == 0x13: # Lighting4 self.send_command(transport, 0x1 if turn_on else 0x0) elif self.packettype == 0x14: # Lighting5 self.send_command(transport, turn_on and 0x01 or 0x00) elif self.packettype == 0x15: # Lighting6 self.send_command(transport, not turn_on and 0x01 or 0x00) def send_on(self, transport): """ Send an 'On' command using the given transport """ self.send_onoff(transport, True) def send_off(self, transport): """ Send an 'Off' command using the given transport """ self.send_onoff(transport, False) def send_openclosestop(self, transport, command): """ Send an 'Open' or a 'Close' or a 'Stop' command using the given transport """ if self.packettype == 0x14: # Lighting5 if command not in [0x0d, 0x0e, 0x0f]: raise ValueError(command, "is not a relay packet in Lighting5") self.send_command(transport, command) else: raise ValueError("Unsupported packettype") def send_open(self, transport): """ Send an 'Open' command using the given transport """ self.send_openclosestop(transport, 0x0f) def send_close(self, transport): """ Send an 'Close' command using the given transport """ self.send_openclosestop(transport, 0x0d) def send_stop(self, transport): """ Send an 'Stop' command using the given transport """ self.send_openclosestop(transport, 0x0e) def send_dim(self, transport, level): """ Send a 'Dim' command with the given level using the given transport """ # pylint: disable=too-many-branches if level < 0 or level > 100: raise ValueError("Dim level must be between 0 and 100") if self.packettype == 0x10: # Lighting1 raise ValueError("Dim level unsupported for Lighting1") # Supporting a dim level for X10 directly is not possible because # RFXtrx does not support sending extended commands if self.packettype == 0x11: # Lighting2 if level == 0: self.send_off(transport) else: pkt = lowlevel.Lighting2() pkt.set_transmit(self.subtype, 0, self.id_combined, self.unitcode, 0x02, ((level + 6) * 16 // 100) - 1) transport.send(pkt.data) elif self.packettype == 0x12: # Lighting3 if level == 0: self.send_off(transport) elif level == 100: self.send_on(transport) else: pkt = lowlevel.Lighting3() pkt.set_transmit(self.subtype, 0, self.system, self.channel, (level * 9 // 100) + 17) transport.send(pkt.data) elif self.packettype == 0x14: # Lighting5 if level == 0: self.send_off(transport) else: pkt = lowlevel.Lighting5() pkt.set_transmit(self.subtype, 0, self.id_combined, self.unitcode, 0x10, ((level + 3) * 32 // 100) - 1) transport.send(pkt.data) elif self.packettype == 0x15: # Lighting6 raise ValueError("Dim level unsupported for Lighting6") elif self.packettype == 0x1e: # Funkbus raise ValueError("Dim level unsupported for Funkbus") else: raise ValueError("Unsupported packettype") class ChimeDevice(RFXtrxDevice): """ Concrete class for a control device """ def __init__(self, pkt): super().__init__(pkt) self.id1 = pkt.id1 self.id2 = pkt.id2 self.COMMANDS = lowlevel.Chime.COMMANDS def send_command(self, transport, sound): """Trigger a chime sound on device.""" pkt = lowlevel.Chime() pkt.set_transmit(self.subtype, 0, self.id1, self.id2, sound) transport.send(pkt.data) ############################################################################### # get_device_from_pkt method ############################################################################### def get_device_from_pkt(pkt): """Construct a device object from a packet.""" # pylint: disable=too-many-boolean-expressions if isinstance(pkt, (lowlevel.Lighting1, lowlevel.Lighting2, lowlevel.Lighting3, lowlevel.Lighting4, lowlevel.Lighting5, lowlevel.Lighting6)): device = LightingDevice(pkt) elif isinstance(pkt, lowlevel.RollerTrol): device = RollerTrolDevice(pkt) elif isinstance(pkt, lowlevel.DDxxxx): device = DDxxxxDevice(pkt) elif isinstance(pkt, lowlevel.Rfy): device = RfyDevice(pkt) elif isinstance(pkt, lowlevel.Chime): device = ChimeDevice(pkt) elif isinstance(pkt, lowlevel.Security1): device = SecurityDevice(pkt) elif isinstance(pkt, lowlevel.Funkbus): device = FunkDevice(pkt) else: device = RFXtrxDevice(pkt) return device class SecurityDevice(RFXtrxDevice): """ Concrete class for a control device """ def __init__(self, pkt): super().__init__(pkt) self.id_combined = pkt.id_combined self.cmndseqnbr = 0 self.STATUS = lowlevel.Security1.STATUS def send_status(self, transport, status): """Trigger a status message on device.""" pkt = lowlevel.Security1() pkt.set_transmit( self.subtype, self.cmndseqnbr, self.id_combined, status ) self.cmndseqnbr = (self.cmndseqnbr + 1) % 5 transport.send(pkt.data) ############################################################################### # get_device method ############################################################################### def get_device(packettype, subtype, id_string): """ Return a device base on its identifying values """ pkt = lowlevel.get_packet_with_id(packettype, subtype, id_string) if pkt is None: raise ValueError("Unsupported packettype") return get_device_from_pkt(pkt) ############################################################################### # RFXtrxEvent class ############################################################################### class RFXtrxEvent: """ Abstract superclass for all events """ def __init__(self, device): self.device = device ############################################################################### # SensorEvent class ############################################################################### class SensorEvent(RFXtrxEvent): """ Concrete class for sensor events """ def __init__(self, pkt): # pylint: disable=too-many-branches, too-many-statements device = get_device_from_pkt(pkt) super().__init__(device) self.values = {} self.pkt = pkt if isinstance(pkt, lowlevel.Undecoded): self.values['Payload'] = pkt.payload.hex() if isinstance(pkt, lowlevel.RfxMeter): self.values['Counter value'] = pkt.value if isinstance(pkt, (lowlevel.Temp, lowlevel.TempHumid, lowlevel.TempHumidBaro, lowlevel.TempRain)): self.values['Temperature'] = pkt.temp if isinstance(pkt, lowlevel.Bbq): self.values['Temperature'] = pkt.temp1 self.values['Temperature2'] = pkt.temp2 if isinstance(pkt, (lowlevel.Humid, lowlevel.TempHumid, lowlevel.TempHumidBaro)): self.values['Humidity'] = pkt.humidity self.values['Humidity status'] = pkt.humidity_status_string self.values['Humidity status numeric'] = pkt.humidity_status if isinstance(pkt, (lowlevel.Baro, lowlevel.TempHumidBaro)): self.values['Barometer'] = pkt.baro self.values['Forecast'] = pkt.forecast_string self.values['Forecast numeric'] = pkt.forecast if isinstance(pkt, lowlevel.Rain): self.values['Rain rate'] = pkt.rainrate self.values['Rain total'] = pkt.raintotal if isinstance(pkt, lowlevel.TempRain): self.values['Rain total'] = pkt.raintotal if isinstance(pkt, lowlevel.Wind): self.values['Wind direction'] = pkt.direction self.values['Wind average speed'] = pkt.average_speed self.values['Wind gust'] = pkt.gust if pkt.temperature is not None: self.values['Temperature'] = pkt.temperature if pkt.chill is not None: self.values['Chill'] = pkt.chill if isinstance(pkt, lowlevel.UV): self.values['UV'] = pkt.uvi if isinstance(pkt, lowlevel.Energy): self.values['Energy usage'] = pkt.currentwatt self.values['Total usage'] = pkt.totalwatts self.values['Count'] = pkt.count if isinstance(pkt, lowlevel.Energy1): self.values['Current Ch. 1'] = pkt.currentamps1 self.values['Current Ch. 2'] = pkt.currentamps2 self.values['Current Ch. 3'] = pkt.currentamps3 # CM113/ELEC1 doesn't have a 'total usage' counter, so provide an # aggregated virtual value self.values['Total usage'] = (pkt.currentamps1 + pkt.currentamps2 + pkt.currentamps3) self.values['Count'] = pkt.count if isinstance(pkt, lowlevel.Energy4): self.values['Current Ch. 1'] = pkt.currentamps1 self.values['Current Ch. 2'] = pkt.currentamps2 self.values['Current Ch. 3'] = pkt.currentamps3 self.values['Total usage'] = pkt.totalwatthours self.values['Count'] = pkt.count if isinstance(pkt, lowlevel.Energy5): self.values['Voltage'] = pkt.voltage self.values['Current'] = pkt.currentamps self.values['Energy usage'] = pkt.currentwatt self.values['Total usage'] = pkt.totalwatthours if isinstance(pkt, lowlevel.Cartelectronic): if pkt.type_string == 'CARTELECTRONIC_ENCODER': self.values['Counter value'] = pkt.counter1 self.values['Count'] = pkt.counter2 elif pkt.type_string == 'CARTELECTRONIC_LINKY': # Index for current tarif if consummer self.values['Total usage'] = pkt.conswatthours # Index for current tarif if production self.values['Count'] = pkt.prodwatthours # Index of current tarif self.values['Counter value'] = pkt.tarif_num self.values['Voltage'] = pkt.voltage self.values['Energy usage'] = pkt.currentwatt self.values['Sensor Status'] = pkt.teleinfo_ok elif pkt.type_string == 'CARTELECTRONIC_TIC': self.values['Counter value'] = pkt.counter1 self.values['Count'] = pkt.counter2 self.values['Energy usage'] = pkt.currentwatt self.values['Sensor Status'] = pkt.teleinfo_ok self.values['Contract type'] = pkt.contract_type if isinstance(pkt, lowlevel.Security1): self.values['Sensor Status'] = pkt.security1_status_string if not isinstance(pkt, (lowlevel.Energy5, lowlevel.RfxMeter, lowlevel.Undecoded)): self.values['Battery numeric'] = pkt.battery if not isinstance(pkt, lowlevel.Undecoded): self.values["Rssi numeric"] = pkt.rssi def __str__(self): return "{0} device=[{1}] values={2}".format( type(self), self.device, sorted(self.values.items())) ############################################################################### # ControlEvent class ############################################################################### class ControlEvent(RFXtrxEvent): """ Concrete class for control events """ def __init__(self, pkt): device = get_device_from_pkt(pkt) super().__init__(device) self.values = {} self.values['Command'] = pkt.value('cmnd_string') if isinstance(pkt, lowlevel.Lighting2) and pkt.cmnd in [2, 5]: dimmable = True self.values['Dim level'] = (pkt.level + 1) * 100 // 16 elif isinstance(pkt, lowlevel.Lighting5) and pkt.cmnd in [0x10]: dimmable = True self.values['Dim level'] = (pkt.level + 1) * 100 // 32 else: dimmable = False self.device.known_to_be_dimmable = dimmable if isinstance(pkt, lowlevel.Lighting5) \ and pkt.cmnd in [0x0d, 0x0e, 0x0f]: self.device.known_to_be_rollershutter = True if isinstance(pkt, lowlevel.Chime): self.values['Sound'] = pkt.sound if pkt.rssi is not None: self.values['Rssi numeric'] = pkt.rssi if isinstance(pkt, lowlevel.Funkbus): self.values['Keypress'] = pkt.value('time_string') def __str__(self): return "{0} device=[{1}] values={2}".format( type(self), self.device, sorted(self.values.items())) ############################################################################### # Status class ############################################################################### class StatusEvent(RFXtrxEvent): """ Concrete class for status """ def __str__(self): return "{0} device=[{1}]".format( type(self), self.device) class ConnectionEvent(RFXtrxEvent): """ Connection event """ def __init__(self): super().__init__(None) class ConnectionLost(ConnectionEvent): """ Connection lost """ class ConnectionDone(ConnectionEvent): """ Connection lost """ ############################################################################### # DummySerial class ############################################################################### class _dummySerial: """ Dummy class for testing""" # pylint: disable=unused-argument def __init__(self, *args, **kwargs): self._read_num = 0 self._data = {} self._data[0] = [0x0D, 0x01, 0x00, 0x01, 0x02, 0x53, 0x45, # status 0x10, # msg3: rsl 0x0C, # msg4: hideki lacrosse 0x2F, # msg5: x10 arc ac homeeasy oregon 0x01, # msg6: keeloq 0x01, 0x00, 0x00] self._data[1] = [0x00, 0x00, 0x00, 0x00, 0x00, # response to start 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] self._data[2] = [0x0b, 0x15, 0x00, 0x2a, 0x12, 0x34, 0x41, 0x05, 0x03, 0x01, 0x00, 0x70] # light self._data[3] = [0x0b, 0x15, 0x00, 0x2a, 0x12, 0x34, 0x41, 0x05, 0x03, 0x01, 0x00, 0x70] # light self._data[4] = [0x0a, 0x51, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # sensor1 self._data[5] = [0x0b, 0x15, 0x00, 0x2a, 0x12, 0x34, 0x41, 0x05, 0x03, 0x01, 0x00, 0x70] # light self._data[6] = [0x0a, 0x51, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # sensor1 self._data[7] = [0x0a, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] # sensor2 self._data[8] = [0x09, 0x03, 0x01, 0x1e, 0x28, 0x0a, 0xb7, 0x66, 0x04, 0x74] # undecoded self._close_event = threading.Event() def write(self, *args, **kwargs): """ Dummy function for writing""" # pylint: disable=invalid-name def flushInput(self, *args, **kwargs): """ Called by PySerialTransport""" def read(self, data=None): """ Dummy function for reading""" if data is not None or self._read_num >= len(self._data): self._close_event.wait(0.1) return [0x00] res = self._data[self._read_num] self._read_num = self._read_num + 1 return res def close(self): """ close connection to rfxtrx device """ self._close_event.set() ############################################################################### # RFXtrxTransportError class ############################################################################### class RFXtrxTransportError(Exception): """ Connection error """ ############################################################################### # RFXtrxTransport class ############################################################################### class RFXtrxTransport: """ Abstract superclass for all transport mechanisms """ # pylint: disable=attribute-defined-outside-init @staticmethod def parse(data): """ Parse the given data and return an RFXtrxEvent """ if data is None: return None pkt = lowlevel.parse(data) if pkt is not None: if isinstance(pkt, lowlevel.SensorPacket): obj = SensorEvent(pkt) elif isinstance(pkt, lowlevel.Status): obj = StatusEvent(pkt) else: obj = ControlEvent(pkt) # Store the latest RF signal data obj.data = data return obj return None def connect(self, timeout=None): """ connect to device """ def reset(self): """ reset the rfxtrx device """ def close(self): """ close connection to rfxtrx device """ def receive_blocking(self): """ Wait until a packet is received and return with an RFXtrxEvent """ def send(self, data): """ Send the given packet """ def transport_errors(message): """ Decorator to wrap low level errors in known error. """ def _errors(func): @functools.wraps(func) def __errors(instance: RFXtrxTransport, *args, **kargs): try: return func(instance, *args, **kargs) except (socket.error, serial.SerialException, OSError) as exception: _LOGGER.debug("%s failed: %s", message, str(exception), exc_info=True) raise RFXtrxTransportError( "{0} failed: {1}".format(message, exception) ) from exception return __errors return _errors ############################################################################### # PySerialTransport class ############################################################################### class PySerialTransport(RFXtrxTransport): """ Implementation of a transport using PySerial """ def __init__(self, port): self.port = port self.serial = None @transport_errors("connect") def connect(self, timeout=None): """ Open a serial connexion """ try: self.serial = serial.Serial(self.port, 38400) except serial.SerialException: port = glob.glob('/dev/serial/by-id/usb-RFXCOM_*-port0') if len(port) < 1: raise _LOGGER.debug("Attempting connection by name %s", port) self.serial = serial.Serial(port[0], 38400) @transport_errors("receive") def receive_blocking(self): return self._receive_packet() def _receive_packet(self): """ Wait until a packet is received and return with an RFXtrxEvent """ data = self.serial.read() if data == '\x00': return None pkt = bytearray(data) while len(pkt) < pkt[0]+1: data = self.serial.read(pkt[0]+1 - len(pkt)) pkt.extend(bytearray(data)) _LOGGER.debug( "Recv: %s", " ".join("0x{0:02x}".format(x) for x in pkt) ) return self.parse(pkt) @transport_errors("send") def send(self, data): """ Send the given packet """ if isinstance(data, bytearray): pkt = data elif isinstance(data, (bytes, str)): pkt = bytearray(data) else: raise ValueError("Invalid type") _LOGGER.debug( "Send: %s", " ".join("0x{0:02x}".format(x) for x in pkt) ) self.serial.write(pkt) @transport_errors("reset") def reset(self): """ Reset the RFXtrx """ self.send(b'\x0D\x00\x00\x00\x00\x00\x00' b'\x00\x00\x00\x00\x00\x00\x00') sleep(0.3) # Should work with 0.05, but not for me self.serial.flushInput() @transport_errors("close") def close(self): """ close connection to rfxtrx device """ with suppress(serial.SerialException): self.serial.close() ############################################################################### # PyNetworkTransport class ############################################################################### class PyNetworkTransport(RFXtrxTransport): """ Implementation of a transport using sockets """ def __init__(self, hostport): self.hostport = hostport # must be a (host, port) tuple self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @transport_errors("connect") def connect(self, timeout=None): """ Open a socket connection """ self.sock.settimeout(timeout) self.sock.connect(self.hostport) self.sock.settimeout(None) _LOGGER.debug("Connected to network socket") @transport_errors("receive") def receive_blocking(self): """ Wait until a packet is received and return with an RFXtrxEvent """ return self._receive_packet() def _receive_packet(self): """ Wait until a packet is received and return with an RFXtrxEvent """ data = self.sock.recv(1) if data == b'': raise RFXtrxTransportError("Server was shutdown") if data == '\x00': return None pkt = bytearray(data) while len(pkt) < pkt[0]+1: data = self.sock.recv(pkt[0]+1 - len(pkt)) if data == b'': raise RFXtrxTransportError("Server was shutdown") pkt.extend(bytearray(data)) _LOGGER.debug( "Recv: %s", " ".join("0x{0:02x}".format(x) for x in pkt) ) return self.parse(pkt) @transport_errors("send") def send(self, data): """ Send the given packet """ if isinstance(data, bytearray): pkt = data elif isinstance(data, (bytes, str)): pkt = bytearray(data) else: raise ValueError("Invalid type") _LOGGER.debug( "Send: %s", " ".join("0x{0:02x}".format(x) for x in pkt) ) self.sock.send(pkt) @transport_errors("reset") def reset(self): """ Reset the RFXtrx """ try: self.send(b'\x0D\x00\x00\x00\x00\x00\x00' b'\x00\x00\x00\x00\x00\x00\x00') sleep(0.3) self.sock.sendall(b'') except socket.error as exception: raise RFXtrxTransportError( "Reset failed: {0}".format(exception)) from exception @transport_errors("close") def close(self): """ close connection to rfxtrx device """ with suppress(socket.error): self.sock.shutdown(socket.SHUT_RDWR) self.sock.close() class DummyTransport(RFXtrxTransport): """ Dummy transport for testing purposes """ def __init__(self, device=""): self.device = device self._close_event = threading.Event() def connect(self, timeout=None): pass def receive(self, data=None): """ Emulate a receive by parsing the given data """ if data is None: self._close_event.wait(0.1) return None pkt = bytearray(data) _LOGGER.debug( "Recv: %s", " ".join("0x{0:02x}".format(x) for x in pkt) ) return self.parse(pkt) def receive_blocking(self, data=None): """ Emulate a receive by parsing the given data """ return self.receive(data) def send(self, data): """ Emulate a send by doing nothing (except printing debug info if requested) """ pkt = bytearray(data) _LOGGER.debug( "Send: %s", " ".join("0x{0:02x}".format(x) for x in pkt) ) def close(self): """Close.""" self._close_event.set() class DummyTransport2(PySerialTransport): """ Dummy transport for testing purposes """ # pylint: disable=super-init-not-called def __init__(self, device=""): self.serial = _dummySerial(device, 38400, timeout=0.1) self._run_event = threading.Event() def connect(self, timeout=None): self._run_event.set() class Connect: """ The main class for rfxcom-py. Has methods for sensors. """ # pylint: disable=too-many-instance-attributes, too-many-arguments def __init__(self, transport, event_callback=None, modes=None): self._run_event = threading.Event() self._sensors = {} self._status = None self._modes = modes self._thread = threading.Thread(target=self._connect, daemon=True) self.event_callback = event_callback self.transport: RFXtrxTransport = transport def connect(self, timeout=None): """Connect to device.""" self.transport.connect(timeout) self._thread.start() if not self._run_event.wait(timeout): self.close_connection() raise TimeoutError() def _connect(self): try: self._connect_internal() except RFXtrxTransportError as exception: _LOGGER.info("Connection lost %s", exception) finally: if self.event_callback and self._run_event.is_set(): self.event_callback(ConnectionLost()) def _connect_internal(self): """Connect """ self.transport.reset() self._status = self.send_get_status() if self._modes is not None: self.set_recmodes(self._modes) self._status = self.send_get_status() if self._status: _LOGGER.debug( "Status: %s", self._status.device ) self.send_start() self._run_event.set() if self.event_callback: self.event_callback(ConnectionDone()) while self._run_event.is_set(): event = self.transport.receive_blocking() if isinstance(event, RFXtrxEvent): if self.event_callback: self.event_callback(event) if isinstance(event, SensorEvent): self._sensors[event.device.id_string] = event.device def sensors(self): """ Return all found sensors. :return: dict of :class:`Sensor` instances. """ return self._sensors def close_connection(self): """ Close connection to rfxtrx device """ self._run_event.clear() self.transport.close() self._thread.join() def set_recmodes(self, modenames): """ Sets the device modes (which protocols to decode) """ data = bytearray([0x0D, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) # Keep the values read during init. data[5] = self._status.device.tranceiver_type data[6] = self._status.device.output_power # Build the mode data bytes from the mode names for mode in modenames: byteno, bitno = lowlevel.get_recmode_tuple(mode) if byteno is None: raise ValueError('Unknown mode name '+mode) data[7 + byteno] |= 1 << bitno self.transport.send(data) self._modes = modenames return self.transport.receive_blocking() def send_start(self): """ Sends the Start RFXtrx transceiver command """ self.transport.send(b'\x0D\x00\x00\x03\x07\x00\x00' b'\x00\x00\x00\x00\x00\x00\x00') return self.transport.receive_blocking() def send_get_status(self): """ Sends the Get Status command """ self.transport.send(b'\x0D\x00\x00\x01\x02\x00\x00' b'\x00\x00\x00\x00\x00\x00\x00') return self.transport.receive_blocking() class Core(Connect): """ The main class for rfxcom-py. Has changed name to Connect """ pyRFXtrx-0.32.0/RFXtrx/lowlevel.py000066400000000000000000003332421500543535500167560ustar00rootroot00000000000000# This file is part of pyRFXtrx, a Python library to communicate with # the RFXtrx family of devices from http://www.rfxcom.com/ # See https://github.com/Danielhiversen/pyRFXtrx for the latest version. # # Copyright (C) 2012 Edwin Woudt # # pyRFXtrx is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # pyRFXtrx is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with pyRFXtrx. See the file COPYING.txt in the distribution. # If not, see . """ This module provides low level packet parsing and generation code for the RFXtrx. """ # pylint: disable=C0302,R0902,R0903,R0911,R0913 # pylint: disable= too-many-lines, too-many-statements ############################################################################### # Packet class ############################################################################### class Packet(): """ Abstract superclass for all low level packets """ _UNKNOWN_TYPE = "Unknown type ({0:#04x}/{1:#04x})" _UNKNOWN_CMND = "Unknown command ({0:#04x})" def __init__(self): """Constructor""" self.data = None self.packetlength = None self.packettype = None self.subtype = None self.seqnbr = None self.rssi = None self.rssi_byte = None self.type_string = None self.id_string = None def has_value(self, datatype): """Return True if the sensor supports the given data type. sensor.has_value(RFXCOM_TEMPERATURE) is identical to calling sensor.has_temperature(). """ return hasattr(self, datatype) def value(self, datatype): """Return the :class:`SensorValue` for the given data type. sensor.value(RFXCOM_TEMPERATURE) is identical to calling sensor.temperature(). """ return getattr(self, datatype, None) def __getattr__(self, name): typename = name.replace("has_", "", 1) if not name == typename: return lambda: self.has_value(typename) raise AttributeError(name) def __eq__(self, other): if not isinstance(other, Packet): return False return self.id_string == other.id_string def __str__(self): return "Packet [id_string={0}]".format(self.id_string) def __repr__(self): return self.__str__() ############################################################################### # Status class ############################################################################### class Status(Packet): """ Data class for the Status packet type """ TYPES = { 0x50: '310MHz', 0x51: '315MHz', 0x53: '433.92MHz', 0x55: '868.00MHz', 0x56: '868.00MHz FSK', 0x57: '868.30MHz', 0x58: '868.30MHz FSK', 0x59: '868.35MHz', 0x5A: '868.35MHz FSK', 0x5B: '868.95MHz', 0x5C: '868.30MHz FSK PKT', 0x5D: '868.35MHz FSK PKT', 0x5E: '868.40MHz FSK PKT' } """ Receiving modes names. DO NOT alter their order. """ RECMODES = [ [ "aeblyss", "rubicson", "fineoffset", "lighting4", "rsl", "byronsx", "imagintronix", "undecoded" ], [ "mertik", "adlightwave", "hideki", "lacrosse", "fs20", "proguard", "blindst0", "blindst1234" ], [ "x10", "arc", "ac", "homeeasy", "meiantech", "oregon", "ati", "visonic" ], [ "keeloq", "homeconfort" ] ] """ Mapping of numeric subtype values to strings, used in type_string """ def __str__(self): return ("Status [subtype={0}, firmware={1}, output_power={2}, " "devices={3}]").format(self.type_string, self.firmware_version, self.output_power, self.devices) def __init__(self): """Constructor""" super().__init__() self.tranceiver_type = None self.firmware_version = None self.output_power = None self.devices = None def _decode_recmodes(self, data, index): res = set() for i in range(0, len(self.RECMODES[index])): if (data & (1 << i)) != 0: res.add(self.RECMODES[index][i]) return res def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.tranceiver_type = data[5] self.firmware_version = data[6] self.output_power = data[13] devs = set() devs.update(self._decode_recmodes(data[7], 0)) devs.update(self._decode_recmodes(data[8], 1)) devs.update(self._decode_recmodes(data[9], 2)) devs.update(self._decode_recmodes(data[10], 3)) self.devices = sorted(devs) self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" if self.tranceiver_type in self.TYPES: self.type_string = self.TYPES[self.tranceiver_type] else: # Degrade nicely for yet unknown subtypes self.type_string = 'Unknown' def get_recmode_tuple(mode_name): """ Look for a receiving mode in the RECMODES lists from a name. Return a tuple (listno, sublistno), or (None, None) if not found. """ for i, modes in enumerate(Status.RECMODES): if mode_name in modes: return (i, modes.index(mode_name)) return (None, None) ############################################################################### # Lighting1 class ############################################################################### class Lighting1(Packet): """ Data class for the Lighting1 packet type """ TYPES = {0x00: 'X10 lighting', 0x01: 'ARC', 0x02: 'ELRO AB400D', 0x03: 'Waveman', 0x04: 'Chacon EMW200', 0x05: 'IMPULS', 0x06: 'RisingSun', 0x07: 'Philips SBC', 0x08: 'Energenie', 0x09: 'Energenie5', 0x0A: 'GDR2', 0x0B: 'HQ'} """ Mapping of numeric subtype values to strings, used in type_string """ ALIAS_TYPES = {'KlikAanKlikUit code wheel': 0x01, 'NEXA code wheel': 0x01, 'CHACON code wheel': 0x01, 'HomeEasy code wheel': 0x01, 'Proove': 0x01, 'DomiaLite': 0x01, 'InterTechno': 0x01, 'AB600': 0x01} """ Mapping of subtype aliases to the corresponding subtype value """ HOUSECODES = {0x41: 'A', 0x42: 'B', 0x43: 'C', 0x44: 'D', 0x45: 'E', 0x46: 'F', 0x47: 'G', 0x48: 'H', 0x49: 'I', 0x4A: 'J', 0x4B: 'K', 0x4C: 'L', 0x4D: 'M', 0x4E: 'N', 0x4F: 'O', 0x50: 'P'} """ Mapping of housecode numeric values to strings, used in id_string """ COMMANDS = {0x00: 'Off', 0x01: 'On', 0x02: 'Dim', 0x03: 'Bright', 0x05: 'All/group Off', 0x06: 'All/group On', 0x07: 'Chime', 0xFF: 'Illegal command'} """ Mapping of command numeric values to strings, used for cmnd_string """ def __str__(self): return ("Lighting1 [subtype={0}, seqnbr={1}, id={2}, cmnd={3}, " + "rssi={4}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.cmnd_string, self.rssi) def __init__(self): """Constructor""" super().__init__() self.housecode = None self.unitcode = None self.cmnd = None self.cmnd_string = None def parse_id(self, subtype, id_string): """Parse a string id into individual components""" try: self.packettype = 0x10 self.subtype = subtype hcode = id_string[0:1] for hcode_num, hcode_code in self.HOUSECODES.items(): if hcode_code == hcode: self.housecode = hcode_num self.unitcode = int(id_string[1:]) self._set_strings() except ValueError as exc: raise ValueError("Invalid id_string") from exc if self.id_string != id_string: raise ValueError("Invalid id_string") def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.housecode = data[4] self.unitcode = data[5] self.cmnd = data[6] self.rssi_byte = data[7] self.rssi = self.rssi_byte >> 4 self._set_strings() def set_transmit(self, subtype, seqnbr, housecode, unitcode, cmnd): """Load data from individual data fields""" self.packetlength = 7 self.packettype = 0x10 self.subtype = subtype self.seqnbr = seqnbr self.housecode = housecode self.unitcode = unitcode self.cmnd = cmnd self.rssi_byte = 0 self.rssi = 0 self.data = bytearray([self.packetlength, self.packettype, self.subtype, self.seqnbr, self.housecode, self.unitcode, self.cmnd, self.rssi_byte]) self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = self.HOUSECODES[self.housecode] + str(self.unitcode) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) if self.cmnd is not None: if self.cmnd in self.COMMANDS: self.cmnd_string = self.COMMANDS[self.cmnd] else: self.cmnd_string = self._UNKNOWN_CMND.format(self.cmnd) ############################################################################### # Lighting2 class ############################################################################### class Lighting2(Packet): """ Data class for the Lighting2 packet type """ TYPES = {0x00: 'AC', 0x01: 'HomeEasy EU', 0x02: 'ANSLUT', 0x03: 'Kambrook'} """ Mapping of numeric subtype values to strings, used in type_string """ ALIAS_TYPES = {'KlikAanKlikUit automatic': 0x00, 'NEXA automatic': 0x00, 'CHACON autometic': 0x00, 'HomeEasy UK': 0x00} """ Mapping of subtype aliases to the corresponding subtype value """ COMMANDS = {0x00: 'Off', 0x01: 'On', 0x02: 'Set level', 0x03: 'Group off', 0x04: 'Group on', 0x05: 'Set group level'} """ Mapping of command numeric values to strings, used for cmnd_string """ def __str__(self): return ("Lighting2 [subtype={0}, seqnbr={1}, id={2}, cmnd={3}, " + "level={4}, rssi={5}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.cmnd_string, self.level, self.rssi) def __repr__(self): return self.__str__() def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.id3 = None self.id4 = None self.id_combined = None self.unitcode = None self.cmnd = None self.level = None self.cmnd_string = None def parse_id(self, subtype, id_string): """Parse a string id into individual components""" try: self.packettype = 0x11 self.subtype = subtype self.id_combined = int(id_string[:7], 16) self.id1 = self.id_combined >> 24 self.id2 = self.id_combined >> 16 & 0xff self.id3 = self.id_combined >> 8 & 0xff self.id4 = self.id_combined & 0xff self.unitcode = int(id_string[8:]) self._set_strings() except ValueError as exc: raise ValueError("Invalid id_string") from exc if self.id_string != id_string: raise ValueError("Invalid id_string") def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.id3 = data[6] self.id4 = data[7] self.id_combined = (self.id1 << 24) + (self.id2 << 16) \ + (self.id3 << 8) + self.id4 self.unitcode = data[8] self.cmnd = data[9] self.level = data[10] self.rssi_byte = data[11] self.rssi = self.rssi_byte >> 4 self._set_strings() def set_transmit(self, subtype, seqnbr, id_combined, unitcode, cmnd, level): """Load data from individual data fields""" self.packetlength = 0x0b self.packettype = 0x11 self.subtype = subtype self.seqnbr = seqnbr self.id_combined = id_combined self.id1 = id_combined >> 24 self.id2 = id_combined >> 16 & 0xff self.id3 = id_combined >> 8 & 0xff self.id4 = id_combined & 0xff self.unitcode = unitcode self.cmnd = cmnd self.level = level self.rssi_byte = 0 self.rssi = 0 self.data = bytearray([self.packetlength, self.packettype, self.subtype, self.seqnbr, self.id1, self.id2, self.id3, self.id4, self.unitcode, self.cmnd, self.level, self.rssi_byte]) self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:07x}:{1}".format(self.id_combined, self.unitcode) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) if self.cmnd is not None: if self.cmnd in self.COMMANDS: self.cmnd_string = self.COMMANDS[self.cmnd] else: self.cmnd_string = self._UNKNOWN_CMND.format(self.cmnd) ############################################################################### # Lighting3 class ############################################################################### class Lighting3(Packet): """ Data class for the Lighting3 packet type """ TYPES = {0x00: 'Ikea Koppla'} """ Mapping of numeric subtype values to strings, used in type_string """ COMMANDS = {0x00: 'Bright', 0x08: 'Dim', 0x10: 'On', 0x11: 'Level 1', 0x12: 'Level 2', 0x13: 'Level 3', 0x14: 'Level 4', 0x15: 'Level 5', 0x16: 'Level 6', 0x17: 'Level 7', 0x18: 'Level 8', 0x19: 'Level 9', 0x1a: 'Off', 0x1c: 'Program'} """ Mapping of command numeric values to strings, used for cmnd_string """ def __str__(self): return ("Lighting3 [subtype={0}, seqnbr={1}, id={2}, cmnd={3}, " + "battery={4}, rssi={5}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.cmnd_string, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.system = None self.channel1 = None self.channel2 = None self.channel = None self.cmnd = None self.battery = None self.cmnd_string = None def parse_id(self, subtype, id_string): """Parse a string id into individual components""" try: self.packettype = 0x12 self.subtype = subtype self.system = int(id_string[:1], 16) self.channel = int(id_string[2:], 16) self.channel1 = self.channel & 0xff self.channel2 = self.channel >> 8 self._set_strings() except ValueError as exc: raise ValueError("Invalid id_string") from exc if self.id_string != id_string: raise ValueError("Invalid id_string") def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.system = data[4] self.channel1 = data[5] self.channel2 = data[6] self.channel = (self.channel2 << 8) + self.channel1 self.cmnd = data[7] self.rssi_byte = data[8] self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def set_transmit(self, subtype, seqnbr, system, channel, cmnd): """Load data from individual data fields""" self.packetlength = 0x08 self.packettype = 0x12 self.subtype = subtype self.seqnbr = seqnbr self.system = system self.channel = channel self.channel1 = channel & 0xff self.channel2 = channel >> 8 self.cmnd = cmnd self.rssi_byte = 0 self.battery = 0 self.rssi = 0 self.data = bytearray([self.packetlength, self.packettype, self.subtype, self.seqnbr, self.system, self.channel1, self.channel2, self.cmnd, self.rssi_byte]) self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:1x}:{1:03x}".format(self.system, self.channel) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) if self.cmnd is not None: if self.cmnd in self.COMMANDS: self.cmnd_string = self.COMMANDS[self.cmnd] else: self.cmnd_string = self._UNKNOWN_CMND.format(self.cmnd) ############################################################################### # Lighting4 class ############################################################################### class Lighting4(Packet): """ Data class for the Lighting4 packet type """ TYPES = {0x00: 'PT2262'} """ Mapping of numeric subtype values to strings, used in type_string """ COMMANDS = {0x00: 'Off', 0x01: 'On', 0x02: 'Off', 0x03: 'On', 0x04: 'Off', 0x05: 'On', 0x07: 'On', 0x09: 'On', 0x0c: 'On'} """ Mapping of command numeric values to strings, used for cmnd_string """ def __str__(self): return ("Lighting4 [subtype={0}, seqnbr={1}, cmd={2}, pulse={3}, " + "rssi={4}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.pulse, self.rssi) def __init__(self): """Constructor""" super().__init__() self.cmd1 = None self.cmd2 = None self.cmd3 = None self.cmd = None self.pulsehigh = None self.pulselow = None self.pulse = None self.cmnd_string = "" def parse_id(self, subtype, id_string): """Parse a string id into individual components""" try: self.packettype = 0x13 self.subtype = subtype self.cmd = int(id_string, 16) self.cmd1 = self.cmd >> 16 self.cmd2 = (self.cmd >> 8) & 0xff self.cmd3 = self.cmd & 0xff self._set_strings() except ValueError as exc: raise ValueError("Invalid id_string") from exc if self.id_string != id_string: raise ValueError("Invalid id_string") def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.cmd1 = data[4] self.cmd2 = data[5] self.cmd3 = data[6] self.cmd = (self.cmd1 << 16) + (self.cmd2 << 8) + self.cmd3 self.pulsehigh = data[7] self.pulselow = data[8] self.pulse = (self.pulsehigh << 8) + self.pulselow self.rssi_byte = data[9] self.rssi = self.rssi_byte >> 4 self._set_strings() def set_transmit(self, subtype, seqnbr, cmd, pulse): """Load data from individual data fields""" self.packetlength = 0x09 self.packettype = 0x13 self.subtype = subtype self.seqnbr = seqnbr self.cmd = cmd self.cmd1 = self.cmd >> 16 self.cmd2 = (self.cmd >> 8) & 0xff self.cmd3 = self.cmd & 0xff self.pulse = pulse self.pulsehigh = self.pulse >> 8 self.pulselow = self.pulse & 0xff self.rssi_byte = 0 self.rssi = 0 self.data = bytearray([self.packetlength, self.packettype, self.subtype, self.seqnbr, self.cmd1, self.cmd2, self.cmd3, self.pulsehigh, self.pulselow, self.rssi_byte]) self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:06x}".format(self.cmd) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) if self.cmd is not None: if self.cmd2 in self.COMMANDS: self.cmnd_string = self.COMMANDS[self.cmd2] else: self.cmnd_string = self._UNKNOWN_CMND.format(self.cmd) ############################################################################### # Lighting5 class ############################################################################### class Lighting5(Packet): """ Data class for the Lighting5 packet type """ TYPES = {0x00: 'LightwaveRF, Siemens', 0x01: 'EMW100 GAO/Everflourish', 0x02: 'BBSB new types', 0x03: 'MDREMOTE LED dimmer', 0x04: 'Conrad RSL2', 0x05: 'Livolo', 0x06: 'TRC02', 0x07: 'Aoke', 0x08: 'TRC02_2', 0x09: 'Eurodomest', 0x0A: 'Livolo appliance', 0x0B: 'RGB432W', 0x0C: 'MDREMOTE 107', 0x0D: 'Legrand CAD', 0x0E: 'Avantek', 0x0F: 'ProMax/IT', 0x10: 'MDREMOTE 108', 0x11: 'Kangtai'} """ Mapping of numeric subtype values to strings, used in type_string """ ALIAS_TYPES = {'LightwaveRF': 0x00, 'Siemens': 0x00, 'EMW100 GAO': 0x01, 'Everflourish': 0x01, 'ProMax': 0x0f, 'IT': 0x0f} """ Mapping of subtype aliases to the corresponding subtype value """ COMMANDS_00 = {0x00: 'Off', 0x01: 'On', 0x02: 'Group off', 0x03: 'Mood1', 0x04: 'Mood2', 0x05: 'Mood3', 0x06: 'Mood4', 0x07: 'Mood5', 0x0a: 'Unlock', 0x0b: 'Lock', 0x0c: 'All lock', 0x0d: 'Close (inline relay)', 0x0e: 'Stop (inline relay)', 0x0f: 'Open (inline relay)', 0x10: 'Set level'} """ Mapping of command numeric values to strings, used for cmnd_string """ COMMANDS_01 = {0x00: 'Off', 0x01: 'On', 0x02: 'Learn'} """ Mapping of command numeric values to strings, used for cmnd_string """ COMMANDS_02_04_0F = {0x00: 'Off', 0x01: 'On', 0x02: 'Group off', 0x03: 'Group on'} """ Mapping of command numeric values to strings, used for cmnd_string """ COMMANDS_03 = {0x00: 'Power', 0x01: 'Light', 0x02: 'Bright', 0x03: 'Dim', 0x04: '100%', 0x05: '50%', 0x06: '25%', 0x07: 'Mode+', 0x08: 'Speed-', 0x09: 'Speed+', 0x0a: 'Mode-'} """ Mapping of command numeric values to strings, used for cmnd_string """ COMMANDS_XX = {0x00: 'Off', 0x01: 'On'} """ Mapping of command numeric values to strings, used for cmnd_string """ def __str__(self): return ("Lighting5 [subtype={0}, seqnbr={1}, id={2}, cmnd={3}, " + "level={4}, rssi={5}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.cmnd_string, self.level, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.id3 = None self.id_combined = None self.unitcode = None self.cmnd = None self.level = None self.cmnd_string = None def parse_id(self, subtype, id_string): """( a string id into individual components""" try: self.packettype = 0x14 self.subtype = subtype self.id_combined = int(id_string[:6], 16) self.id1 = self.id_combined >> 16 self.id2 = self.id_combined >> 8 & 0xff self.id3 = self.id_combined & 0xff self.unitcode = int(id_string[7:]) self._set_strings() except ValueError as exc: raise ValueError("Invalid id_string") from exc if self.id_string != id_string: raise ValueError("Invalid id_string") def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.id3 = data[6] self.id_combined = (self.id1 << 16) + (self.id2 << 8) + self.id3 self.unitcode = data[7] self.cmnd = data[8] self.level = data[9] self.rssi_byte = data[10] self.rssi = self.rssi_byte >> 4 self._set_strings() def set_transmit(self, subtype, seqnbr, id_combined, unitcode, cmnd, level): """Load data from individual data fields""" self.packetlength = 0x0a self.packettype = 0x14 self.subtype = subtype self.seqnbr = seqnbr self.id_combined = id_combined self.id1 = id_combined >> 16 self.id2 = id_combined >> 8 & 0xff self.id3 = id_combined & 0xff self.unitcode = unitcode self.cmnd = cmnd self.level = level self.rssi_byte = 0 self.rssi = 0 self.data = bytearray([self.packetlength, self.packettype, self.subtype, self.seqnbr, self.id1, self.id2, self.id3, self.unitcode, self.cmnd, self.level, self.rssi_byte]) self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" # pylint: disable=too-many-branches self.id_string = "{0:06x}:{1}".format(self.id_combined, self.unitcode) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) if self.cmnd is not None: if self.subtype == 0x00 and self.cmnd in self.COMMANDS_00: self.cmnd_string = self.COMMANDS_00[self.cmnd] elif self.subtype == 0x01 and self.cmnd in self.COMMANDS_01: self.cmnd_string = self.COMMANDS_01[self.cmnd] elif self.subtype == 0x02 and self.cmnd in self.COMMANDS_02_04_0F: self.cmnd_string = self.COMMANDS_02_04_0F[self.cmnd] elif self.subtype == 0x03 and self.cmnd in self.COMMANDS_03: self.cmnd_string = self.COMMANDS_03[self.cmnd] elif self.subtype == 0x04 and self.cmnd in self.COMMANDS_02_04_0F: self.cmnd_string = self.COMMANDS_02_04_0F[self.cmnd] elif self.subtype >= 0x05 and self.cmnd in self.COMMANDS_XX: self.cmnd_string = self.COMMANDS_XX[self.cmnd] elif self.subtype >= 0x0f and self.cmnd in self.COMMANDS_02_04_0F: self.cmnd_string = self.COMMANDS_02_04_0F[self.cmnd] else: self.cmnd_string = self._UNKNOWN_CMND.format(self.cmnd) ############################################################################### # Lighting6 class ############################################################################### class Lighting6(Packet): """ Data class for the Lighting6 packet type """ TYPES = {0x00: 'Blyss'} """ Mapping of numeric subtype values to strings, used in type_string """ COMMANDS = {0x00: 'On', 0x01: 'Off', 0x02: 'Group on', 0x03: 'Group off'} """ Mapping of command numeric values to strings, used for cmnd_string """ def __str__(self): return ("Lighting6 [subtype={0}, seqnbr={1}, id={2}, cmnd={3}, " + "cmndseqnbr={4}, rssi={5}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.cmnd_string, self.cmndseqnbr, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.id_combined = None self.groupcode = None self.unitcode = None self.cmnd = None self.cmndseqnbr = None self.rfu = None self.level = None self.cmnd_string = None def parse_id(self, subtype, id_string): """Parse a string id into individual components""" try: self.packettype = 0x15 self.subtype = subtype self.id_combined = int(id_string[:4], 16) self.id1 = self.id_combined >> 8 & 0xff self.id2 = self.id_combined & 0xff self.groupcode = ord(id_string[5]) self.unitcode = int(id_string[6:]) self._set_strings() except ValueError as exc: raise ValueError("Invalid id_string") from exc if self.id_string != id_string: raise ValueError("Invalid id_string") def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.id_combined = (self.id1 << 8) + self.id2 self.groupcode = data[6] self.unitcode = data[7] self.cmnd = data[8] self.cmndseqnbr = data[9] self.rfu = data[10] self.rssi_byte = data[11] self.rssi = self.rssi_byte >> 4 self._set_strings() def set_transmit(self, subtype, seqnbr, id_combined, groupcode, unitcode, cmnd, cmndseqnbr): """Load data from individual data fields""" self.packetlength = 0x0b self.packettype = 0x15 self.subtype = subtype self.seqnbr = seqnbr self.id_combined = id_combined self.id1 = id_combined >> 8 & 0xff self.id2 = id_combined & 0xff self.groupcode = groupcode self.unitcode = unitcode self.cmnd = cmnd self.cmndseqnbr = cmndseqnbr self.rfu = 0 self.rssi_byte = 0 self.rssi = 0 self.data = bytearray([self.packetlength, self.packettype, self.subtype, self.seqnbr, self.id1, self.id2, self.groupcode, self.unitcode, self.cmnd, self.cmndseqnbr, self.rfu, self.rssi_byte]) self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:04x}:{1}{2}".format(self.id_combined, chr(self.groupcode), self.unitcode) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) if self.cmnd is not None: if self.cmnd in self.COMMANDS: self.cmnd_string = self.COMMANDS[self.cmnd] else: self.cmnd_string = self._UNKNOWN_CMND.format(self.cmnd) ############################################################################### # SensorPacket class ############################################################################### class SensorPacket(Packet): """ Abstract superclass for all sensor related packets """ HUMIDITY_TYPES = {0x00: 'dry', 0x01: 'comfort', 0x02: 'normal', 0x03: 'wet', -1: 'unknown humidity'} """ Mapping of humidity types to string """ FORECAST_TYPES = {0x00: 'no forecast available', 0x01: 'sunny', 0x02: 'partly cloudy', 0x03: 'cloudy', 0x04: 'rain', -1: 'unknown forecast'} """ Mapping of forecast types to string """ ############################################################################### # Undecoded class ############################################################################### class Undecoded(SensorPacket): """ Data class for the Undecoded packet type """ TYPES = { 0x00: 'ac', 0x01: 'arc', 0x02: 'ati', 0x03: 'hideki/upm', 0x04: 'lacrosse/viking', 0x05: 'ad', 0x06: 'mertik', 0x07: 'oregon1', 0x08: 'oregon2', 0x09: 'oregon3', 0x0A: 'proguard', 0x0B: 'visonic', 0x0C: 'nec', 0x0D: 'fs20', 0x0E: 'reserved', 0x0F: 'blinds', 0x10: 'rubicson', 0x11: 'ae', 0x12: 'fineoffset', 0x13: 'rgb', 0x14: 'rts', 0x15: 'selectplus', 0x16: 'homeconfort', 0x17: 'edisio', 0x18: 'honeywell', 0x19: 'funkbus', 0x1A: 'byronsx', } """ Mapping of numeric subtype values to strings, used in type_string """ def __str__(self): return ("Undecoded [subtype={0} payload={1}]").format(self.type_string, self.payload) def __init__(self): """Constructor""" super().__init__() self.payload = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.payload = data[4:] self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = 'Undecoded' if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = 'Unknown' ############################################################################### # Temp class ############################################################################### class Temp(SensorPacket): """ Data class for the Temp1 packet type """ TYPES = {0x01: 'THR128/138, THC138', 0x02: 'THC238/268,THN132,THWR288,THRN122,THN122,AW129/131', 0x03: 'THWR800', 0x04: 'RTHN318', 0x05: 'La Crosse TX2, TX3, TX4, TX17', 0x06: 'TS15C', 0x07: 'Viking 02811', 0x08: 'La Crosse WS2300', 0x09: 'RUBiCSON', 0x0A: 'TFA 30.3133', 0x0B: 'WT0122'} """ Mapping of numeric subtype values to strings, used in type_string """ def __str__(self): return ("Temp [subtype={0}, seqnbr={1}, id={2}, temp={3}, " + "battery={4}, rssi={5}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.temp, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.temphigh = None self.templow = None self.temp = None self.battery = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.temphigh = data[6] self.templow = data[7] self.temp = float(((self.temphigh & 0x7f) << 8) + self.templow) / 10 if self.temphigh >= 0x80: self.temp = -1 * self.temp self.rssi_byte = data[8] self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:02x}:{1:02x}".format(self.id1, self.id2) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) ############################################################################### # Bbq class ############################################################################### class Bbq(SensorPacket): """ Data class for the Temp1 packet type """ TYPES = {0x01: 'BBQ1 - Maverick ET-732'} """ Mapping of numeric subtype values to strings, used in type_string """ def __str__(self): return ("Bbq [subtype={0}, seqnbr={1}, id={2}, temp1={3}, " + "temp2={4}, battery={5}, rssi={6}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.temp1, self.temp2, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.id3 = None self.id_combined = None self.temp1 = None self.temp2 = None self.battery = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.id3 = data[6] self.id_combined = (self.id1 << 16) + (self.id2 << 8) + self.id3 self.temp1 = data[7] self.temp2 = data[9] self.rssi_byte = data[10] self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:06x}:{1}".format(self.id_combined, self.packettype) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) ############################################################################### # Humid class ############################################################################### class Humid(SensorPacket): """ Data class for the Humid packet type """ TYPES = {0x01: 'LaCrosse TX3', 0x02: 'LaCrosse WS2300', 0x03: 'Inovalley S80'} """ Mapping of numeric subtype values to strings, used in type_string """ def __str__(self): return ("Humid [subtype={0}, seqnbr={1}, id={2}, " + "humidity={3}, humidity_status={4}, battery={5}, rssi={6}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.humidity, self.humidity_status, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.humidity = None self.humidity_status = None self.humidity_status_string = None self.battery = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.humidity = data[6] self.humidity_status = data[7] self.rssi_byte = data[8] self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:02x}:{1:02x}".format(self.id1, self.id2) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) if self.humidity_status in self.HUMIDITY_TYPES: self.humidity_status_string = \ self.HUMIDITY_TYPES[self.humidity_status] else: self.humidity_status_string = self.HUMIDITY_TYPES[-1] ############################################################################### # TempHumid class ############################################################################### class TempHumid(SensorPacket): """ Data class for the TempHumid packet type """ TYPES = {0x01: 'THGN122/123, THGN132, THGR122/228/238/268', 0x02: 'THGR810, THGN800', 0x03: 'RTGR328', 0x04: 'THGR328', 0x05: 'WTGR800', 0x06: 'THGR918/928, THGRN228, THGN500', 0x07: 'TFA TS34C, Cresta', 0x08: 'WT260,WT260H,WT440H,WT450,WT450H', 0x09: 'Viking 02035,02038', 0x0A: 'Rubicson', 0x0B: 'EW109', 0x0C: 'Imagintronix', 0x0D: 'Alecto WS1700', 0x0E: 'Alecto'} """ Mapping of numeric subtype values to strings, used in type_string """ def __str__(self): return ("TempHumid [subtype={0}, seqnbr={1}, id={2}, temp={3}, " + "humidity={4}, humidity_status={5}, battery={6}, rssi={7}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.temp, self.humidity, self.humidity_status, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.temphigh = None self.templow = None self.temp = None self.humidity = None self.humidity_status = None self.humidity_status_string = None self.battery = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.temphigh = data[6] self.templow = data[7] self.temp = float(((self.temphigh & 0x7f) << 8) + self.templow) / 10 if self.temphigh >= 0x80: self.temp = -1 * self.temp self.humidity = data[8] self.humidity_status = data[9] self.rssi_byte = data[10] self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:02x}:{1:02x}".format(self.id1, self.id2) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) if self.humidity_status in self.HUMIDITY_TYPES: self.humidity_status_string = \ self.HUMIDITY_TYPES[self.humidity_status] else: self.humidity_status_string = self.HUMIDITY_TYPES[-1] ############################################################################### # Baro class ############################################################################### class Baro(SensorPacket): """ Data class for the Baro packet type """ TYPES = {} """ Mapping of numeric subtype values to strings, used in type_string """ def __str__(self): return ("Baro [subtype={0}, seqnbr={1}, id={2}, baro={3}, " + "forecast={4}, battery={5}, rssi={6}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.baro, self.forecast, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.baro1 = None self.baro2 = None self.baro = None self.forecast = None self.forecast_string = None self.battery = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.baro1 = data[6] self.baro2 = data[7] self.baro = (self.baro1 << 8) + self.baro2 self.forecast = data[8] self.rssi_byte = data[9] self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:02x}:{1:02x}".format(self.id1, self.id2) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) if self.forecast in self.FORECAST_TYPES: self.forecast_string = self.FORECAST_TYPES[self.forecast] else: self.forecast_string = self.FORECAST_TYPES[-1] ############################################################################### # RFXMeter class ############################################################################### class RfxMeter(SensorPacket): """ Data class for the RFXMeter packet type """ TYPES = {0x00: 'RFXMeter Count', 0x01: 'RFXMeter Interval', 0x02: 'RFXMeter Calibration', 0x03: 'RFXMeter Address', 0x04: 'RFXMeter Counter reset', 0x0B: 'RFXMeter Counter set', 0x0C: 'RFXMeter Set interval', 0x0D: 'RFXMeter Set calibration', 0x0E: 'RFXMeter Set Address', 0x0F: 'RFXMeter Ident'} """ Mapping of numeric subtype values to strings, used in type_string """ def __str__(self): return ("RFXMeter [subtype={0}, seqnbr={1}, id={2}, value3={3}, " + "value2={4}, value1={5}, value={6}, rssi={7}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.value3, self.value2, self.value1, self.value, self.rssi) def __init__(self): """Constructor""" super().__init__() self.idbyte = None self.value = None self.value3 = None self.value2 = None self.value1 = None self.type_string = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.idbyte = data[4] self.value3 = data[7] self.value2 = data[8] self.value1 = data[9] self.value = (self.value3 << 16) + (self.value2 << 8) + self.value1 self.rssi_byte = data[10] self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:02x}".format(self.idbyte) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) ############################################################################### # TempHumidBaro class ############################################################################### class TempHumidBaro(SensorPacket): """ Data class for the TempHumidBaro packet type """ TYPES = {0x01: 'BTHR918', 0x02: 'BTHR918N, BTHR968'} """ Mapping of numeric subtype values to strings, used in type_string """ def __str__(self): return ("TempHumidBaro [subtype={0}, seqnbr={1}, id={2}, temp={3}, " + "humidity={4}, humidity_status={5}, baro={6}, forecast={7}, " + "battery={8}, rssi={9}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.temp, self.humidity, self.humidity_status, self.baro, self.forecast, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.temphigh = None self.templow = None self.temp = None self.humidity = None self.humidity_status = None self.humidity_status_string = None self.baro1 = None self.baro2 = None self.baro = None self.forecast = None self.forecast_string = None self.battery = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.temphigh = data[6] self.templow = data[7] self.temp = float(((self.temphigh & 0x7f) << 8) + self.templow) / 10 if self.temphigh >= 0x80: self.temp = -1 * self.temp self.humidity = data[8] self.humidity_status = data[9] self.baro1 = data[10] self.baro2 = data[11] self.baro = (self.baro1 << 8) + self.baro2 self.forecast = data[12] self.rssi_byte = data[13] self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:02x}:{1:02x}".format(self.id1, self.id2) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) if self.humidity_status in self.HUMIDITY_TYPES: self.humidity_status_string = \ self.HUMIDITY_TYPES[self.humidity_status] else: self.humidity_status_string = self.HUMIDITY_TYPES[-1] if self.forecast in self.FORECAST_TYPES: self.forecast_string = self.FORECAST_TYPES[self.forecast] else: self.forecast_string = self.FORECAST_TYPES[-1] ############################################################################### # Rain class ############################################################################### class Rain(SensorPacket): """ Data class for the rain packet type """ TYPES = { 0x01: 'RGR126/682/918', 0x02: 'PCR800', 0x03: 'TFA', 0x04: 'UPM RG700', 0x05: 'WS2300', 0x06: 'La Crosse TX5', 0x07: 'Alecto', 0x08: 'Davis', 0x09: 'TFA 30.3233.01' } def __str__(self): return ("Rain [subtype={0}, seqnbr={1}, id={2}, rainrate={3}, " + "raintotal={4}, battery={5}, rssi={6}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.rainrate, self.raintotal, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.rainrate1 = None self.rainrate2 = None self.rainrate = None self.raintotal1 = None self.raintotal2 = None self.raintotal3 = None self.raintotal = None self.battery = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.rainrate1 = data[6] self.rainrate2 = data[7] if self.subtype in (1, 2): self.rainrate = float((self.rainrate1 << 8) + self.rainrate2) if self.subtype == 2: self.rainrate = float(self.rainrate) / 100 self.raintotal1 = data[8] self.raintotal2 = data[9] self.raintotal3 = data[10] if self.subtype in (1, 2, 3, 4, 5, 7): self.raintotal = float((self.raintotal1 << 16) + (self.raintotal2 << 8) + self.raintotal3) / 10 elif self.subtype == 6: self.raintotal = 0.266 * self.raintotal3 elif self.subtype == 8: # cartridge can be 0.01 inch rather than 0.2mm self.raintotal = 0.2 * self.raintotal3 elif self.subtype == 9: self.raintotal = 0.254 * float((self.raintotal2 << 8) + self.raintotal3) self.rssi_byte = data[11] self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:02x}:{1:02x}".format(self.id1, self.id2) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) ############################################################################### # TempRain class ############################################################################### class TempRain(SensorPacket): """ Data class for the TempRain packet type """ TYPES = {0x01: 'TR1 - WS1200'} """ Mapping of numeric subtype values to strings, used in type_string """ def __str__(self): return ("TempRain [subtype={0}, seqnbr={1}, id={2}, temp={3}, " + "totalrain={4}, battery={5}, rssi={6}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.temp, self.totalrain, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.temphigh = None self.templow = None self.temp = None self.raintotal = None self.battery = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.temphigh = data[6] self.templow = data[7] self.temp = float(((self.temphigh & 0x7f) << 8) + self.templow) / 10 if self.temphigh >= 0x80: self.temp = -1 * self.temp self.raintotal = float(((data[8] & 0x7f) << 8) + data[9]) / 10 self.rssi_byte = data[10] self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:02x}:{1:02x}".format(self.id1, self.id2) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) ############################################################################### # Wind class ############################################################################### class Wind(SensorPacket): """ Data class for the Wind packet type """ TYPES = {0x01: 'WTGR800', 0x02: 'WGR800', 0x03: 'STR918, WGR918, WGR928', 0x04: 'TFA', 0x05: 'UPM WDS500', 0x06: 'WS2300', 0x07: 'Alecto WS4500'} """ Mapping of numeric subtype values to strings, used in type_string """ def __str__(self): return ("Wind [subtype={0}, seqnbr={1}, id={2}, direction={3}, " + "average_speed={4}, gust={5}, temperature={6}, chill={7}, " + "battery={8}, rssi={9}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.direction, self.average_speed, self.gust, self.temperature, self.chill, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.direction = None self.average_speed = None self.gust = None self.temperature = None self.temphigh = None self.templow = None self.chill = None self.chillhigh = None self.chilllow = None self.battery = None self.rssi = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.direction = data[6] * 256 + data[7] if self.subtype != 0x05: self.average_speed = (data[8] * 256.0 + data[9]) / 10.0 self.gust = (data[10] * 256.0 + data[11]) / 10.0 if self.subtype in (0x04, 0x08, 0x09): self.temphigh = data[12] self.templow = data[13] self.temperature = float(((self.temphigh & 0x7f) << 8) + self.templow) / 10 if self.temphigh >= 0x80: self.temperature = -1 * self.temperature self.chillhigh = data[14] self.chilllow = data[15] self.chill = float(((self.chillhigh & 0x7f) << 8) + self.chilllow) / 10 if self.chillhigh >= 0x80: self.chill = -1 * self.chill if self.subtype == 0x03: self.battery = data[16] else: self.rssi_byte = data[16] self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:02x}:{1:02x}".format(self.id1, self.id2) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) ############################################################################### # UV class ############################################################################### class UV(SensorPacket): """ Data class for the uv packet type """ TYPES = {0x01: 'UVN128, UV138', 0x02: 'UVN800', 0x03: 'TFA'} def __str__(self): return ("UV [subtype={0}, seqnbr={1}, id={2}, uv={3}," + " battery={5}, rssi={6}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.uvi, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.uvi = None self.battery = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.uvi = float(data[6]) / 10 self.rssi_byte = data[9] self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:02x}:{1:02x}".format(self.id1, self.id2) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) ############################################################################### # Energy1 class ############################################################################### class Energy1(SensorPacket): """ Data class for the Energy "ELEC1" packet type """ TYPES = {0x01: 'ELEC1, Electrisave'} def __str__(self): return ("Energy1 [subtype={0}, seqnbr={1}, id={2}, count={3}, " + "current_amps1={4}, current_amps2={5}, current_amps3={6}, " + "battery={7}, rssi={8}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.count, self.currentamps1, self.currentamps2, self.currentamps3, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.count = None self.currentamps1 = None self.currentamps2 = None self.currentamps3 = None self.battery = None self.rssi = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.count = data[6] self.currentamps1 = float((data[7] << 8) + data[8]) / 10 self.currentamps2 = float((data[9] << 8) + data[10]) / 10 self.currentamps3 = float((data[11] << 8) + data[12]) / 10 self.rssi_byte = data[13] self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:02x}:{1:02x}".format(self.id1, self.id2) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) ############################################################################### # Energy class ############################################################################### class Energy(SensorPacket): """ Data class for the Energy packet type """ TYPES = {0x01: 'ELEC2, CM119/160', 0x02: 'ELEC3, CM180'} """ Mapping of numeric subtype values to strings, used in type_string """ def __str__(self): return ("Energy [subtype={0}, seqnbr={1}, id={2}, count={3}, " + "current_watts={4}, total_watts={5}" + "battery={6}, rssi={7}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.count, self.currentwatt, self.totalwatts, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.count = None self.currentwatt = None self.totalwatts = None self.battery = None self.rssi = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.count = data[6] self.currentwatt = ((data[7] * pow(2, 24)) + (data[8] << 16) + (data[9] << 8) + data[10]) self.totalwatts = ((data[11] * pow(2, 40)) + (data[12] * pow(2, 32)) + (data[13] * pow(2, 24)) + (data[14] << 16) + (data[15] << 8) + data[16]) / 223.666 if self.subtype == 0x03: self.battery = data[17] else: self.rssi_byte = data[17] self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:02x}:{1:02x}".format(self.id1, self.id2) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) ############################################################################### # Energy4 class ############################################################################### class Energy4(SensorPacket): """ Data class for the Energy "ELEC4" packet type """ TYPES = {0x01: 'ELEC4, CM180i'} """ Mapping of numeric subtype values to strings, used in type_string """ def __str__(self): return ("Energy4 [subtype={0}, seqnbr={1}, id={2}, count={3}, " + "current_amps1={4}, current_amps2={5}, current_amps3={6}, " + "total_watts={7}, battery={8}, rssi={9}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.count, self.currentamps1, self.currentamps2, self.currentamps3, self.totalwatthours, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.count = None self.currentamps1 = None self.currentamps2 = None self.currentamps3 = None self.totalwatthours = None self.battery = None self.rssi = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.count = data[6] self.currentamps1 = float((data[7] << 8) + data[8]) / 10 self.currentamps2 = float((data[9] << 8) + data[10]) / 10 self.currentamps3 = float((data[11] << 8) + data[12]) / 10 self.totalwatthours = ((data[13] * pow(2, 40)) + (data[14] * pow(2, 32)) + (data[15] * pow(2, 24)) + (data[16] << 16) + (data[17] << 8) + data[18]) / 223.666 self.rssi_byte = data[19] self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:02x}:{1:02x}".format(self.id1, self.id2) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) ############################################################################### # Energy5 class ############################################################################### class Energy5(SensorPacket): """ Data class for the Energy "ELEC5" packet type """ TYPES = {0x01: 'ELEC5, Revolt'} """ Mapping of numeric subtype values to strings, used in type_string """ def __str__(self): return ("Energy5 [subtype={0}, seqnbr={1}, id={2}, voltage={3}, " + "current_amps={4}, current_watts={5}, total_watts={6}, " + "powerfactor={7}, frequency={8}, rssi={9}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.voltage, self.currentamps, self.currentwatt, self.totalwatthours, self.powerfactor, self.frequency, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.voltage = None self.currentamps = None self.currentwatt = None self.totalwatthours = None self.powerfactor = None self.frequency = None self.rssi = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.voltage = data[6] self.currentamps = float((data[7] << 8) + data[8]) / 100 self.currentwatt = float((data[9] << 8) + data[10]) / 10 self.totalwatthours = float((data[11] << 8) + data[12]) * 10 self.powerfactor = float(data[13]) / 100 self.frequency = float(data[14]) self.rssi_byte = data[15] self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:02x}:{1:02x}".format(self.id1, self.id2) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) ############################################################################### # Cartelectronic class Encoder et Linky (TIC not treated - old standard) ############################################################################### class Cartelectronic(SensorPacket): """ Data class for the Cartelectronic packet type """ TYPES = {0x01: 'CARTELECTRONIC_TIC', 0x02: 'CARTELECTRONIC_ENCODER', 0x03: 'CARTELECTRONIC_LINKY'} """ Mapping of numeric subtype values to strings, used in type_string """ def __str__(self): return ("Cartelectronic [subtype={0}, seqnbr={1}, id={2}, " + "counter1={3}, counter2={4}, " + "conswatthours={5}, prodwatthours={6}, tarif_num={7}, " + "voltage={8}, currentwatt={9}, teleinfo_ok={10}," "battery={11}, rssi={12}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.counter1, self.counter2, self.conswatthours, self.prodwatthours, self.tarif_num, self.voltage, self.currentwatt, self.teleinfo_ok, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.id3 = None self.id4 = None self.id5 = None self.id_combined = None self.counter1 = None self.counter2 = None self.conswatthours = None self.prodwatthours = None self.tarif_num = None self.voltage = None self.currentwatt = None self.teleinfo_ok = None self.state_byte = None self.battery = None self.rssi = None self.contract_type = None def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.id3 = data[6] self.id4 = data[7] self.id_combined = ((self.id1 << 24) + (self.id2 << 16) + (self.id3 << 8) + self.id4) if self.subtype == 0x01: # TIC self.id5 = data[8] self.id_combined = (self.id_combined << 8) + self.id5 self.contract_type = data[9] self.counter1 = int.from_bytes(data[10:14], 'big') self.counter2 = int.from_bytes(data[14:18], 'big') if data[20] & 0x02: self.currentwatt = int.from_bytes(data[18:20], 'big') else: self.currentwatt = None self.state_byte = data[20] self.teleinfo_ok = not (data[20] & 0x04) == 0x04 self.rssi_byte = data[21] elif self.subtype == 0x02: # Cartelectronic Encoder self.counter1 = ((data[8] * pow(2, 24)) + (data[9] << 16) + (data[10] << 8) + data[11]) self.counter2 = ((data[12] * pow(2, 24)) + (data[13] << 16) + (data[14] << 8) + data[15]) self.rssi_byte = data[17] elif self.subtype == 0x03: # Cartelectronic Linky self.conswatthours = ((data[8] * pow(2, 24)) + (data[9] << 16) + (data[10] << 8) + data[11]) self.prodwatthours = ((data[12] * pow(2, 24)) + (data[13] << 16) + (data[14] << 8) + data[15]) self.tarif_num = data[16] & 0x0f self.voltage = data[17] + 200 self.currentwatt = (data[18] << 8) + data[19] self.state_byte = data[20] self.teleinfo_ok = not (data[20] & 0x04) == 0x04 self.rssi_byte = data[21] self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:08x}".format(self.id_combined) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) ############################################################################### # Chime class ############################################################################### class Chime(Packet): """ Data class for the Chime packet type """ TYPES = {0x00: 'Byron SX', 0x01: 'Byron MP001', 0x02: 'Select Plus', 0x03: 'Select Plus 3', 0x04: 'Envivo'} """ Mapping of numeric subtype values to strings, used in type_string """ COMMANDS = { sound: "Sound {}".format(sound) for sound in range(16) } """ Mapping of a chime sound to a descriptive name. """ def __str__(self): return ("Chime [subtype={0}, seqnbr={1}, id={2}, sound={3}, " + "rssi={5}, cmdn={6}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.sound, self.rssi, self.cmnd_string) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.sound = None self.rssi = None self.cmnd = None self.cmnd_string = None def parse_id(self, subtype, id_string): """Parse a string id into individual components""" try: self.packettype = 0x16 self.subtype = subtype self.id1 = int(id_string[:2], 16) self.id2 = int(id_string[3:5], 16) self._set_strings() except ValueError as exc: raise ValueError("Invalid id_string") from exc if self.id_string != id_string: raise ValueError("Invalid id_string") def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.sound = data[6] self.rssi_byte = data[7] self.rssi = self.rssi_byte >> 4 self._set_strings() def set_transmit(self, subtype, seqnbr, id1, id2, sound): """Load data from individual data fields""" self.packetlength = 0x07 self.packettype = 0x16 self.subtype = subtype self.seqnbr = seqnbr self.id1 = id1 self.id2 = id2 self.sound = sound self.rssi = 0 self.rssi_byte = self.rssi << 4 self.data = bytearray([self.packetlength, self.packettype, self.subtype, self.seqnbr, self.id1, self.id2, self.sound, self.rssi_byte]) def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:02x}:{1:02x}".format(self.id1, self.id2) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) self.cmnd_string = self.COMMANDS.get(self.sound, "Sound") ############################################################################### # Security1 class ############################################################################### class Security1(SensorPacket): """ Data class for the Security1 packet type """ TYPES = {0x00: 'X10 Security', 0x01: 'X10 Security Motion Detector', 0x02: 'X10 Security Remote', 0x03: 'KD101 Smoke Detector', 0x04: 'Visonic Powercode Door/Window Sensor Primary Contact', 0x05: 'Visonic Powercode Motion Detector', 0x06: 'Visonic Codesecure', 0x07: 'Visonic Powercode Door/Window Sensor Auxilary Contact', 0x08: 'Meiantech', 0x09: 'Alecto SA30 Smoke Detector', 0x0A: 'RM174RF Smoke Detector'} """ Mapping of numeric subtype values to strings, used in type_string """ STATUS = {0x00: 'Normal', 0x01: 'Normal Delayed', 0x02: 'Alarm', 0x03: 'Alarm Delayed', 0x04: 'Motion', 0x05: 'No Motion', 0x06: 'Panic', 0x07: 'End Panic', 0x08: 'IR', 0x09: 'Arm Away', 0x0A: 'Arm Away Delayed', 0x0B: 'Arm Home', 0x0C: 'Arm Home Delayed', 0x0D: 'Disarm', 0x10: 'Light 1 Off', 0x11: 'Light 1 On', 0x12: 'Light 2 Off', 0x13: 'Light 2 On', 0x14: 'Dark Detected', 0x15: 'Light Detected', 0x16: 'Battery low', 0x17: 'Pairing KD101', 0x80: 'Normal Tamper', 0x81: 'Normal Delayed Tamper', 0x82: 'Alarm Tamper', 0x83: 'Alarm Delayed Tamper', 0x84: 'Motion Tamper', 0x85: 'No Motion Tamper'} """ Mapping of numeric status values to strings, used in type_string """ def __str__(self): return ("Security1 [subtype={0}, seqnbr={1}, id={2}, status={3}, " + "battery={4}, rssi={5}]") \ .format(self.type_string, self.seqnbr, self.id_string, self.security1_status_string, self.battery, self.rssi) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.id3 = None self.id_combined = None self.security1_status = None self.battery = None self.rssi = None self.security1_status_string = 'unknown' def parse_id(self, subtype, id_string): """Parse a string id into individual components""" try: self.packettype = 0x20 self.subtype = subtype self.id_combined = int(id_string[:6], 16) self.id1 = self.id_combined >> 16 self.id2 = self.id_combined >> 8 & 0xff self.id3 = self.id_combined & 0xff self._set_strings() except ValueError as exc: raise ValueError("Invalid id_string") from exc if self.id_string != id_string: raise ValueError("Invalid id_string") def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.id3 = data[6] self.id_combined = (self.id1 << 16) + (self.id2 << 8) + self.id3 self.security1_status = data[7] self.rssi_byte = data[8] if self.subtype not in (0x03, 0x09, 0x0A): self.battery = self.rssi_byte & 0x0f self.rssi = self.rssi_byte >> 4 self._set_strings() def set_transmit(self, subtype, seqnbr, id_combined, status): """Load data from individual data fields""" self.packetlength = 0x08 self.packettype = 0x20 self.subtype = subtype self.seqnbr = seqnbr self.id_combined = id_combined self.id1 = id_combined >> 16 self.id2 = id_combined >> 8 & 0xff self.id3 = id_combined & 0xff self.security1_status = status self.rssi_byte = 0 self.battery = 0 self.rssi = 0 self.data = bytearray([self.packetlength, self.packettype, self.subtype, self.seqnbr, self.id1, self.id2, self.id3, self.security1_status, self.rssi_byte]) self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:06x}:{1}".format(self.id_combined, self.packettype) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) if self.security1_status in self.STATUS: self.security1_status_string = self.STATUS[self.security1_status] ############################################################################### # Rfy class ############################################################################### class Rfy(Packet): """ Data class for the Rfy packet type """ TYPES = {0x00: 'Rfy', 0x01: 'Rfy Extended', 0x03: 'ASA'} """ Mapping of numeric subtype values to strings, used in type_string """ COMMANDS = {0x00: 'Stop', 0x01: 'Up', 0x03: 'Down', 0x07: 'Program', 0x0F: '0.5 Seconds Up', 0x10: '0.5 Seconds Down', 0x11: '2 Seconds Up', 0x12: '2 Seconds Down', 0x13: 'Enable sun automation', 0x14: 'Disable sun automation'} """ Mapping of command numeric values to strings, used for cmnd_string """ def __repr__(self): return self.__str__() def __str__(self): return "Rfy [subtype={0}, seqnbr={1}, id={2}, cmnd={3}, rssi={4}]" \ .format( self.subtype, self.seqnbr, self.id_string, self.cmnd_string, self.rssi ) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.id3 = None self.id_combined = None self.unitcode = None self.cmnd = None self.cmnd_string = None self.rfu1 = None self.rfu2 = None self.rfu3 = None def parse_id(self, subtype, id_string): """( a string id into individual components""" try: self.packettype = 0x1a self.subtype = subtype self.id_combined = int(id_string[:6], 16) self.id1 = self.id_combined >> 16 self.id2 = self.id_combined >> 8 & 0xff self.id3 = self.id_combined & 0xff self.unitcode = int(id_string[7:]) self._set_strings() except ValueError as exc: raise ValueError("Invalid id_string") from exc if self.id_string != id_string: raise ValueError("Invalid id_string") def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.id3 = data[6] self.id_combined = (self.id1 << 16) + (self.id2 << 8) + self.id3 self.unitcode = data[7] # Packet without command has been used in home assistant if self.packetlength >= 8: self.cmnd = data[8] # Packet was extended in 9.17 if self.packetlength >= 12: self.rfu1 = data[9] self.rfu2 = data[10] self.rfu3 = data[11] self.rssi_byte = data[12] self.rssi = self.rssi_byte >> 4 self._set_strings() def set_transmit(self, subtype, seqnbr, id_combined, unitcode, cmnd): """Load data from individual data fields""" self.packetlength = 0x0C self.packettype = 0x1a self.subtype = subtype self.seqnbr = seqnbr self.id_combined = id_combined self.id1 = id_combined >> 16 self.id2 = id_combined >> 8 & 0xff self.id3 = id_combined & 0xff self.unitcode = unitcode self.cmnd = cmnd self.rfu1 = 0 self.rfu2 = 0 self.rfu3 = 0 self.rssi_byte = 0 self.rssi = 0 self.data = bytearray([self.packetlength, self.packettype, self.subtype, self.seqnbr, self.id1, self.id2, self.id3, self.unitcode, self.cmnd, self.rfu1, self.rfu2, self.rfu3, self.rssi_byte]) self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:06x}:{1}".format(self.id_combined, self.unitcode) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) if self.cmnd is not None: if self.cmnd in self.COMMANDS: self.cmnd_string = self.COMMANDS[self.cmnd] else: self.cmnd_string = self._UNKNOWN_CMND.format(self.cmnd) ############################################################################### # RollerTrol class ############################################################################### class RollerTrol(Packet): """ Data class for the RollerTrol packet type """ TYPES = {0x00: 'RollerTrol', 0x01: 'BlindsT1 / Hasta old', 0x02: 'BlindsT2 / A-OK RF01', 0x03: 'BlindsT3 / A-OK AC114', 0x04: 'BlindsT4 / Raex YR1326', 0x05: 'BlindsT5 / Media Mount', 0x06: 'BlindsT6 / DC106/Rohrmotor24-RMF/Yooda', 0x07: 'BlindsT7 / Forest'} """ Mapping of numeric subtype values to strings, used in type_string """ COMMANDS = {0x02: 'Stop', 0x00: 'Up', 0x01: 'Down'} """ Mapping of command numeric values to strings, used for cmnd_string """ def __repr__(self): return self.__str__() def __str__(self): return ("RollerTrol [subtype={0}, seqnbr={1}, id={2}, cmnd={3}, " + "rssi={4}]") \ .format( self.subtype, self.seqnbr, self.id_string, self.cmnd_string, self.rssi ) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.id3 = None self.id_combined = None self.unitcode = None self.cmnd = None self.cmnd_string = None def parse_id(self, subtype, id_string): """( a string id into individual components""" try: self.packettype = 0x19 self.subtype = subtype self.id_combined = int(id_string[:6], 16) self.id1 = self.id_combined >> 16 self.id2 = self.id_combined >> 8 & 0xff self.id3 = self.id_combined & 0xff self.unitcode = int(id_string[7:]) self._set_strings() except ValueError as exc: raise ValueError("Invalid id_string") from exc if self.id_string != id_string: raise ValueError("Invalid id_string") def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.id3 = data[6] self.id_combined = (self.id1 << 16) + (self.id2 << 8) + self.id3 self.unitcode = data[7] self.cmnd = data[8] self.rssi_byte = data[9] self.rssi = self.rssi_byte >> 4 self._set_strings() def set_transmit(self, subtype, seqnbr, id_combined, unitcode, cmnd): """Load data from individual data fields""" self.packetlength = 0x09 self.packettype = 0x19 self.subtype = subtype self.seqnbr = seqnbr self.id_combined = id_combined self.id1 = id_combined >> 16 self.id2 = id_combined >> 8 & 0xff self.id3 = id_combined & 0xff self.unitcode = unitcode self.cmnd = cmnd self.rssi_byte = 0 self.rssi = self.rssi_byte >> 4 self.data = bytearray([self.packetlength, self.packettype, self.subtype, self.seqnbr, self.id1, self.id2, self.id3, self.unitcode, self.cmnd, self.rssi]) self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:06x}:{1}".format(self.id_combined, self.unitcode) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) if self.cmnd is not None: if self.cmnd in self.COMMANDS: self.cmnd_string = self.COMMANDS[self.cmnd] else: self.cmnd_string = self._UNKNOWN_CMND.format(self.cmnd) ############################################################################### # DDxxxx class ############################################################################### class DDxxxx(Packet): """ Data class for the DDXxxx packet type """ PACKET_TYPE = 0x31 """ Packet type for DDXxxx packets """ TYPES = {0x00: 'Brel/Dooya DDxxxx'} """ Mapping of numeric subtype values to strings, used in type_string """ CMD_UP = 0x00 CMD_DOWN = 0x01 CMD_STOP = 0x02 CMD_P2 = 0x03 CMD_PERCENT = 0x04 CMD_ANGLE = 0x05 CMD_PERCENT_ANGLE = 0x06 CMD_HOLD_UP = 0x07 CMD_HOLD_STOP = 0x08 CMD_HOLD_UP_DOWN = 0x09 CMD_HOLD_STOP_UP = 0x0A CMD_HOLD_STOP_DOWN = 0x0B COMMANDS = {CMD_STOP: 'Stop', CMD_UP: 'Up', CMD_DOWN: 'Down', CMD_P2: 'P2', CMD_PERCENT: 'Percent', CMD_ANGLE: 'Angle', CMD_PERCENT_ANGLE: 'Percent+Angle', CMD_HOLD_UP: 'Hold Up', CMD_HOLD_STOP: 'Hold Stop', CMD_HOLD_UP_DOWN: 'Hold Up+Down', CMD_HOLD_STOP_UP: 'Hold Stop+Up', CMD_HOLD_STOP_DOWN: 'Hold Stop+Down'} """ Mapping of command numeric values to strings, used for cmnd_string """ def __repr__(self): return self.__str__() def __str__(self): return ("DDxxxx [subtype={0}, seqnbr={1}, id={2}, cmnd={3}, " + "percent={4}], angle={5}, battery_level={6}, rssi={7}") \ .format( self.subtype, self.seqnbr, self.id_string, self.cmnd_string, self.percent, self.angle, self.battery_level, self.rssi ) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.id3 = None self.id4 = None self.id_combined = None self.unitcode = None self.cmnd = None self.cmnd_string = None self.percent = None self.angle = None self.battery_level = None def parse_id(self, subtype, id_string): """Parse a string id into individual components""" try: self.packettype = self.PACKET_TYPE self.subtype = subtype # Ensure id_string is long enough if len(id_string) < 8: raise ValueError("Invalid id_string length") # Extract full 4-byte (8 hex character) ID self.id_combined = int(id_string[:8], 16) # Extract individual bytes (big-endian order) self.id1 = (self.id_combined >> 24) & 0xFF self.id2 = (self.id_combined >> 16) & 0xFF self.id3 = (self.id_combined >> 8) & 0xFF self.id4 = self.id_combined & 0xFF # Extract unitcode from the remaining string self.unitcode = int(id_string[8:]) self._set_strings() except ValueError as exc: raise ValueError("Invalid id_string format") from exc if self.id_string != id_string: raise ValueError("Invalid id_string") def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] # Correctly extracting 4-byte ID self.id1 = data[4] self.id2 = data[5] self.id3 = data[6] self.id4 = data[7] self.id_combined = \ (self.id1 << 24) + \ (self.id2 << 16) + \ (self.id3 << 8) + \ self.id4 # Big-endian self.unitcode = data[8] self.cmnd = data[9] self.percent = data[10] self.angle = data[11] # Extract battery_level and RSSI from last byte (data[12]) self.battery_level = data[12] & 0x0F # Lower 4 bits self.rssi = data[12] >> 4 # Upper 4 bits self._set_strings() def set_transmit(self, subtype, seqnbr, id_combined, unitcode, cmnd, percent=0, angle=0, battery_level=0, rssi=0): """Load data and construct the bytearray for transmission""" self.packetlength = 0x0C self.packettype = self.PACKET_TYPE self.subtype = subtype self.seqnbr = seqnbr self.id_combined = id_combined # Extract bytes from id_combined (big-endian format) self.id1 = (id_combined >> 24) & 0xFF self.id2 = (id_combined >> 16) & 0xFF self.id3 = (id_combined >> 8) & 0xFF self.id4 = id_combined & 0xFF self.unitcode = unitcode self.cmnd = cmnd self.percent = percent self.angle = angle # Store battery level and RSSI in a single byte (4 bits each) self.battery_level = battery_level & 0x0F # Lower 4 bits self.rssi = (rssi & 0x0F) << 4 # Upper 4 bits battery_rssi_byte = self.rssi | self.battery_level # Into 1 byte # Construct the bytearray for transmission self.data = bytearray([ self.packetlength, self.packettype, self.subtype, self.seqnbr, self.id1, self.id2, self.id3, self.id4, # 4-byte ID self.unitcode, self.cmnd, self.percent, self.angle, battery_rssi_byte # Battery Level & RSSI packed into last byte ]) self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:06x}:{1}".format(self.id_combined, self.unitcode) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) if self.cmnd is not None: if self.cmnd in self.COMMANDS: self.cmnd_string = self.COMMANDS[self.cmnd] else: self.cmnd_string = self._UNKNOWN_CMND.format(self.cmnd) ############################################################################### # Funkbus class ############################################################################### class Funkbus(Packet): """ Data class for the Funkbus packet type """ __UNKNOWN_TIME = "Unknown time ({0:#02x})" __ALL = "All" __MASTER = "Master" __SCENE = "Scene {0}" TYPES = {0x00: 'Gira remote', 0x01: 'Insta remote'} """ Mapping of numeric subtype values to strings, used in type_string """ COMMANDS = {0x00: 'Down', 0x01: 'Up', 0x02: 'All Off', 0x03: 'All On', 0x04: 'Scene', 0x05: 'Down*', 0x06: 'Up*'} """ Mapping of command numeric values to strings, used for cmnd_string """ GROUPS = {0x41: 'A', 0x42: 'B', 0x43: 'C'} """ Mapping of group code numeric values to strings, used for group_string """ DURATION = {0x00: 'short', 0x01: '1 sec', 0x02: '1.25 sec', 0x03: '1.50 sec', 0x04: '1.75 sec', 0x05: '2.00 sec', 0x06: '2.25 sec', 0x07: '2.50 sec', 0x08: '2.75 sec', 0x09: '3.00 sec', 0x0A: '3.25 sec', 0x0B: '3.50 sec', 0x0C: '3.75 sec', 0x0D: '4.00 sec', 0x0E: '4.25 sec', 0x0F: '4.50 sec', 0x10: '4.75 sec', 0x11: '5.00 sec', 0x12: '5.25 sec', 0x13: '5.50 sec', 0x14: '5.75 sec', 0x15: '6.00 sec', 0x16: '6.25 sec', 0x17: '6.50 sec', 0x18: '6.75 sec', 0x19: '7.00 sec', 0x1A: '7.25 sec', 0x1B: '7.50 sec', 0x1C: '7.75 sec', 0x1D: '8.00 sec', 0x1E: '8.25 sec', 0x1F: '8.50 sec', 0x20: '8.75 sec', 0x21: '9.00 sec', 0x22: '9.25 sec', 0x23: '9.50 sec', 0x24: '9.75 sec', 0x25: '10.00 sec', 0x26: '10.25 sec', 0x27: '10.50 sec', 0x28: '10.75 sec', 0x29: '11.00 sec', 0x2A: '11.25 sec', 0x2B: '11.50 sec', 0x2C: '11.75 sec', 0x2D: '12.00 sec'} """ Mapping of keypress duration numeric values to strings """ def __repr__(self): return self.__str__() def __str__(self): return ("Funkbus [subtype={0}, seqnbr={1}, id={2}, group={3}, " + "target={4}, cmnd={5}, time={6}]")\ .format( self.subtype, self.seqnbr, self.id_string, self.group_string, self.target_string, self.cmnd_string, self.time_string ) def __init__(self): """Constructor""" super().__init__() self.id1 = None self.id2 = None self.id_combined = None self.groupcode = None self.group_string = None self.target = None self.target_string = None self.cmnd = None self.cmnd_string = None self.time = None self.time_string = None def parse_id(self, subtype, id_string): """Parse a string id into individual components""" try: self.packettype = 0x1e self.subtype = subtype self.id_combined = int(id_string[:4], 16) self.id1 = self.id_combined >> 8 & 0xff self.id2 = self.id_combined & 0xff self.groupcode = int(id_string[5:7], 16) self.target = int(id_string[7:9], 16) self._set_strings() except ValueError as exc: raise ValueError("Invalid id_string") from exc if self.id_string != id_string: raise ValueError("Invalid id_string") def load_receive(self, data): """Load data from a bytearray""" self.data = data self.packetlength = data[0] self.packettype = data[1] self.subtype = data[2] self.seqnbr = data[3] self.id1 = data[4] self.id2 = data[5] self.id_combined = (self.id1 << 8) + self.id2 self.groupcode = data[6] self.target = data[7] self.cmnd = data[8] self.time = data[9] self._set_strings() def set_transmit(self, subtype, seqnbr, id_combined, groupcode, target, cmnd, time): """Load data from individual data fields""" self.packetlength = 0x0B self.packettype = 0x1E self.subtype = subtype self.seqnbr = seqnbr self.id_combined = id_combined self.id1 = id_combined >> 8 & 0xff self.id2 = id_combined & 0xff self.groupcode = groupcode self.target = target self.cmnd = cmnd self.time = time self.data = bytearray([self.packetlength, self.packettype, self.subtype, self.seqnbr, self.id1, self.id2, self.groupcode, self.target, self.cmnd, self.time, 0x00, 0x09]) self._set_strings() def _set_strings(self): """Translate loaded numeric values into convenience strings""" self.id_string = "{0:04x}:{1:02x}{2:02x}" \ .format(self.id_combined, self.groupcode, self.target) if self.subtype in self.TYPES: self.type_string = self.TYPES[self.subtype] else: # Degrade nicely for yet unknown subtypes self.type_string = self._UNKNOWN_TYPE.format(self.packettype, self.subtype) if self.cmnd is not None: if self.cmnd in self.COMMANDS: self.cmnd_string = self.COMMANDS[self.cmnd] else: self.cmnd_string = self._UNKNOWN_CMND.format(self.cmnd) if self.groupcode is not None: if self.groupcode in self.GROUPS: self.group_string = self.GROUPS[self.groupcode] else: self.group_string = self.__UNKNOWN_GROUP.format(self.groupcode) if self.target is not None and self.cmnd in self.COMMANDS: self.target_string = \ '{0}'.format(self.target) if self.cmnd in [0x00, 0x01] \ else self.__ALL if self.cmnd in [0x02, 0x03] \ else self.__SCENE.format(self.target) if self.cmnd in [0x04] \ else self.__MASTER if self.time is not None: if self.time in self.DURATION: self.time_string = self.DURATION[self.time] else: self.time_string = self.__UNKNOWN_TIME.format(self.time) PACKET_TYPES = { 0x01: Status, 0x03: Undecoded, 0x10: Lighting1, 0x11: Lighting2, 0x12: Lighting3, 0x13: Lighting4, 0x14: Lighting5, 0x15: Lighting6, 0x16: Chime, 0x19: RollerTrol, 0x1A: Rfy, 0x1E: Funkbus, 0x20: Security1, 0x31: DDxxxx, 0x50: Temp, 0x4E: Bbq, 0x4F: TempRain, 0x51: Humid, 0x52: TempHumid, 0x53: Baro, 0x54: TempHumidBaro, 0x55: Rain, 0x56: Wind, 0x57: UV, 0x59: Energy1, 0x5A: Energy, 0x5B: Energy4, 0x5C: Energy5, 0x60: Cartelectronic, 0x71: RfxMeter, } def get_packet(packettype): """Return a packet based on the packet type.""" cls = PACKET_TYPES.get(packettype) if cls is None: return None return cls() def get_packet_with_id(packettype, subtype, id_string): """Return a packet based on the type and identifiers.""" pkt = get_packet(packettype) if pkt is None or not hasattr(pkt, "parse_id"): return None pkt.parse_id(subtype, id_string) return pkt def parse(data): """ Parse a packet from a bytearray """ if data[0] == 0 or len(data) < 2: # null length packet - sometimes happens on initialization return None expected_length = data[0] + 1 if len(data) != expected_length: return None pkt = get_packet(data[1]) if pkt is None: return None try: pkt.load_receive(data) except IndexError: # parsing failed due to invalid packet length return None return pkt pyRFXtrx-0.32.0/doctest/000077500000000000000000000000001500543535500150145ustar00rootroot00000000000000pyRFXtrx-0.32.0/doctest/test_lighting.txt000066400000000000000000000132371500543535500204270ustar00rootroot00000000000000Lighting tests ============== >>> import logging >>> import sys >>> logging.root.handlers = [] >>> logging.basicConfig(level=logging.DEBUG, format="RFXTRX: %(message)s", handlers=[logging.StreamHandler(sys.stdout)]) Lighting1 --------- >>> from RFXtrx import DummyTransport, get_device >>> x = get_device(0x10, 0x00, 'E13') >>> print(x) type='X10 lighting' id='E13' >>> transport = DummyTransport() >>> x = transport.receive([0x07, 0x10, 0x00, 0x2a, 0x45, 0x05, 0x01, 0x70]) RFXTRX: Recv: 0x07 0x10 0x00 0x2a 0x45 0x05 0x01 0x70 >>> print(x) device=[ type='X10 lighting' id='E5'] values=[('Command', 'On'), ('Rssi numeric', 7)] >>> x.device.send_on(transport) RFXTRX: Send: 0x07 0x10 0x00 0x00 0x45 0x05 0x01 0x00 >>> x.device.send_off(transport) RFXTRX: Send: 0x07 0x10 0x00 0x00 0x45 0x05 0x00 0x00 Lighting2 --------- >>> from RFXtrx import DummyTransport, get_device >>> x = get_device(0x11, 0x00, '1234567:5') >>> print(x) type='AC' id='1234567:5' >>> transport = DummyTransport() >>> x = transport.receive([0x0b, 0x11, 0x00, 0x2a, 0x01, 0x23, 0x45, 0x67, 0x05, 0x02, 0x07, 0x70]) RFXTRX: Recv: 0x0b 0x11 0x00 0x2a 0x01 0x23 0x45 0x67 0x05 0x02 0x07 0x70 >>> print(x) device=[ type='AC' id='1234567:5'] values=[('Command', 'Set level'), ('Dim level', 50), ('Rssi numeric', 7)] >>> x.device.send_on(transport) RFXTRX: Send: 0x0b 0x11 0x00 0x00 0x01 0x23 0x45 0x67 0x05 0x01 0x00 0x00 >>> x.device.send_off(transport) RFXTRX: Send: 0x0b 0x11 0x00 0x00 0x01 0x23 0x45 0x67 0x05 0x00 0x00 0x00 >>> x.device.send_dim(transport, 0) RFXTRX: Send: 0x0b 0x11 0x00 0x00 0x01 0x23 0x45 0x67 0x05 0x00 0x00 0x00 >>> x.device.send_dim(transport, 1) RFXTRX: Send: 0x0b 0x11 0x00 0x00 0x01 0x23 0x45 0x67 0x05 0x02 0x00 0x00 >>> x.device.send_dim(transport, 50) RFXTRX: Send: 0x0b 0x11 0x00 0x00 0x01 0x23 0x45 0x67 0x05 0x02 0x07 0x00 >>> x.device.send_dim(transport, 99) RFXTRX: Send: 0x0b 0x11 0x00 0x00 0x01 0x23 0x45 0x67 0x05 0x02 0x0f 0x00 >>> x.device.send_dim(transport, 100) RFXTRX: Send: 0x0b 0x11 0x00 0x00 0x01 0x23 0x45 0x67 0x05 0x02 0x0f 0x00 Lighting3 --------- >>> from RFXtrx import DummyTransport, get_device >>> x = get_device(0x12, 0x00, '1:234') >>> print(x) type='Ikea Koppla' id='1:234' >>> transport = DummyTransport() >>> x = transport.receive([0x08, 0x12, 0x00, 0x2a, 0x01, 0x34, 0x02, 0x15, 0x79]) RFXTRX: Recv: 0x08 0x12 0x00 0x2a 0x01 0x34 0x02 0x15 0x79 >>> print(x) device=[ type='Ikea Koppla' id='1:234'] values=[('Command', 'Level 5'), ('Rssi numeric', 7)] >>> x.device.send_on(transport) RFXTRX: Send: 0x08 0x12 0x00 0x00 0x01 0x34 0x02 0x10 0x00 >>> x.device.send_off(transport) RFXTRX: Send: 0x08 0x12 0x00 0x00 0x01 0x34 0x02 0x1a 0x00 Lighting5 --------- >>> from RFXtrx import DummyTransport, get_device >>> x = get_device(0x14, 0x00, '123456:7') >>> print(x) type='LightwaveRF, Siemens' id='123456:7' >>> transport = DummyTransport() >>> x = transport.receive([0x0a, 0x14, 0x00, 0x2a, 0x12, 0x34, 0x56, 0x07, 0x10, 0x0f, 0x70]) RFXTRX: Recv: 0x0a 0x14 0x00 0x2a 0x12 0x34 0x56 0x07 0x10 0x0f 0x70 >>> print(x) device=[ type='LightwaveRF, Siemens' id='123456:7'] values=[('Command', 'Set level'), ('Dim level', 50), ('Rssi numeric', 7)] >>> x.device.send_on(transport) RFXTRX: Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x01 0x00 0x00 >>> x.device.send_off(transport) RFXTRX: Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x00 0x00 0x00 >>> x.device.send_open(transport) RFXTRX: Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x0f 0x00 0x00 >>> x.device.send_close(transport) RFXTRX: Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x0d 0x00 0x00 >>> x.device.send_stop(transport) RFXTRX: Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x0e 0x00 0x00 >>> x.device.send_dim(transport, 0) RFXTRX: Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x00 0x00 0x00 >>> x.device.send_dim(transport, 1) RFXTRX: Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x10 0x00 0x00 >>> x.device.send_dim(transport, 50) RFXTRX: Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x10 0x0f 0x00 >>> x.device.send_dim(transport, 99) RFXTRX: Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x10 0x1f 0x00 >>> x.device.send_dim(transport, 100) RFXTRX: Send: 0x0a 0x14 0x00 0x00 0x12 0x34 0x56 0x07 0x10 0x1f 0x00 Lighting6 --------- >>> from RFXtrx import DummyTransport, get_device >>> x = get_device(0x15, 0x00, '1234:A5') >>> print(x) type='Blyss' id='1234:A5' >>> transport = DummyTransport() >>> x = transport.receive([0x0b, 0x15, 0x00, 0x2a, 0x12, 0x34, 0x41, 0x05, 0x03, 0x01, 0x00, 0x70]) RFXTRX: Recv: 0x0b 0x15 0x00 0x2a 0x12 0x34 0x41 0x05 0x03 0x01 0x00 0x70 >>> print(x) device=[ type='Blyss' id='1234:A5'] values=[('Command', 'Group off'), ('Rssi numeric', 7)] >>> x.device.send_on(transport) RFXTRX: Send: 0x0b 0x15 0x00 0x00 0x12 0x34 0x41 0x05 0x00 0x00 0x00 0x00 >>> x.device.send_off(transport) RFXTRX: Send: 0x0b 0x15 0x00 0x00 0x12 0x34 0x41 0x05 0x01 0x01 0x00 0x00 >>> x.device.send_on(transport) RFXTRX: Send: 0x0b 0x15 0x00 0x00 0x12 0x34 0x41 0x05 0x00 0x02 0x00 0x00 >>> x.device.send_off(transport) RFXTRX: Send: 0x0b 0x15 0x00 0x00 0x12 0x34 0x41 0x05 0x01 0x03 0x00 0x00 >>> x.device.send_on(transport) RFXTRX: Send: 0x0b 0x15 0x00 0x00 0x12 0x34 0x41 0x05 0x00 0x04 0x00 0x00 >>> x.device.send_off(transport) RFXTRX: Send: 0x0b 0x15 0x00 0x00 0x12 0x34 0x41 0x05 0x01 0x00 0x00 0x00 pyRFXtrx-0.32.0/doctest/test_lowlevel.txt000066400000000000000000000552741500543535500204620ustar00rootroot00000000000000Doctests for the lowlevel module ================================ This file is part of pyRFXtrx, a Python library to communicate with the RFXtrx family of devices from http://www.rfxcom.com/ See https://github.com/woudt/pyRFXtrx for the latest version. Copyright (C) 2012 Edwin Woudt pyRFXtrx is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. pyRFXtrx is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with pyRFXtrx. See the file COPYING.txt in the distribution. If not, see . Status ------ >>> from RFXtrx import lowlevel >>> >>> x = lowlevel.Status() >>> print(x) Status [subtype=None, firmware=None, output_power=None, devices=None] >>> x.load_receive(bytearray([0x0d, 0x01, 0x00, 0x01, 0x02, 0x53, 0x3e, 0x00, 0x0c, 0x2f, 0x01, 0x01, 0x00, 0x00])) >>> print(x) Status [subtype=433.92MHz, firmware=62, output_power=0, devices=['ac', 'arc', 'hideki', 'homeeasy', 'keeloq', 'lacrosse', 'oregon', 'x10']] >>> >>> print(list(x.data)) [13, 1, 0, 1, 2, 83, 62, 0, 12, 47, 1, 1, 0, 0] >>> print(x.packetlength) 13 >>> print(x.packettype) 1 >>> print(x.tranceiver_type) 83 >>> print(x.firmware_version) 62 >>> print(x.output_power) 0 >>> print(x.type_string) 433.92MHz >>> print(x.devices) ['ac', 'arc', 'hideki', 'homeeasy', 'keeloq', 'lacrosse', 'oregon', 'x10'] Lighting1 --------- >>> from RFXtrx import lowlevel >>> >>> x = lowlevel.Lighting1() >>> print(x) Lighting1 [subtype=None, seqnbr=None, id=None, cmnd=None, rssi=None] >>> x.load_receive(bytearray([0x07, 0x10, 0x00, 0x2a, 0x45, 0x05, 0x01, 0x70])) >>> print(x) Lighting1 [subtype=X10 lighting, seqnbr=42, id=E5, cmnd=On, rssi=7] >>> >>> print(list(x.data)) [7, 16, 0, 42, 69, 5, 1, 112] >>> print(x.packetlength) 7 >>> print(x.packettype) 16 >>> print(x.subtype) 0 >>> print(x.type_string) X10 lighting >>> print(x.seqnbr) 42 >>> print(x.housecode) 69 >>> print(x.unitcode) 5 >>> print(x.id_string) E5 >>> print(x.cmnd) 1 >>> print(x.cmnd_string) On >>> print(x.rssi_byte) 112 >>> print(x.rssi) 7 >>> >>> x = lowlevel.Lighting1() >>> x.set_transmit(0x00, 0x2a, 0x45, 0x05, 0x01) >>> print(x) Lighting1 [subtype=X10 lighting, seqnbr=42, id=E5, cmnd=On, rssi=0] >>> >>> print(list(x.data)) [7, 16, 0, 42, 69, 5, 1, 0] >>> print(x.packetlength) 7 >>> print(x.packettype) 16 >>> print(x.subtype) 0 >>> print(x.type_string) X10 lighting >>> print(x.seqnbr) 42 >>> print(x.housecode) 69 >>> print(x.unitcode) 5 >>> print(x.id_string) E5 >>> print(x.cmnd) 1 >>> print(x.cmnd_string) On >>> print(x.rssi_byte) 0 >>> print(x.rssi) 0 >>> >>> x = lowlevel.Lighting1() >>> x.parse_id(0, "E13") >>> print(x) Lighting1 [subtype=X10 lighting, seqnbr=None, id=E13, cmnd=None, rssi=None] >>> print(x.housecode) 69 >>> print(x.unitcode) 13 >>> x.parse_id(0, "Q1") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string >>> x.parse_id(0, "AA") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string Lighting2 --------- >>> from RFXtrx import lowlevel >>> >>> x = lowlevel.Lighting2() >>> print(x) Lighting2 [subtype=None, seqnbr=None, id=None, cmnd=None, level=None, rssi=None] >>> x.load_receive(bytearray([0x0b, 0x11, 0x00, 0x2a, 0x01, 0x23, 0x45, 0x67, 0x05, 0x02, 0x08, 0x70])) >>> print(x) Lighting2 [subtype=AC, seqnbr=42, id=1234567:5, cmnd=Set level, level=8, rssi=7] >>> >>> print(list(x.data)) [11, 17, 0, 42, 1, 35, 69, 103, 5, 2, 8, 112] >>> print(x.packetlength) 11 >>> print(x.packettype) 17 >>> print(x.subtype) 0 >>> print(x.type_string) AC >>> print(x.seqnbr) 42 >>> print(x.id1) 1 >>> print(x.id2) 35 >>> print(x.id3) 69 >>> print(x.id4) 103 >>> print(x.id_combined) 19088743 >>> print(x.unitcode) 5 >>> print(x.id_string) 1234567:5 >>> print(x.cmnd) 2 >>> print(x.cmnd_string) Set level >>> print(x.level) 8 >>> print(x.rssi_byte) 112 >>> print(x.rssi) 7 >>> >>> x = lowlevel.Lighting2() >>> x.set_transmit(0x00, 0x2a, 0x1234567, 0x05, 0x02, 0x08) >>> print(x) Lighting2 [subtype=AC, seqnbr=42, id=1234567:5, cmnd=Set level, level=8, rssi=0] >>> >>> print(list(x.data)) [11, 17, 0, 42, 1, 35, 69, 103, 5, 2, 8, 0] >>> print(x.packetlength) 11 >>> print(x.packettype) 17 >>> print(x.subtype) 0 >>> print(x.type_string) AC >>> print(x.seqnbr) 42 >>> print(x.id1) 1 >>> print(x.id2) 35 >>> print(x.id3) 69 >>> print(x.id4) 103 >>> print(x.id_combined) 19088743 >>> print(x.unitcode) 5 >>> print(x.id_string) 1234567:5 >>> print(x.cmnd) 2 >>> print(x.cmnd_string) Set level >>> print(x.level) 8 >>> print(x.rssi_byte) 0 >>> print(x.rssi) 0 >>> >>> x = lowlevel.Lighting2() >>> x.parse_id(0, "1234567:5") >>> print(x) Lighting2 [subtype=AC, seqnbr=None, id=1234567:5, cmnd=None, level=None, rssi=None] >>> print(x.id1) 1 >>> print(x.id2) 35 >>> print(x.id3) 69 >>> print(x.id4) 103 >>> print(x.id_combined) 19088743 >>> print(x.unitcode) 5 >>> x.parse_id(0, "12345678:5") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string >>> x.parse_id(0, "123456:54") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string >>> x.parse_id(0, "123456785") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string Lighting3 --------- >>> from RFXtrx import lowlevel >>> >>> x = lowlevel.Lighting3() >>> print(x) Lighting3 [subtype=None, seqnbr=None, id=None, cmnd=None, battery=None, rssi=None] >>> x.load_receive(bytearray([0x08, 0x12, 0x00, 0x2a, 0x01, 0x34, 0x02, 0x15, 0x79])) >>> print(x) Lighting3 [subtype=Ikea Koppla, seqnbr=42, id=1:234, cmnd=Level 5, battery=9, rssi=7] >>> >>> print(list(x.data)) [8, 18, 0, 42, 1, 52, 2, 21, 121] >>> print(x.packetlength) 8 >>> print(x.packettype) 18 >>> print(x.subtype) 0 >>> print(x.type_string) Ikea Koppla >>> print(x.seqnbr) 42 >>> print(x.system) 1 >>> print(x.channel1) 52 >>> print(x.channel2) 2 >>> print(x.channel) 564 >>> print(x.id_string) 1:234 >>> print(x.cmnd) 21 >>> print(x.cmnd_string) Level 5 >>> print(x.rssi_byte) 121 >>> print(x.rssi) 7 >>> print(x.battery) 9 >>> >>> x = lowlevel.Lighting3() >>> x.set_transmit(0x00, 0x2a, 0x1, 0x234, 0x15) >>> print(x) Lighting3 [subtype=Ikea Koppla, seqnbr=42, id=1:234, cmnd=Level 5, battery=0, rssi=0] >>> >>> print(list(x.data)) [8, 18, 0, 42, 1, 52, 2, 21, 0] >>> print(x.packetlength) 8 >>> print(x.packettype) 18 >>> print(x.subtype) 0 >>> print(x.type_string) Ikea Koppla >>> print(x.seqnbr) 42 >>> print(x.system) 1 >>> print(x.channel1) 52 >>> print(x.channel2) 2 >>> print(x.channel) 564 >>> print(x.id_string) 1:234 >>> print(x.cmnd) 21 >>> print(x.cmnd_string) Level 5 >>> print(x.rssi_byte) 0 >>> print(x.rssi) 0 >>> print(x.battery) 0 >>> x = lowlevel.Lighting3() >>> x.parse_id(0, "1:234") >>> print(x) Lighting3 [subtype=Ikea Koppla, seqnbr=None, id=1:234, cmnd=None, battery=None, rssi=None] >>> print(x.system) 1 >>> print(x.channel1) 52 >>> print(x.channel2) 2 >>> print(x.channel) 564 >>> x.parse_id(0, "G:234") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string >>> x.parse_id(0, "10234") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string >>> x.parse_id(0, "1:23X") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string Lighting4 --------- >>> from RFXtrx import lowlevel >>> >>> x = lowlevel.Lighting4() >>> print(x) Lighting4 [subtype=None, seqnbr=None, cmd=None, pulse=None, rssi=None] >>> x.load_receive(bytearray([0x09, 0x13, 0x00, 0x2a, 0x12, 0x34, 0x56, 0x01, 0x5e, 0x70])) >>> print(x) Lighting4 [subtype=PT2262, seqnbr=42, cmd=123456, pulse=350, rssi=7] >>> >>> print(list(x.data)) [9, 19, 0, 42, 18, 52, 86, 1, 94, 112] >>> >>> print(x.packetlength) 9 >>> print(x.packettype) 19 >>> print(x.subtype) 0 >>> print(x.type_string) PT2262 >>> print(x.seqnbr) 42 >>> print(x.cmd1) 18 >>> print(x.cmd2) 52 >>> print(x.cmd3) 86 >>> print(x.cmd) 1193046 >>> print(x.id_string) 123456 >>> print(x.pulsehigh) 1 >>> print(x.pulselow) 94 >>> print(x.pulse) 350 >>> print(x.rssi_byte) 112 >>> print(x.rssi) 7 >>> >>> x = lowlevel.Lighting4() >>> x.set_transmit(0x00, 0x2a, 0x123456, 0x15e) >>> print(x) Lighting4 [subtype=PT2262, seqnbr=42, cmd=123456, pulse=350, rssi=0] >>> >>> print(list(x.data)) [9, 19, 0, 42, 18, 52, 86, 1, 94, 0] >>> >>> print(x.packetlength) 9 >>> print(x.packettype) 19 >>> print(x.subtype) 0 >>> print(x.type_string) PT2262 >>> print(x.seqnbr) 42 >>> print(x.cmd1) 18 >>> print(x.cmd2) 52 >>> print(x.cmd3) 86 >>> print(x.cmd) 1193046 >>> print(x.id_string) 123456 >>> print(x.pulsehigh) 1 >>> print(x.pulselow) 94 >>> print(x.pulse) 350 >>> print(x.rssi_byte) 0 >>> print(x.rssi) 0 >>> x = lowlevel.Lighting4() >>> x.parse_id(0, "123456") >>> print(x) Lighting4 [subtype=PT2262, seqnbr=None, cmd=123456, pulse=None, rssi=None] >>> print(x.cmd1) 18 >>> print(x.cmd2) 52 >>> print(x.cmd3) 86 >>> print(x.cmd) 1193046 >>> x.parse_id(0, "12345X") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string Lighting5 --------- >>> from RFXtrx import lowlevel >>> >>> x = lowlevel.Lighting5() >>> print(x) Lighting5 [subtype=None, seqnbr=None, id=None, cmnd=None, level=None, rssi=None] >>> x.load_receive(bytearray([0x0a, 0x14, 0x00, 0x2a, 0x12, 0x34, 0x56, 0x07, 0x10, 0x11, 0x70])) >>> print(x) Lighting5 [subtype=LightwaveRF, Siemens, seqnbr=42, id=123456:7, cmnd=Set level, level=17, rssi=7] >>> >>> print(list(x.data)) [10, 20, 0, 42, 18, 52, 86, 7, 16, 17, 112] >>> print(x.packetlength) 10 >>> print(x.packettype) 20 >>> print(x.subtype) 0 >>> print(x.type_string) LightwaveRF, Siemens >>> print(x.seqnbr) 42 >>> print(x.id1) 18 >>> print(x.id2) 52 >>> print(x.id3) 86 >>> print(x.id_combined) 1193046 >>> print(x.unitcode) 7 >>> print(x.id_string) 123456:7 >>> print(x.cmnd) 16 >>> print(x.cmnd_string) Set level >>> print(x.level) 17 >>> print(x.rssi_byte) 112 >>> print(x.rssi) 7 >>> >>> x = lowlevel.Lighting5() >>> x.set_transmit(0x00, 0x2a, 0x123456, 0x07, 0x10, 0x11) >>> print(x) Lighting5 [subtype=LightwaveRF, Siemens, seqnbr=42, id=123456:7, cmnd=Set level, level=17, rssi=0] >>> >>> print(list(x.data)) [10, 20, 0, 42, 18, 52, 86, 7, 16, 17, 0] >>> print(x.packetlength) 10 >>> print(x.packettype) 20 >>> print(x.subtype) 0 >>> print(x.type_string) LightwaveRF, Siemens >>> print(x.seqnbr) 42 >>> print(x.id1) 18 >>> print(x.id2) 52 >>> print(x.id3) 86 >>> print(x.id_combined) 1193046 >>> print(x.unitcode) 7 >>> print(x.id_string) 123456:7 >>> print(x.cmnd) 16 >>> print(x.cmnd_string) Set level >>> print(x.level) 17 >>> print(x.rssi_byte) 0 >>> print(x.rssi) 0 >>> x = lowlevel.Lighting5() >>> x.parse_id(0, "123456:7") >>> print(x) Lighting5 [subtype=LightwaveRF, Siemens, seqnbr=None, id=123456:7, cmnd=None, level=None, rssi=None] >>> print(x.id1) 18 >>> print(x.id2) 52 >>> print(x.id3) 86 >>> print(x.id_combined) 1193046 >>> print(x.unitcode) 7 >>> x.parse_id(0, "123456:X") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string >>> x.parse_id(0, "12345X:7") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string >>> x.parse_id(0, "12345677") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string >>> x.parse_id(0, "1234567:8") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string >>> x.parse_id(0, "12345:8") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string Lighting6 --------- >>> from RFXtrx import lowlevel >>> >>> x = lowlevel.Lighting6() >>> print(x) Lighting6 [subtype=None, seqnbr=None, id=None, cmnd=None, cmndseqnbr=None, rssi=None] >>> x.load_receive(bytearray([0x0b, 0x15, 0x00, 0x2a, 0x12, 0x34, 0x41, 0x05, 0x03, 0x01, 0x00, 0x70])) >>> print(x) Lighting6 [subtype=Blyss, seqnbr=42, id=1234:A5, cmnd=Group off, cmndseqnbr=1, rssi=7] >>> >>> print(list(x.data)) [11, 21, 0, 42, 18, 52, 65, 5, 3, 1, 0, 112] >>> >>> print(x.packetlength) 11 >>> print(x.packettype) 21 >>> print(x.subtype) 0 >>> print(x.type_string) Blyss >>> print(x.seqnbr) 42 >>> print(x.id1) 18 >>> print(x.id2) 52 >>> print(x.id_combined) 4660 >>> print(x.groupcode) 65 >>> print(x.unitcode) 5 >>> print(x.id_string) 1234:A5 >>> print(x.cmnd) 3 >>> print(x.cmnd_string) Group off >>> print(x.cmndseqnbr) 1 >>> print(x.rfu) 0 >>> print(x.rssi_byte) 112 >>> print(x.rssi) 7 >>> >>> x = lowlevel.Lighting6() >>> x.set_transmit(0x00, 0x2a, 0x1234, 0x41, 0x05, 0x03, 0x01) >>> print(x) Lighting6 [subtype=Blyss, seqnbr=42, id=1234:A5, cmnd=Group off, cmndseqnbr=1, rssi=0] >>> >>> print(list(x.data)) [11, 21, 0, 42, 18, 52, 65, 5, 3, 1, 0, 0] >>> >>> print(x.packetlength) 11 >>> print(x.packettype) 21 >>> print(x.subtype) 0 >>> print(x.type_string) Blyss >>> print(x.seqnbr) 42 >>> print(x.id1) 18 >>> print(x.id2) 52 >>> print(x.id_combined) 4660 >>> print(x.groupcode) 65 >>> print(x.unitcode) 5 >>> print(x.id_string) 1234:A5 >>> print(x.cmnd) 3 >>> print(x.cmnd_string) Group off >>> print(x.cmndseqnbr) 1 >>> print(x.rfu) 0 >>> print(x.rssi_byte) 0 >>> print(x.rssi) 0 >>> x = lowlevel.Lighting6() >>> x.parse_id(0, "1234:A5") >>> print(x) Lighting6 [subtype=Blyss, seqnbr=None, id=1234:A5, cmnd=None, cmndseqnbr=None, rssi=None] >>> print(x.id1) 18 >>> print(x.id2) 52 >>> print(x.id_combined) 4660 >>> print(x.groupcode) 65 >>> print(x.unitcode) 5 >>> x.parse_id(0, "1234:AA") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string >>> x.parse_id(0, "123X:A5") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string >>> x.parse_id(0, "12345A5") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string >>> x.parse_id(0, "12345:A5") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string >>> x.parse_id(0, "123:A5") Traceback (most recent call last): File "", line 1, in File "RFXtrx/lowlevel.py", line 280, in parse_id raise ValueError("Invalid id_string") ValueError: Invalid id_string Curtain1 -------- Blinds1 ------- Security1 --------- Camera1 ------- Remote1 ------- Thermostat1 ----------- Thermostat2 ----------- Thermostat3 ----------- Temp ---- >>> from RFXtrx import lowlevel >>> >>> x = lowlevel.Temp() >>> print(x) Temp [subtype=None, seqnbr=None, id=None, temp=None, battery=None, rssi=None] >>> x.load_receive(bytearray([0x08, 0x50, 0x02, 0x2a, 0x96, 0x03, 0x81, 0x41, 0x79])) >>> print(x) Temp [subtype=THC238/268,THN132,THWR288,THRN122,THN122,AW129/131, seqnbr=42, id=96:03, temp=-32.1, battery=9, rssi=7] >>> >>> print(list(x.data)) [8, 80, 2, 42, 150, 3, 129, 65, 121] >>> print(x.packetlength) 8 >>> print(x.packettype) 80 >>> print(x.subtype) 2 >>> print(x.type_string) THC238/268,THN132,THWR288,THRN122,THN122,AW129/131 >>> print(x.seqnbr) 42 >>> print(x.id1) 150 >>> print(x.id2) 3 >>> print(x.id_string) 96:03 >>> print(x.temphigh) 129 >>> print(x.templow) 65 >>> print(x.temp) -32.1 >>> print(x.rssi_byte) 121 >>> print(x.rssi) 7 >>> print(x.battery) 9 Humid ----- >>> from RFXtrx import lowlevel >>> >>> x = lowlevel.Humid() >>> print(x) Humid [subtype=None, seqnbr=None, id=None, humidity=None, humidity_status=None, battery=None, rssi=None] >>> x.load_receive(bytearray([0x08, 0x51, 0x01, 0x2a, 0x96, 0x03, 0x60, 0x03, 0x79])) >>> print(x) Humid [subtype=LaCrosse TX3, seqnbr=42, id=96:03, humidity=96, humidity_status=3, battery=9, rssi=7] >>> >>> print(list(x.data)) [8, 81, 1, 42, 150, 3, 96, 3, 121] >>> print(x.packetlength) 8 >>> print(x.packettype) 81 >>> print(x.subtype) 1 >>> print(x.type_string) LaCrosse TX3 >>> print(x.seqnbr) 42 >>> print(x.id1) 150 >>> print(x.id2) 3 >>> print(x.id_string) 96:03 >>> print(x.humidity) 96 >>> print(x.humidity_status) 3 >>> print(x.rssi_byte) 121 >>> print(x.rssi) 7 >>> print(x.battery) 9 TempHumid --------- >>> from RFXtrx import lowlevel >>> >>> x = lowlevel.TempHumid() >>> print(x) TempHumid [subtype=None, seqnbr=None, id=None, temp=None, humidity=None, humidity_status=None, battery=None, rssi=None] >>> x.load_receive(bytearray([0x0a, 0x52, 0x01, 0x2a, 0x96, 0x03, 0x81, 0x41, 0x60, 0x03, 0x79])) >>> print(x) TempHumid [subtype=THGN122/123, THGN132, THGR122/228/238/268, seqnbr=42, id=96:03, temp=-32.1, humidity=96, humidity_status=3, battery=9, rssi=7] >>> >>> print(list(x.data)) [10, 82, 1, 42, 150, 3, 129, 65, 96, 3, 121] >>> print(x.packetlength) 10 >>> print(x.packettype) 82 >>> print(x.subtype) 1 >>> print(x.type_string) THGN122/123, THGN132, THGR122/228/238/268 >>> print(x.seqnbr) 42 >>> print(x.id1) 150 >>> print(x.id2) 3 >>> print(x.id_string) 96:03 >>> print(x.temphigh) 129 >>> print(x.templow) 65 >>> print(x.temp) -32.1 >>> print(x.humidity) 96 >>> print(x.humidity_status) 3 >>> print(x.rssi_byte) 121 >>> print(x.rssi) 7 >>> print(x.battery) 9 Baro ---- >>> from RFXtrx import lowlevel >>> >>> x = lowlevel.Baro() >>> print(x) Baro [subtype=None, seqnbr=None, id=None, baro=None, forecast=None, battery=None, rssi=None] >>> x.load_receive(bytearray([0x09, 0x53, 0x01, 0x2a, 0x96, 0x03, 0x04, 0x06, 0x00, 0x79])) >>> print(x) Baro [subtype=Unknown type (0x53/0x01), seqnbr=42, id=96:03, baro=1030, forecast=0, battery=9, rssi=7] >>> >>> print(list(x.data)) [9, 83, 1, 42, 150, 3, 4, 6, 0, 121] >>> print(x.packetlength) 9 >>> print(x.packettype) 83 >>> print(x.subtype) 1 >>> print(x.type_string) Unknown type (0x53/0x01) >>> print(x.seqnbr) 42 >>> print(x.id1) 150 >>> print(x.id2) 3 >>> print(x.id_string) 96:03 >>> print(x.baro1) 4 >>> print(x.baro2) 6 >>> print(x.baro) 1030 >>> print(x.forecast) 0 >>> print(x.rssi_byte) 121 >>> print(x.rssi) 7 >>> print(x.battery) 9 TempHumidBaro ------------- >>> from RFXtrx import lowlevel >>> >>> x = lowlevel.TempHumidBaro() >>> print(x) TempHumidBaro [subtype=None, seqnbr=None, id=None, temp=None, humidity=None, humidity_status=None, baro=None, forecast=None, battery=None, rssi=None] >>> x.load_receive(bytearray([0x0d, 0x54, 0x01, 0x2a, 0x96, 0x03, 0x81, 0x41, 0x60, 0x03, 0x04, 0x06, 0x00, 0x79])) >>> print(x) TempHumidBaro [subtype=BTHR918, seqnbr=42, id=96:03, temp=-32.1, humidity=96, humidity_status=3, baro=1030, forecast=0, battery=9, rssi=7] >>> >>> print(list(x.data)) [13, 84, 1, 42, 150, 3, 129, 65, 96, 3, 4, 6, 0, 121] >>> print(x.packetlength) 13 >>> print(x.packettype) 84 >>> print(x.subtype) 1 >>> print(x.type_string) BTHR918 >>> print(x.seqnbr) 42 >>> print(x.id1) 150 >>> print(x.id2) 3 >>> print(x.id_string) 96:03 >>> print(x.temphigh) 129 >>> print(x.templow) 65 >>> print(x.temp) -32.1 >>> print(x.humidity) 96 >>> print(x.humidity_status) 3 >>> print(x.baro1) 4 >>> print(x.baro2) 6 >>> print(x.baro) 1030 >>> print(x.forecast) 0 >>> print(x.rssi_byte) 121 >>> print(x.rssi) 7 >>> print(x.battery) 9 Rain ---- >>> from RFXtrx import lowlevel >>> >>> x = lowlevel.Rain() >>> print(x) Rain [subtype=None, seqnbr=None, id=None, rainrate=None, raintotal=None, battery=None, rssi=None] >>> x.load_receive(bytearray([0x0b, 0x55, 0x02, 0x03, 0x12, 0x34, 0x02, 0x50, 0x01, 0x23, 0x45, 0x57])) >>> print(x) Rain [subtype=PCR800, seqnbr=3, id=12:34, rainrate=5.92, raintotal=7456.5, battery=7, rssi=5] >>> >>> print(list(x.data)) [11, 85, 2, 3, 18, 52, 2, 80, 1, 35, 69, 87] >>> print(x.packetlength) 11 >>> print(x.packettype) 85 >>> print(x.subtype) 2 >>> print(x.type_string) PCR800 >>> print(x.seqnbr) 3 >>> print(x.id1) 18 >>> print(x.id2) 52 >>> print(x.id_string) 12:34 >>> print(x.rainrate1) 2 >>> print(x.rainrate2) 80 >>> print(x.rainrate) 5.92 >>> print(x.raintotal1) 1 >>> print(x.raintotal2) 35 >>> print(x.raintotal3) 69 >>> print(x.raintotal) 7456.5 >>> print(x.rssi_byte) 87 >>> print(x.rssi) 5 >>> print(x.battery) 7 Wind ---- >>> from RFXtrx import lowlevel >>> >>> x = lowlevel.Wind() >>> print(x) Wind [subtype=None, seqnbr=None, id=None, direction=None, average_speed=None, gust=None, temperature=None, chill=None, battery=None, rssi=None] >>> x.load_receive(bytearray([0x10, 0x56, 0x01, 0x03, 0x2F, 0x00, 0x00, 0xF7, 0x00, 0x20, 0x00, 0x24, 0x81, 0x60, 0x82, 0x50, 0x59])) >>> print(x) Wind [subtype=WTGR800, seqnbr=3, id=2f:00, direction=247, average_speed=3.2, gust=3.6, temperature=None, chill=None, battery=9, rssi=5] >>> >>> print(list(x.data)) [16, 86, 1, 3, 47, 0, 0, 247, 0, 32, 0, 36, 129, 96, 130, 80, 89] >>> print(x.packetlength) 16 >>> print(x.packettype) 86 >>> print(x.subtype) 1 >>> print(x.type_string) WTGR800 >>> print(x.seqnbr) 3 >>> print(x.id1) 47 >>> print(x.id2) 0 >>> print(x.id_string) 2f:00 >>> print(x.direction) 247 >>> print(x.average_speed) 3.2 >>> print(x.gust) 3.6 >>> print(x.temperature) None >>> print(x.chill) None >>> print(x.rssi_byte) 89 >>> print(x.rssi) 5 >>> print(x.battery) 9 Security1 --------- UV -- DateTime -------- Current ------- Energy ------ Weight ------ RFXSensor --------- RFXMeter -------- FS20 ---- pyRFXtrx-0.32.0/examples/000077500000000000000000000000001500543535500151655ustar00rootroot00000000000000pyRFXtrx-0.32.0/examples/receive.py000066400000000000000000000032211500543535500171570ustar00rootroot00000000000000# This file is part of pyRFXtrx, a Python library to communicate with # the RFXtrx family of devices from http://www.rfxcom.com/ # See https://github.com/woudt/pyRFXtrx for the latest version. # # Copyright (C) 2012 Edwin Woudt # # pyRFXtrx is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # pyRFXtrx is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with pyRFXtrx. See the file COPYING.txt in the distribution. # If not, see . import sys import logging sys.path.append("../") import RFXtrx import time def print_callback(event): print(event) def main(): logging.basicConfig(level=logging.DEBUG) if len(sys.argv) >= 2: rfxcom_device = sys.argv[1] else: rfxcom_device = '/dev/serial/by-id/usb-RFXCOM_RFXtrx433_A1Y0NJGR-if00-port0' modes_list = sys.argv[2].split() if len(sys.argv) > 2 else None print ("modes: ", modes_list) core = RFXtrx.Connect(RFXtrx.PySerialTransport(rfxcom_device), print_callback, modes=modes_list) core.connect() print (core) while True: print(core.sensors()) time.sleep(2) if __name__ == "__main__": try: main() except KeyboardInterrupt: passpyRFXtrx-0.32.0/examples/send.py000066400000000000000000000025201500543535500164670ustar00rootroot00000000000000# This file is part of pyRFXtrx, a Python library to communicate with # the RFXtrx family of devices from http://www.rfxcom.com/ # See https://github.com/woudt/pyRFXtrx for the latest version. # # Copyright (C) 2012 Edwin Woudt # # pyRFXtrx is free software: you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # pyRFXtrx is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with pyRFXtrx. See the file COPYING.txt in the distribution. # If not, see . NOT TESTED from RFXtrx.pyserial import PySerialTransport from RFXtrx import LightingDevice from time import sleep transport = PySerialTransport('/dev/cu.usbserial-05VN8GHS') transport.connect() transport.reset() while True: event = transport.receive_blocking() if isinstance(event.device, LightingDevice): sleep(5) event.device.send_off(transport) ack = transport.receive_blocking() pyRFXtrx-0.32.0/pylintrc000066400000000000000000000012501500543535500151340ustar00rootroot00000000000000[MASTER] reports=no # Reasons disabled: # locally-disabled - it spams too much # redefined-variable-type - this is Python, we're duck typing! disable= locally-disabled, [MESSAGES CONTROL] # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option # multiple time. #enable= # Disable the message, report, category or checker with the given id(s). You # can either give multiple identifier separated by comma (,) or put this option # multiple time (only on the command line, not in the configuration file where # it should appear only once). disable=C0209, R0917 [EXCEPTIONS] pyRFXtrx-0.32.0/requirements.txt000066400000000000000000000000111500543535500166230ustar00rootroot00000000000000pyserial pyRFXtrx-0.32.0/requirements_test.txt000066400000000000000000000001401500543535500176650ustar00rootroot00000000000000flake8>=2.5.1 pylint>=1.5.3 coveralls>=1.1 pytest>=2.8.0 pytest-cov>=2.2.0 pytest-timeout>=1.0.0pyRFXtrx-0.32.0/setup.cfg000066400000000000000000000000401500543535500151620ustar00rootroot00000000000000[tool:pytest] testpaths = tests pyRFXtrx-0.32.0/setup.py000066400000000000000000000033071500543535500150640ustar00rootroot00000000000000''' This file is part of pyRFXtrx, a Python library to communicate with the RFXtrx family of devices from http://www.rfxcom.com/ See https://github.com/Danielhiversen/pyRFXtrx for the latest version. Copyright (C) 2012 Edwin Woudt pyRFXtrx is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. pyRFXtrx is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with pyRFXtrx. See the file COPYING.txt in the distribution. If not, see . ''' from setuptools import setup setup( name = 'pyRFXtrx', packages = ['RFXtrx'], install_requires=['pyserial>=2.7'], version = '0.32.0', description = 'a library to communicate with the RFXtrx family of devices', author='Edwin Woudt', author_email='edwin@woudt.nl', url='https://github.com/Danielhiversen/pyRFXtrx', classifiers=[ 'Development Status :: 3 - Alpha', 'Environment :: Other Environment', 'Intended Audience :: Developers', 'License :: OSI Approved :: ' + 'GNU Lesser General Public License v3 or later (LGPLv3+)', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Topic :: Home Automation', 'Topic :: Software Development :: Libraries :: Python Modules' ] ) pyRFXtrx-0.32.0/tests/000077500000000000000000000000001500543535500145115ustar00rootroot00000000000000pyRFXtrx-0.32.0/tests/test_base.py000066400000000000000000000634511500543535500170450ustar00rootroot00000000000000from unittest import TestCase import time import RFXtrx num_calbacks = 0 def _callback(*args, **kwargs): global num_calbacks num_calbacks = num_calbacks + 1 class CoreTestCase(TestCase): def setUp(self): self.path = '/dev/serial/...' global num_calbacks num_calbacks = 0 self.maxDiff = 1000 def test_constructor(self): global num_calbacks core = RFXtrx.Connect(RFXtrx.DummyTransport2(self.path), event_callback=_callback) core.connect() while num_calbacks < 7: time.sleep(0.1) self.assertEqual(len(core.sensors()),3) self.assertTrue(core._thread.is_alive()) core.close_connection() self.assertFalse(core._thread.is_alive()) def test_invalid_packet(self): bytes_array = bytearray([0x09, 0x11, 0xd7, 0x00, 0x01, 0x1d, 0x14, 0x02, 0x79, 0x0a]) core = RFXtrx.Connect(RFXtrx.DummyTransport(self.path), event_callback=_callback) core.connect() event = core.transport.parse(bytes_array) self.assertIsNone(event) def test_format_packet(self): # Lighting1 core = RFXtrx.Connect(RFXtrx.DummyTransport(self.path), event_callback=_callback) core.connect() bytes_array = bytearray([0x07, 0x10, 0x00, 0x2a, 0x45, 0x05, 0x01, 0x70]) event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.ControlEvent, type(event)) self.assertEqual(event.device.type_string,'X10 lighting') self.assertEqual(event.device.id_string,'E5') self.assertEqual(event.values['Command'],'On') self.assertEqual(event.values['Rssi numeric'],7) event.device.send_on(core.transport) event.device.send_off(core.transport) self.assertRaises(ValueError,event.device.send_dim,core.transport,50) # Lighting2 bytes_array =[0x0b, 0x11, 0x00, 0x2a, 0x01, 0x23, 0x45, 0x67, 0x05, 0x02, 0x07, 0x70] event = core.transport.parse(bytes_array) event.device.send_on(core.transport) event.device.send_off(core.transport) self.assertRaises(ValueError,event.device.send_dim,core.transport,150) self.assertRaises(ValueError,event.device.send_dim,core.transport,-1) event.device.send_dim(core.transport,50) event.device.send_dim(core.transport,0) # Lighting3 bytes_array = [0x08, 0x12, 0x00, 0x2a, 0x01, 0x34, 0x02, 0x15, 0x79] event = core.transport.parse(bytes_array) event.device.send_on(core.transport) event.device.send_off(core.transport) self.assertRaises(ValueError,event.device.send_dim,core.transport,150) self.assertRaises(ValueError,event.device.send_dim,core.transport,-1) event.device.send_dim(core.transport,50) event.device.send_dim(core.transport,0) # Lighting4 bytes_array = [0x09, 0x13, 0x00, 0x2a, 0x12, 0x34, 0x56, 0x01, 0x5e, 0x70] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.ControlEvent, type(event)) self.assertEqual(RFXtrx.LightingDevice, type(event.device)) event.device.send_on(core.transport) event.device.send_off(core.transport) self.assertRaises(ValueError,event.device.send_dim,core.transport,50) # Lighting5, subtype0 bytes_array = bytearray(b'\x0A\x14\x00\xAD\xF3\x94\xAB\x01\x10\x00\x60') event = core.transport.parse(bytes_array) event.device.send_on(core.transport) event.device.send_off(core.transport) event.device.send_open(core.transport) event.device.send_close(core.transport) event.device.send_stop(core.transport) self.assertRaises(ValueError,event.device.send_openclosestop,core.transport,0x0c) self.assertRaises(ValueError,event.device.send_dim,core.transport,150) self.assertRaises(ValueError,event.device.send_dim,core.transport,-1) event.device.send_dim(core.transport,50) event.device.send_dim(core.transport,0) # Lighting5, subtype0, rollershutter bytes_array = bytearray(b'\x0A\x14\x00\xAD\xF3\x94\xAB\x01\x0D\x00\x60') event = core.transport.parse(bytes_array) event.device.send_open(core.transport) event.device.send_close(core.transport) event.device.send_stop(core.transport) # Lighting5, subtype1 bytes_array = bytearray(b'\x0A\x14\x01\xAD\xF3\x94\xAB\x01\x10\x00\x60') event = core.transport.parse(bytes_array) event.device.send_on(core.transport) event.device.send_off(core.transport) self.assertRaises(ValueError,event.device.send_dim,core.transport,150) self.assertRaises(ValueError,event.device.send_dim,core.transport,-1) event.device.send_dim(core.transport,50) event.device.send_dim(core.transport,0) # Lighting5, subtype2 bytes_array = bytearray(b'\x0A\x14\x02\xAD\xF3\x94\xAB\x01\x10\x00\x60') event = core.transport.parse(bytes_array) event.device.send_on(core.transport) event.device.send_off(core.transport) self.assertRaises(ValueError,event.device.send_dim,core.transport,150) self.assertRaises(ValueError,event.device.send_dim,core.transport,-1) event.device.send_dim(core.transport,50) event.device.send_dim(core.transport,0) # Lighting5, subtype3 bytes_array = bytearray(b'\x0A\x14\x03\xAD\xF3\x94\xAB\x01\x10\x00\x60') event = core.transport.parse(bytes_array) event.device.send_on(core.transport) event.device.send_off(core.transport) self.assertRaises(ValueError,event.device.send_dim,core.transport,150) self.assertRaises(ValueError,event.device.send_dim,core.transport,-1) event.device.send_dim(core.transport,50) event.device.send_dim(core.transport,0) # Lighting5, subtype4 bytes_array = bytearray(b'\x0A\x14\x04\xAD\xF3\x94\xAB\x01\x10\x00\x60') event = core.transport.parse(bytes_array) event.device.send_on(core.transport) event.device.send_off(core.transport) self.assertRaises(ValueError,event.device.send_dim,core.transport,150) self.assertRaises(ValueError,event.device.send_dim,core.transport,-1) event.device.send_dim(core.transport,50) event.device.send_dim(core.transport,0) # Lighting5, subtype5 bytes_array = bytearray(b'\x0A\x14\x05\xAD\xF3\x94\xAB\x01\x10\x00\x60') event = core.transport.parse(bytes_array) event.device.send_on(core.transport) event.device.send_off(core.transport) self.assertRaises(ValueError,event.device.send_dim,core.transport,150) self.assertRaises(ValueError,event.device.send_dim,core.transport,-1) event.device.send_dim(core.transport,50) event.device.send_dim(core.transport,0) # Lighting5, subtype6 . unknown bytes_array = bytearray(b'\x0A\x14\x06\xAD\xF3\x94\xAB\x01\x10\x00\x60') event = core.transport.parse(bytes_array) event.device.send_on(core.transport) event.device.send_off(core.transport) self.assertRaises(ValueError,event.device.send_dim,core.transport,150) self.assertRaises(ValueError,event.device.send_dim,core.transport,-1) event.device.send_dim(core.transport,50) event.device.send_dim(core.transport,0) #Lighting 6 bytes_array = [0x0b, 0x15, 0x00, 0x2a, 0x12, 0x34, 0x41, 0x05, 0x03, 0x01, 0x00, 0x70] event = core.transport.parse(bytes_array) event.device.send_on(core.transport) event.device.send_off(core.transport) self.assertRaises(ValueError,event.device.send_dim,core.transport,50) #rain bytes_array = [0x0b, 0x55, 0x02, 0x03, 0x12, 0x34, 0x02, 0x50, 0x01, 0x23, 0x45, 0x57] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='PCR800' id='12:34'] values=[('Battery numeric', 7), ('Rain rate', 5.92), ('Rain total', 7456.5), ('Rssi numeric', 5)]") #bbq bytes_array = [0x0a, 0x4e, 0x01, 0x06, 0xfc, 0xd8, 0x00, 0x13, 0x00, 0x13, 0x79] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='BBQ1 - Maverick ET-732' id='fcd800:78'] values=[('Battery numeric', 9), ('Rssi numeric', 7), ('Temperature', 19), ('Temperature2', 19)]") #baro bytes_array = [0x09, 0x53, 0x01, 0x2a, 0x96, 0x03, 0x04, 0x06, 0x00, 0x79] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='Unknown type (0x53/0x01)' id='96:03'] values=[('Barometer', 1030), ('Battery numeric', 9), ('Forecast', 'no forecast available'), ('Forecast numeric', 0), ('Rssi numeric', 7)]") #wind bytes_array = [0x10, 0x56, 0x01, 0x03, 0x2F, 0x00, 0x00, 0xF7, 0x00, 0x20, 0x00, 0x24, 0x81, 0x60, 0x82, 0x50, 0x59] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='WTGR800' id='2f:00'] values=[('Battery numeric', 9), ('Rssi numeric', 5), ('Wind average speed', 3.2), ('Wind direction', 247), ('Wind gust', 3.6)]") #uv bytes_array = [0x09, 0x57, 0x02, 0x02, 0x64, 0x00, 0x20, 0x02, 0x3c, 0x69] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='UVN800' id='64:00'] values=[('Battery numeric', 9), ('Rssi numeric', 6), ('UV', 3.2)]") #Elec4 bytes_array = [0x13, 0x5b, 0x01, 0x04, 0x2e, 0xB2, 0x01, 0x11, 0x12, 0x14, 0x15, 0x17, 0x18, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x69] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='ELEC4, CM180i' id='2e:b2'] values=[('Battery numeric', 9), ('Count', 1), ('Current Ch. 1', 437.0), ('Current Ch. 2', 514.1), ('Current Ch. 3', 591.2), ('Rssi numeric', 6), ('Total usage', 113527617921.3023)]") #Cartelectronic TIC bytes_array = [0x15, 0x60, 0x01, 0x03, 0x07, 0x7d, 0x20, 0x06, 0x86, 0x11, 0x00, 0x3a, 0x92, 0xc9, 0x00, 0x00, 0x00, 0x00, 0x01, 0x4a, 0x02, 0x79] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='CARTELECTRONIC_TIC' id='77d200686'] values=[('Battery numeric', 9), ('Contract type', 17), ('Count', 0), ('Counter value', 3838665), ('Energy usage', 330), ('Rssi numeric', 7), ('Sensor Status', True)]") #Cartelectronic Encoder bytes_array = [0x11, 0x60, 0x02, 0x5f, 0x3f, 0xfe, 0x61, 0xa3, 0x00, 0x00, 0x47, 0xd4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x69] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='CARTELECTRONIC_ENCODER' id='3ffe61a3'] values=[('Battery numeric', 9), ('Count', 0), ('Counter value', 18388), ('Rssi numeric', 6)]") #Cartelectronic Linky bytes_array = [0x15, 0x60, 0x03, 0x5c, 0x2a, 0x29, 0xf2, 0x75, 0x00, 0x19, 0x8d, 0x3a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x02, 0xb9, 0x00, 0x69] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='CARTELECTRONIC_LINKY' id='2a29f275'] values=[('Battery numeric', 9), ('Count', 0), ('Counter value', 0), ('Energy usage', 697), ('Rssi numeric', 6), ('Sensor Status', True), ('Total usage', 1674554), ('Voltage', 233)]") #Lighting5 bytes_array = bytearray(b'\x0A\x14\x00\xAD\xF3\x94\xAB' b'\x01\x01\x00\x60') event= core.transport.receive(bytes_array) self.assertEqual(RFXtrx.ControlEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='LightwaveRF, Siemens' id='f394ab:1'] values=[('Command', 'On'), ('Rssi numeric', 6)]") #RollerTrol bytes_array = bytearray(b'\x09\x19\x00\x00\x00\x9b\xa8\x01\x01\x00') event= core.transport.receive(bytes_array) self.assertEqual(RFXtrx.ControlEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='RollerTrol' id='009ba8:1'] values=[('Command', 'Down'), ('Rssi numeric', 0)]") event.device.send_open(core.transport) event.device.send_close(core.transport) event.device.send_stop(core.transport) #Rfy bytes_array = bytearray(b'\x0C\x1A\x00\x00\x0A\x00\x01\x01\x03\x00\x00\x00\x03') event= core.transport.receive(bytes_array) self.assertEqual(RFXtrx.ControlEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='Rfy' id='0a0001:1'] values=[('Command', 'Down'), ('Rssi numeric', 0)]") event.device.send_open(core.transport) event.device.send_close(core.transport) event.device.send_stop(core.transport) event.device.send_up05sec(core.transport) event.device.send_down05sec(core.transport) event.device.send_up2sec(core.transport) event.device.send_down2sec(core.transport) event.device.send_on(core.transport) event.device.send_off(core.transport) #Funkbus bytes_array = [0x09, 0x1E, 0x00, 0x00, 0x3F, 0xCC, 0x42, 0x01, 0x00, 0x00] event= core.transport.receive(bytes_array) self.assertEqual(RFXtrx.ControlEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='Gira remote' id='3fcc:4201'] values=[('Command', 'Down'), ('Keypress', 'short')]") event.device.send_on(core.transport) event.device.send_off(core.transport) event.device.send_dim(core.transport, 0x02) event.device.send_bright(core.transport, 0x02) event.device.send_allon(core.transport) event.device.send_alloff(core.transport) event.device.send_setscene(core.transport, 0x03) event.device.send_masterdim(core.transport, 0x02) event.device.send_masterbright(core.transport, 0x02) #temphumid bytes_array = [0x0a, 0x52, 0x01, 0x2a, 0x96, 0x03, 0x81, 0x41, 0x60, 0x03, 0x79] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='THGN122/123, THGN132, THGR122/228/238/268' id='96:03'] values=[('Battery numeric', 9), ('Humidity', 96), ('Humidity status', 'wet'), ('Humidity status numeric', 3), ('Rssi numeric', 7), ('Temperature', -32.1)]") #Chime bytes_array = [0x0a, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.ControlEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='Byron SX' id='00:00'] values=[('Command', 'Sound 0'), ('Rssi numeric', 0), ('Sound', 0)]") event.device.send_command(core.transport, 1) #security1 bytes_array = [0x0a, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='X10 Security' id='000000:32'] values=[('Battery numeric', 0), ('Rssi numeric', 0), ('Sensor Status', 'Normal')]") event.device.send_status(core.transport, 0x01) #temp bytes_array = [0x0a, 0x50, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='THR128/138, THC138' id='00:00'] values=[('Battery numeric', 0), ('Rssi numeric', 0), ('Temperature', 0.0)]") #humid bytes_array = [0x0a, 0x51, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='LaCrosse TX3' id='00:00'] values=[('Battery numeric', 0), ('Humidity', 0), ('Humidity status', 'dry'), ('Humidity status numeric', 0), ('Rssi numeric', 0)]") #temphumidBaro bytes_array = [0x10, 0x54, 0x01, 0x03, 0x2F, 0x00, 0x00, 0xF7, 0x00, 0x20, 0x00, 0x24, 0x81, 0x60, 0x82, 0x50, 0x59] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='BTHR918' id='2f:00'] values=[('Barometer', 36), ('Battery numeric', 0), ('Forecast', 'unknown forecast'), ('Forecast numeric', 129), ('Humidity', 0), ('Humidity status', 'unknown humidity'), ('Humidity status numeric', 32), ('Rssi numeric', 6), ('Temperature', 24.7)]") #rfxmeter # A 71 0 1F 21 D1 0 20 1F A4 60 bytes_array = [0x0A, 0x71, 0x00, 0x1F, 0x21, 0xD1, 0x00, 0x20, 0x1F, 0xA4, 0x60] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.device.subtype, 0x00) self.assertEqual(event.device.type_string, 'RFXMeter Count') self.assertEqual(event.device.id_string, '21') self.assertEqual(event.values['Counter value'], 2105252) #temphumidBaro, too short package length bytes_array = [0x10, 0x54, 0x01, 0x03, 0x2F, 0x00, 0x00, 0xF7, 0x00, 0x20, 0x00, 0x24, 0x81, 0x60, 0x82, 0x50] event = core.transport.parse(bytes_array) self.assertEqual(None, event) #temprain bytes_array = [0x0a, 0x4f, 0x01, 0x06, 0xee, 0x09, 0x00, 0x65, 0x00, 0x03, 0x69] event = core.transport.parse(bytes_array) self.assertEqual(RFXtrx.SensorEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='TR1 - WS1200' id='ee:09'] values=[('Battery numeric', 9), ('Rain total', 0.3), ('Rssi numeric', 6), ('Temperature', 10.1)]") core.close_connection() def test_equal_check(self): data1 = bytearray(b'\x11\x5A\x01\x00\x2E\xB2\x03\x00\x00' b'\x02\xB4\x00\x00\x0C\x46\xA8\x11\x69') energy = RFXtrx.lowlevel.parse(data1) data2 = bytearray(b'\x0A\x14\x00\xAD\xF3\x94\xAB' b'\x01\x01\x00\x60') light = RFXtrx.lowlevel.parse(data2) light2 = RFXtrx.lowlevel.parse(data2) data3 = bytearray(b'\x0A\x52\x02\x11\x70\x02\x00\xA7' b'\x2D\x00\x89') temphum = RFXtrx.lowlevel.parse(data3) self.assertTrue(light==light2) self.assertFalse(light==energy) self.assertFalse(temphum==energy) def test_equal_device_check(self): core = RFXtrx.Connect(RFXtrx.DummyTransport(self.path), event_callback=_callback) core.connect() data1 = bytearray(b'\x11\x5A\x01\x00\x2E\xB2\x03\x00\x00' b'\x02\xB4\x00\x00\x0C\x46\xA8\x11\x69') energy = core.transport.receive(data1) data2 = bytearray(b'\x0A\x14\x00\xAD\xF3\x94\xAB' b'\x01\x01\x00\x60') light = core.transport.receive(data2) light2 = core.transport.receive(data2) data3 = bytearray(b'\x0A\x52\x02\x11\x70\x02\x00\xA7' b'\x2D\x00\x89') temphum = core.transport.receive(data3) bytes_array = bytearray(b'\x0A\x14\x00\xAD\xF3\x94\xAB\x01\x10\x00\x60') lighting5_subtype0 = core.transport.receive(bytes_array) bytes_array = bytearray(b'\x0A\x14\x01\xAD\xF3\x94\xAB\x01\x10\x00\x60') lighting5_subtype1 = core.transport.receive(bytes_array) self.assertFalse(light==light2) self.assertFalse(light==energy) self.assertFalse(temphum==energy) self.assertTrue(light.device==light2.device) self.assertFalse(light.device==energy.device) self.assertFalse(temphum.device==energy.device) self.assertFalse(lighting5_subtype0.device==lighting5_subtype1.device) core.close_connection() def test_get_device(self): core = RFXtrx.Connect(RFXtrx.DummyTransport(self.path), event_callback=_callback) core.connect() # Lighting1 bytes_array = bytearray([0x07, 0x10, 0x00, 0x2a, 0x45, 0x05, 0x01, 0x70]) event = core.transport.parse(bytes_array) device = RFXtrx.get_device(event.device.packettype, event.device.subtype, event.device.id_string) self.assertTrue(device==event.device) # Lighting2 bytes_array =[0x0b, 0x11, 0x00, 0x2a, 0x01, 0x23, 0x45, 0x67, 0x05, 0x02, 0x07, 0x70] event = core.transport.parse(bytes_array) device = RFXtrx.get_device(event.device.packettype, event.device.subtype, event.device.id_string) self.assertTrue(device==event.device) # Lighting3 bytes_array = [0x08, 0x12, 0x00, 0x2a, 0x01, 0x34, 0x02, 0x15, 0x79] event = core.transport.parse(bytes_array) device = RFXtrx.get_device(event.device.packettype, event.device.subtype, event.device.id_string) self.assertTrue(device==event.device) # Lighting4 bytes_array = [0x09, 0x13, 0x00, 0x2a, 0x12, 0x34, 0x56, 0x01, 0x5e, 0x70] event = core.transport.parse(bytes_array) device = RFXtrx.get_device(event.device.packettype, event.device.subtype, event.device.id_string) self.assertTrue(device==event.device) # Lighting5 bytes_array = bytearray(b'\x0A\x14\x00\xAD\xF3\x94\xAB' b'\x01\x01\x00\x60') event = core.transport.parse(bytes_array) device = RFXtrx.get_device(event.device.packettype, event.device.subtype, event.device.id_string) self.assertTrue(device==event.device) #Lighting 6 bytes_array = [0x0b, 0x15, 0x00, 0x2a, 0x12, 0x34, 0x41, 0x05, 0x03, 0x01, 0x00, 0x70] event = core.transport.parse(bytes_array) device = RFXtrx.get_device(event.device.packettype, event.device.subtype, event.device.id_string) self.assertTrue(device==event.device) #energy sensor bytes_array = bytearray(b'\x11\x5A\x01\x00\x2E\xB2\x03\x00\x00' b'\x02\xB4\x00\x00\x0C\x46\xA8\x11\x69') event = core.transport.parse(bytes_array) self.assertRaises(ValueError, RFXtrx.get_device,event.device.packettype, event.device.subtype, event.device.id_string) core.close_connection() def test_set_recmodes(self): core = RFXtrx.Connect(RFXtrx.DummyTransport(self.path), event_callback=_callback) core.connect() time.sleep(0.2) self.assertEqual(None, core._modes) modes = ['ac', 'arc', 'hideki', 'homeeasy', 'keeloq', 'lacrosse', 'oregon', 'rsl', 'x10'] bytes_array = bytearray(b'\x0D\x01\x00\x01\x02\x53\x45' b'\x10' # msg3: rsl b'\x0C' # msg4: hideki lacrosse b'\x2F' # msg5: x10 arc ac homeeasy oregon b'\x01' # msg6: keeloq b'\x01\x00\x00' # unused ) core._status = core.transport.receive(bytes_array) core.set_recmodes(modes) self.assertEqual(modes, core._modes) # set an unknown mode with self.assertRaises(ValueError): core.set_recmodes(['arc', 'oregon', 'unknown-mode']) def test_receive(self): core = RFXtrx.Connect(RFXtrx.DummyTransport(self.path), event_callback=_callback) core.connect() time.sleep(0.2) # Lighting1 bytes_array = bytearray([0x07, 0x10, 0x00, 0x2a, 0x45, 0x05, 0x01, 0x70]) event= core.transport.receive(bytes_array) self.assertEqual(RFXtrx.ControlEvent, type(event)) self.assertEqual(event.__str__()," device=[ type='X10 lighting' id='E5'] values=[('Command', 'On'), ('Rssi numeric', 7)]") #status bytes_array = bytearray(b'\x0D\x01\x00\x01\x02\x53\x45' b'\x10' # msg3: rsl b'\x0C' # msg4: hideki lacrosse b'\x2F' # msg5: x10 arc ac homeeasy oregon b'\x01' # msg6: keeloq b'\x01\x00\x00' # unused ) event= core.transport.receive(bytes_array) self.assertEqual(RFXtrx.StatusEvent, type(event)) self.assertEqual(event.__str__()," device=[Status [subtype=433.92MHz, firmware=69, output_power=0, devices=['ac', 'arc', 'hideki', 'homeeasy', 'keeloq', 'lacrosse', 'oregon', 'rsl', 'x10']]]") core.close_connection() pyRFXtrx-0.32.0/tests/test_bbq.py000066400000000000000000000041761500543535500166760ustar00rootroot00000000000000from unittest import TestCase import RFXtrx class BbqTestCase(TestCase): def setUp(self): self.parser = RFXtrx.lowlevel.Bbq() def test_parse_bytes(self): self.data = bytearray([0x0a, 0x4e, 0x01, 0x06, 0xfc, 0xd8, 0x00, 0x13, 0x00, 0x13, 0x79]) bbq = RFXtrx.lowlevel.parse(self.data) self.assertEqual(RFXtrx.lowlevel.Bbq, type(bbq)) self.assertEqual(bbq.temp1,19) self.assertEqual(bbq.temp2,19) self.assertEqual(bbq.type_string,'BBQ1 - Maverick ET-732') self.assertEqual(bbq.id_string,'fcd800:78') self.data = bytearray([0x0a, 0x4e, 0x01, 0x01, 0x6f, 0xe1, 0x00, 0x13, 0x00, 0x20, 0x79]) bbq = RFXtrx.lowlevel.parse(self.data) self.assertEqual(RFXtrx.lowlevel.Bbq, type(bbq)) self.assertEqual(bbq.temp1,19) self.assertEqual(bbq.temp2,32) self.assertEqual(bbq.type_string,'BBQ1 - Maverick ET-732') self.assertEqual(bbq.id_string,'6fe100:78') self.data = bytearray([0x0a, 0x4e, 0x01, 0x11, 0x6f, 0xe1, 0x00, 0x1c, 0x00, 0x1a, 0x79]) bbq = RFXtrx.lowlevel.parse(self.data) self.assertEqual(RFXtrx.lowlevel.Bbq, type(bbq)) self.assertEqual(bbq.temp1,28) self.assertEqual(bbq.temp2,26) self.assertEqual(bbq.type_string,'BBQ1 - Maverick ET-732') self.assertEqual(bbq.id_string,'6fe100:78') self.data = bytearray([0x0a, 0x4e, 0x01, 0x15, 0x6f, 0xe1, 0x00, 0x1a, 0x00, 0x1e, 0x79]) bbq = RFXtrx.lowlevel.parse(self.data) self.assertEqual(RFXtrx.lowlevel.Bbq, type(bbq)) self.assertEqual(bbq.temp1,26) self.assertEqual(bbq.temp2,30) self.assertEqual(bbq.type_string,'BBQ1 - Maverick ET-732') self.assertEqual(bbq.id_string,'6fe100:78') self.data = bytearray([0x0a, 0x4e, 0x01, 0x1f, 0x6f, 0xe1, 0x00, 0x18, 0x00, 0x1f, 0x79]) bbq = RFXtrx.lowlevel.parse(self.data) self.assertEqual(RFXtrx.lowlevel.Bbq, type(bbq)) self.assertEqual(bbq.temp1,24) self.assertEqual(bbq.temp2,31) self.assertEqual(bbq.type_string,'BBQ1 - Maverick ET-732') self.assertEqual(bbq.id_string,'6fe100:78') pyRFXtrx-0.32.0/tests/test_energy.py000066400000000000000000000140331500543535500174140ustar00rootroot00000000000000from unittest import TestCase import RFXtrx from RFXtrx.lowlevel import Cartelectronic class Elec1TestCase(TestCase): def setUp(self): self.data = bytearray(b'\x0D\x59\x01\xA7\x56\x00\x0A' b'\x00\x07\x00\x00\x0B\x07\x69') self.parser = RFXtrx.lowlevel.Energy1() def test_parse_bytes(self): energy = RFXtrx.lowlevel.parse(self.data) print(energy) self.assertEqual(energy.type_string,"ELEC1, Electrisave") self.assertEqual(energy.seqnbr,167) self.assertEqual(energy.id_string,"56:00") self.assertEqual(energy.count,10) self.assertEqual(energy.currentamps1,0.7) self.assertEqual(energy.currentamps2,0) self.assertEqual(energy.currentamps3,282.3) self.assertEqual(energy.rssi,6) self.assertEqual(energy.battery,9) class Elec2TestCase(TestCase): def setUp(self): self.data = bytearray(b'\x11\x5A\x01\x00\x2E\xB2\x03\x00\x00' b'\x02\xB4\x00\x00\x0C\x46\xA8\x11\x69') self.parser = RFXtrx.lowlevel.Energy() def test_parse_bytes(self): energy = RFXtrx.lowlevel.parse(self.data) self.assertEqual(energy.type_string,"ELEC2, CM119/160") self.assertEqual(energy.seqnbr,0) self.assertEqual(energy.id_string,"2e:b2") self.assertEqual(energy.count,3) self.assertEqual(energy.currentwatt,692) self.assertEqual(energy.totalwatts,920824.5195961836) class Elec4TestCase(TestCase): def setUp(self): self.data = bytearray(b'\x13\x5b\x01\x04' b'\x2e\xB2' b'\x01' b'\x11\x12' b'\x14\x15' b'\x17\x18' b'\x17\x18\x19\x20\x21\x22' b'\x69') self.parser = RFXtrx.lowlevel.Energy4() def test_parse_bytes(self): energy = RFXtrx.lowlevel.parse(self.data) self.assertEqual(energy.type_string,"ELEC4, CM180i") self.assertEqual(energy.seqnbr,4) self.assertEqual(energy.id_string,"2e:b2") self.assertEqual(energy.count,1) self.assertEqual(energy.currentamps1,437) self.assertEqual(energy.currentamps2,514.1) self.assertEqual(energy.currentamps3,591.2) self.assertEqual(energy.totalwatthours,113527617921.3023) class Elec5TestCase(TestCase): def setUp(self): self.data = bytearray(b'\x0f\x5c\x01\x05' b'\x23\x95' b'\xb2' b'\x04\x48' b'\x20\xce' b'\x00\x76' b'\x00' b'\x32' b'\x80') self.parser = RFXtrx.lowlevel.Energy5() def test_parse_bytes(self): energy = RFXtrx.lowlevel.parse(self.data) self.assertEqual(energy.type_string,"ELEC5, Revolt") self.assertEqual(energy.seqnbr,5) self.assertEqual(energy.id_string,"23:95") self.assertEqual(energy.voltage,178) self.assertEqual(energy.currentamps,10.96) self.assertEqual(energy.currentwatt,839.8) self.assertEqual(energy.totalwatthours,1180) self.assertEqual(energy.powerfactor,0) self.assertEqual(energy.frequency,50) class CartelectronicTestCase(TestCase): def setUp(self): self.data = "" self.parser = RFXtrx.lowlevel.Cartelectronic() def test_parse_bytes(self): # Encoder self.data = bytearray(b'\x11\x60\x02\xb3\x3f\xfe\x61\xa3' b'\x00\x00\x3c\x01' b'\x00\x00\x00\x00' b'\x00\x69') energy = RFXtrx.lowlevel.parse(self.data) self.assertEqual(energy.type_string, "CARTELECTRONIC_ENCODER") self.assertEqual(energy.seqnbr, 179) self.assertEqual(energy.id_string, "3ffe61a3") self.assertEqual(energy.counter1, 15361) self.assertEqual(energy.counter2, 0) # Linky self.data = bytearray(b'\x15\x60\x03\xb0\x2a\x29\xf2\x75' b'\x00\x17\x9d\x74' b'\x00\x00\x00\x00' b'\x00' b'\x23' b'\x02\xae' b'\x00\x69') energy = RFXtrx.lowlevel.parse(self.data) self.assertEqual(energy.type_string, "CARTELECTRONIC_LINKY") self.assertEqual(energy.seqnbr, 176) self.assertEqual(energy.id_string, "2a29f275") self.assertEqual(energy.conswatthours, 1547636) self.assertEqual(energy.prodwatthours, 0) self.assertEqual(energy.tarif_num, 0) self.assertEqual(energy.voltage, 235) self.assertEqual(energy.currentwatt, 686) self.assertEqual(energy.teleinfo_ok, True) self.data = bytearray([0x15, 0x60, 0x01, 0x03, 0x07, 0x7d, 0x20, 0x06, 0x86, 0x11, 0x00, 0x3a, 0x92, 0xc9, 0x00, 0x00, 0x00, 0x00, 0x01, 0x4a, 0x02, 0x79]) energy = RFXtrx.lowlevel.parse(self.data) assert isinstance(energy, Cartelectronic) self.assertEqual(energy.type_string, "CARTELECTRONIC_TIC") self.assertEqual(energy.seqnbr, 3) self.assertEqual(energy.id_string, "77d200686") self.assertEqual(energy.conswatthours, None) self.assertEqual(energy.prodwatthours, None) self.assertEqual(energy.tarif_num, None) self.assertEqual(energy.voltage, None) self.assertEqual(energy.counter1, 3838665) self.assertEqual(energy.counter2, 0) self.assertEqual(energy.currentwatt, 330) self.assertEqual(energy.teleinfo_ok, True) self.assertEqual(energy.contract_type, 17) pyRFXtrx-0.32.0/tests/test_funkbus.py000066400000000000000000000047701500543535500176070ustar00rootroot00000000000000from unittest import TestCase import RFXtrx class FunkbusTestCase(TestCase): def test_parse_bytes(self): funkbus = RFXtrx.lowlevel.parse(bytearray(b'\x09\x1E\x00\x00\x0A\x0B\x42\x01\x01\x01')) self.assertEqual(funkbus.__repr__(), "Funkbus [subtype=0, seqnbr=0, id=0a0b:4201, group=B, target=1, cmnd=Up, time=1 sec]") self.assertEqual(funkbus.packetlength, 9) self.assertEqual(funkbus.subtype, 0) self.assertEqual(funkbus.type_string, "Gira remote") self.assertEqual(funkbus.seqnbr, 0) self.assertEqual(funkbus.id_string, "0a0b:4201") self.assertEqual(funkbus.cmnd, 1) self.assertEqual(funkbus.cmnd_string, "Up") funkbus = RFXtrx.lowlevel.Funkbus() funkbus.set_transmit(0, 0, 0x0a0b, 0x41, 0x06, 0x00, 0x00) self.assertEqual(funkbus.__repr__(), "Funkbus [subtype=0, seqnbr=0, id=0a0b:4106, group=A, target=6, cmnd=Down, time=short]") self.assertEqual(funkbus.packetlength, 11) self.assertEqual(funkbus.subtype, 0) self.assertEqual(funkbus.type_string, "Gira remote") self.assertEqual(funkbus.seqnbr, 0) self.assertEqual(funkbus.id1, 10) self.assertEqual(funkbus.id2, 11) self.assertEqual(funkbus.id_combined, 2571) self.assertEqual(funkbus.id_string, "0a0b:4106") self.assertEqual(funkbus.cmnd, 0) self.assertEqual(funkbus.cmnd_string, "Down") self.assertEqual(funkbus.target, 6) self.assertEqual(funkbus.target_string, "6") self.assertEqual(funkbus.time, 0) self.assertEqual(funkbus.time_string, "short") funkbus = RFXtrx.lowlevel.Funkbus() funkbus.parse_id(0, "3fcc:4301") self.assertEqual(funkbus.id1, 63) self.assertRaises(ValueError, funkbus.parse_id, 0, "1E87") funkbus = RFXtrx.get_device(0x1E, 0, "3fcc:4102") self.assertEqual(funkbus.__str__(), " type='Gira remote' id='3fcc:4102'") self.assertEqual(funkbus.groupcode, 65) self.assertEqual(funkbus.target, 2) funkbus = RFXtrx.lowlevel.parse(bytearray(b'\x09\x1E\x01\x00\x0A\x0B\x41\x09\x09\x00')) self.assertEqual(funkbus.cmnd_string, "Unknown command (0x09)") self.assertEqual(funkbus.type_string, "Insta remote") funkbus = RFXtrx.lowlevel.parse(bytearray(b'\x09\x1E\x05\x00\x0A\x0B\x41\x09\x07\x00')) self.assertEqual(funkbus.cmnd_string, "Unknown command (0x07)") self.assertEqual(funkbus.type_string, "Unknown type (0x1e/0x05)")pyRFXtrx-0.32.0/tests/test_lights.py000066400000000000000000000205731500543535500174230ustar00rootroot00000000000000import unittest from RFXtrx import lowlevel import RFXtrx class TestRFXTRlowlevel(unittest.TestCase): """ Tests rfxtrx lowlewel """ def test_Status(self): x = lowlevel.Status() self.assertIsNone(x.type_string) self.assertIsNone(x.firmware_version) self.assertIsNone(x.devices) x.load_receive(bytearray([0x0d, 0x01, 0x00, 0x01, 0x02, 0x53, 0x3e, 0x00, 0x0c, 0x2f, 0x01, 0x01, 0x00, 0x00])) self.assertEqual(x.type_string, "433.92MHz") self.assertEqual(x.firmware_version, 62) self.assertEqual(x.output_power, 0) self.assertEqual(x.devices, ['ac', 'arc', 'hideki', 'homeeasy', 'keeloq', 'lacrosse', 'oregon', 'x10']) self.assertEqual(list(x.data), [13, 1, 0, 1, 2, 83, 62, 0, 12, 47, 1, 1, 0, 0]) self.assertEqual(x.packetlength, 13) self.assertEqual(x.packettype, 1) self.assertEqual(x.tranceiver_type, 83) def test_Lighting1(self): x = lowlevel.Lighting1() self.assertIsNone(x.subtype) self.assertIsNone(x.seqnbr) self.assertIsNone(x.id_string) self.assertIsNone(x.cmnd) self.assertIsNone(x.rssi) x.load_receive(bytearray([0x07, 0x10, 0x00, 0x2a, 0x45, 0x05, 0x01, 0x70])) self.assertEqual(x.seqnbr, 42) self.assertEqual(x.id_string,"E5") self.assertEqual(list(x.data), [7, 16, 0, 42, 69, 5, 1, 112]) self.assertEqual(x.packetlength,7) self.assertEqual(x.packettype,16) self.assertEqual(x.subtype,0) self.assertEqual(x.type_string,"X10 lighting") self.assertEqual(x.seqnbr,42) self.assertEqual(x.housecode,69) self.assertEqual(x.unitcode,5) self.assertEqual(x.cmnd,1) self.assertEqual(x.cmnd_string,"On") self.assertEqual(x.rssi_byte,112) self.assertEqual(x.rssi,7) self.assertEqual(x.__str__(),'Lighting1 [subtype=X10 lighting, seqnbr=42, id=E5, cmnd=On, rssi=7]') self.assertTrue(x.has_type_string) x = lowlevel.Lighting1() x.set_transmit(0x00, 0x2a, 0x45, 0x05, 0x01) self.assertEqual(x.seqnbr, 42) self.assertEqual(x.id_string,"E5") self.assertEqual(list(x.data), [7, 16, 0, 42, 69, 5, 1, 0]) self.assertEqual(x.packetlength,7) self.assertEqual(x.packettype,16) self.assertEqual(x.subtype,0) self.assertEqual(x.type_string,"X10 lighting") self.assertEqual(x.seqnbr,42) self.assertEqual(x.housecode,69) self.assertEqual(x.unitcode,5) self.assertEqual(x.cmnd,1) self.assertEqual(x.cmnd_string,"On") self.assertEqual(x.rssi_byte,0) self.assertEqual(x.rssi,0) x.parse_id(0, "E13") self.assertEqual(x.housecode, 69) self.assertEqual(x.unitcode,13) self.assertRaises(ValueError, x.parse_id,0, "Q1") self.assertRaises(ValueError, x.parse_id,0, "AA") def test_Lighting2(self): x = lowlevel.Lighting2() self.assertIsNone(x.subtype) self.assertIsNone(x.seqnbr) self.assertIsNone(x.id_string) self.assertIsNone(x.cmnd) self.assertIsNone(x.rssi) x.load_receive(bytearray([0x0b, 0x11, 0x00, 0x2a, 0x01, 0x23, 0x45, 0x67, 0x05, 0x02, 0x08, 0x70])) self.assertEqual(x.seqnbr, 42) self.assertEqual(x.id_string,"1234567:5") self.assertEqual(list(x.data), [11, 17, 0, 42, 1, 35, 69, 103, 5, 2, 8, 112]) self.assertEqual(x.packetlength,11) self.assertEqual(x.packettype,17) self.assertEqual(x.subtype,0) self.assertEqual(x.type_string,"AC") self.assertEqual(x.seqnbr,42) self.assertEqual(x.unitcode,5) self.assertEqual(x.id1,1) self.assertEqual(x.id2,35) self.assertEqual(x.id3,69) self.assertEqual(x.id4,103) self.assertEqual(x.id_combined,19088743) self.assertEqual(x.cmnd,2) self.assertEqual(x.cmnd_string,"Set level") self.assertEqual(x.rssi_byte,112) self.assertEqual(x.rssi,7) self.assertEqual(x.__str__(),'Lighting2 [subtype=AC, seqnbr=42, id=1234567:5, cmnd=Set level, level=8, rssi=7]') x = lowlevel.Lighting2() x.set_transmit(0x00, 0x2a, 0x1234567, 0x05, 0x02, 0x08) self.assertEqual(x.seqnbr, 42) self.assertEqual(list(x.data), [11, 17, 0, 42, 1, 35, 69, 103, 5, 2, 8, 0]) self.assertEqual(x.packetlength,11) self.assertEqual(x.packettype,17) self.assertEqual(x.subtype,0) self.assertEqual(x.type_string,"AC") self.assertEqual(x.seqnbr,42) self.assertEqual(x.id1,1) self.assertEqual(x.id2,35) self.assertEqual(x.id3,69) self.assertEqual(x.id4,103) self.assertEqual(x.id_combined,19088743) self.assertEqual(x.unitcode,5) self.assertEqual(x.id_string,"1234567:5") self.assertEqual(x.cmnd,2) self.assertEqual(x.cmnd_string,"Set level") self.assertEqual(x.rssi_byte,0) self.assertEqual(x.rssi,0) x = lowlevel.Lighting2() x.parse_id(0, "1234567:5") self.assertEqual(x.id1,1) self.assertEqual(x.id2,35) self.assertEqual(x.id3,69) self.assertEqual(x.id4,103) self.assertEqual(x.id_combined,19088743) self.assertEqual(x.unitcode,5) self.assertRaises(ValueError, x.parse_id,0, "12345678:5") self.assertRaises(ValueError, x.parse_id,0, "123456:54") self.assertRaises(ValueError, x.parse_id,0, "123456785") def test_Lighting3(self): x = lowlevel.Lighting3() self.assertIsNone(x.subtype) self.assertIsNone(x.seqnbr) self.assertIsNone(x.id_string) self.assertIsNone(x.cmnd) self.assertIsNone(x.rssi) x.load_receive(bytearray([0x08, 0x12, 0x00, 0x2a, 0x01, 0x34, 0x02, 0x15, 0x79])) self.assertEqual(list(x.data), [8, 18, 0, 42, 1, 52, 2, 21, 121]) self.assertEqual(x.packetlength,8) self.assertEqual(x.packettype,18) self.assertEqual(x.subtype,0) self.assertEqual(x.type_string,"Ikea Koppla") self.assertEqual(x.seqnbr,42) self.assertEqual(x.system,1) self.assertEqual(x.channel1,52) self.assertEqual(x.channel2,2) self.assertEqual(x.channel,564) self.assertEqual(x.id_string,"1:234") self.assertEqual(x.cmnd,21) self.assertEqual(x.cmnd_string,"Level 5") self.assertEqual(x.rssi_byte,121) self.assertEqual(x.rssi,7) self.assertEqual(x.battery,9) self.assertEqual(x.__str__(),'Lighting3 [subtype=Ikea Koppla, seqnbr=42, id=1:234, cmnd=Level 5, battery=9, rssi=7]') x = lowlevel.Lighting3() x.set_transmit(0x00, 0x2a, 0x1, 0x234, 0x15) self.assertEqual(list(x.data), [8, 18, 0, 42, 1, 52, 2, 21, 0]) self.assertEqual(x.packetlength,8) self.assertEqual(x.packettype,18) self.assertEqual(x.subtype,0) self.assertEqual(x.type_string,"Ikea Koppla") self.assertEqual(x.seqnbr,42) self.assertEqual(x.system,1) self.assertEqual(x.channel1,52) self.assertEqual(x.channel2,2) self.assertEqual(x.channel,564) self.assertEqual(x.id_string,"1:234") self.assertEqual(x.cmnd,21) self.assertEqual(x.cmnd_string,"Level 5") self.assertEqual(x.rssi_byte,0) self.assertEqual(x.rssi,0) self.assertEqual(x.battery,0) x = lowlevel.Lighting3() x.parse_id(0, "1:234") self.assertEqual(x.channel1,52) self.assertEqual(x.channel2,2) self.assertEqual(x.channel,564) self.assertRaises(ValueError, x.parse_id,0, "G:234") self.assertRaises(ValueError, x.parse_id,0, "10234") self.assertRaises(ValueError, x.parse_id,0, "1:23X") class test_Lighting3(unittest.TestCase): def setUp(self): self.data = bytearray(b'\x0A\x14\x00\xAD\xF3\x94\xAB' b'\x01\x01\x00\x60') self.parser = RFXtrx.lowlevel.Lighting5() def test_parse_bytes(self): light = RFXtrx.lowlevel.parse(self.data) self.assertEqual(RFXtrx.lowlevel.Lighting5, type(light)) self.assertEqual(light.type_string,"LightwaveRF, Siemens") self.assertEqual(light.seqnbr,173) self.assertEqual(light.id_string,"f394ab:1") self.assertEqual(light.cmnd_string,"On") self.assertEqual(light.cmnd,1) self.assertEqual(light.level,0) pyRFXtrx-0.32.0/tests/test_rain.py000066400000000000000000000042011500543535500170500ustar00rootroot00000000000000from unittest import TestCase import RFXtrx class RainTestCase(TestCase): def test_rain2(self): data = [0x0B, 0x55, 0x02, 0x17, 0xB6, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x3C, 0x69] packet = RFXtrx.lowlevel.parse(data) self.assertEqual(RFXtrx.lowlevel.Rain, type(packet)) self.assertEqual(packet.type_string,'PCR800') self.assertEqual(packet.id_string,'b6:00') self.assertAlmostEqual(packet.rainrate, 0) self.assertAlmostEqual(packet.raintotal, 1977.2) self.assertEqual(packet.battery, 9) self.assertEqual(packet.rssi, 6) def test_rain6(self): data = [0x0B, 0x55, 0x06, 0x03, 0x3E, 0xBB, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x69] packet = RFXtrx.lowlevel.parse(data) self.assertEqual(RFXtrx.lowlevel.Rain, type(packet)) self.assertEqual(packet.type_string,'La Crosse TX5') self.assertEqual(packet.id_string,'3e:bb') self.assertAlmostEqual(packet.rainrate, None) self.assertAlmostEqual(packet.raintotal, 33.782) self.assertEqual(packet.battery, 9) self.assertEqual(packet.rssi, 6) def test_rain8(self): data = [0x0B, 0x55, 0x08, 0x03, 0x3E, 0xBB, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x69] packet = RFXtrx.lowlevel.parse(data) self.assertEqual(RFXtrx.lowlevel.Rain, type(packet)) self.assertEqual(packet.type_string,'Davis') self.assertEqual(packet.id_string,'3e:bb') self.assertAlmostEqual(packet.rainrate, None) self.assertAlmostEqual(packet.raintotal, 25.400) self.assertEqual(packet.battery, 9) self.assertEqual(packet.rssi, 6) def test_rain9(self): data = [0x0B, 0x55, 0x09, 0x03, 0x3E, 0xBB, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x69] packet = RFXtrx.lowlevel.parse(data) self.assertEqual(RFXtrx.lowlevel.Rain, type(packet)) self.assertEqual(packet.type_string,'TFA 30.3233.01') self.assertEqual(packet.id_string,'3e:bb') self.assertAlmostEqual(packet.rainrate, None) self.assertAlmostEqual(packet.raintotal, 32.258) self.assertEqual(packet.battery, 9) self.assertEqual(packet.rssi, 6) pyRFXtrx-0.32.0/tests/test_rfxmeter.py000066400000000000000000000033241500543535500177600ustar00rootroot00000000000000from unittest import TestCase import RFXtrx class RfxMeterTestCase(TestCase): def setUp(self): #A 71 0 1F 21 D1 0 20 1F A4 60 self.data = bytearray(b'\x0A\x71\x00\x1F\x21\xD1\x00\x20' b'\x1F\xA4\x60') self.parser = RFXtrx.lowlevel.RfxMeter() def test_parse_bytes(self): rfxmeterpacket = RFXtrx.lowlevel.parse(self.data) self.assertEqual(RFXtrx.lowlevel.RfxMeter, type(rfxmeterpacket)) self.assertEqual(rfxmeterpacket.type_string, 'RFXMeter Count') self.assertEqual(rfxmeterpacket.id_string, '21') self.assertEqual(rfxmeterpacket.value3, 0x20) self.assertEqual(rfxmeterpacket.value2, 0x1F) self.assertEqual(rfxmeterpacket.value1, 0xA4) self.assertEqual(rfxmeterpacket.value, 2105252) def test_validate_bytes_short(self): data = self.data[:1] rfxmeterpacket = RFXtrx.lowlevel.parse(data) self.assertEqual(rfxmeterpacket, None) def test_validate_unkown_packet_type(self): self.data[1] = 0xFF rfxmeterpacket = RFXtrx.lowlevel.parse(self.data) self.assertEqual(rfxmeterpacket, None) def test_validate_unknown_sub_type(self): self.data[2] = 0xEE rfxmeterpacket = RFXtrx.lowlevel.parse(self.data) self.assertEqual(rfxmeterpacket.type_string, 'Unknown type (0x71/0xee)') def test_equal(self): rfxmeterpacket = RFXtrx.lowlevel.parse(self.data) self.data = bytearray(b'\x0A\x71\x00\x1F\x21\xD1\x00\x20' b'\x1F\xA4\x60') rfxmeterpacket2 = RFXtrx.lowlevel.parse(self.data) self.assertTrue(rfxmeterpacket == rfxmeterpacket2) self.assertFalse(rfxmeterpacket == None) pyRFXtrx-0.32.0/tests/test_rfy.py000066400000000000000000000062211500543535500167230ustar00rootroot00000000000000from unittest import TestCase import RFXtrx class RfyTestCase(TestCase): def test_parse_bytes_legacy_format(self): ### Tests with legacy formats used by home assistant. rfy = RFXtrx.lowlevel.parse(bytearray(b'\x08\x1A\x00\x00\x0A\x00\x01\x01\x03')) self.assertEqual(rfy.__repr__(), "Rfy [subtype=0, seqnbr=0, id=0a0001:1, cmnd=Down, rssi=None]") self.assertEqual(rfy.packetlength, 8) self.assertEqual(rfy.subtype, 0) self.assertEqual(rfy.type_string, "Rfy") self.assertEqual(rfy.seqnbr, 0) self.assertEqual(rfy.id_string, "0a0001:1") self.assertEqual(rfy.cmnd, 3) self.assertEqual(rfy.cmnd_string, "Down") rfy = RFXtrx.lowlevel.parse(bytearray(b'\x07\x1A\x00\x00\x0A\x00\x01\x01')) self.assertEqual(rfy.__repr__(), "Rfy [subtype=0, seqnbr=0, id=0a0001:1, cmnd=None, rssi=None]") self.assertEqual(rfy.packetlength, 7) self.assertEqual(rfy.subtype, 0) self.assertEqual(rfy.type_string, "Rfy") self.assertEqual(rfy.seqnbr, 0) self.assertEqual(rfy.id_string, "0a0001:1") def test_parse_bytes(self): rfy = RFXtrx.lowlevel.parse(bytearray(b'\x0C\x1A\x00\x00\x0A\x00\x01\x01\x03\x00\x00\x00\x30')) self.assertEqual(rfy.__repr__(), "Rfy [subtype=0, seqnbr=0, id=0a0001:1, cmnd=Down, rssi=3]") self.assertEqual(rfy.packetlength, 12) self.assertEqual(rfy.subtype, 0) self.assertEqual(rfy.type_string, "Rfy") self.assertEqual(rfy.seqnbr, 0) self.assertEqual(rfy.id_string, "0a0001:1") self.assertEqual(rfy.cmnd, 3) self.assertEqual(rfy.cmnd_string, "Down") rfy = RFXtrx.lowlevel.Rfy() rfy.set_transmit(0, 0, 0x0a0001, 1, 3) self.assertEqual(rfy.__repr__(), "Rfy [subtype=0, seqnbr=0, id=0a0001:1, cmnd=Down, rssi=0]") self.assertEqual(rfy.packetlength, 12) self.assertEqual(rfy.subtype, 0) self.assertEqual(rfy.type_string, "Rfy") self.assertEqual(rfy.seqnbr, 0) self.assertEqual(rfy.id_string, "0a0001:1") self.assertEqual(rfy.cmnd, 3) self.assertEqual(rfy.cmnd_string, "Down") rfy = RFXtrx.lowlevel.Rfy() rfy.parse_id(0, "0a0001:2") self.assertEqual(rfy.unitcode, 2) self.assertRaises(ValueError, rfy.parse_id, 0, "AA") rfy = RFXtrx.get_device(0x1A, 0, "0a0001:1") self.assertEqual(rfy.__str__(), " type='Rfy' id='0a0001:1'") self.assertEqual(rfy.unitcode, 1) rfy = RFXtrx.lowlevel.parse(bytearray(b'\x0C\x1A\x01\x00\x0A\x00\x01\x01\x05\x00\x00\x00\x30')) self.assertEqual(rfy.cmnd_string, "Unknown command (0x05)") self.assertEqual(rfy.type_string, "Rfy Extended") rfy = RFXtrx.lowlevel.parse(bytearray(b'\x0C\x1A\x02\x00\x0A\x00\x01\x01\x05\x00\x00\x00\x30')) self.assertEqual(rfy.cmnd_string, "Unknown command (0x05)") self.assertEqual(rfy.type_string, "Unknown type (0x1a/0x02)") rfy = RFXtrx.get_device(0x1A,3,'0a0001:2') self.assertEqual(rfy.subtype, 3) self.assertEqual(rfy.__str__(), " type='ASA' id='0a0001:2'") pyRFXtrx-0.32.0/tests/test_rollertrol.py000066400000000000000000000046001500543535500203220ustar00rootroot00000000000000from unittest import TestCase import RFXtrx class RollerTrolTestCase(TestCase): def test_parse_bytes(self): rollertrol = RFXtrx.lowlevel.parse(bytearray(b'\x09\x19\x00\x00\x00\x9b\xa8\x01\x01\x00')) self.assertEqual(rollertrol.__repr__(), "RollerTrol [subtype=0, seqnbr=0, id=009ba8:1, cmnd=Down, rssi=0]") self.assertEqual(rollertrol.packetlength, 9) self.assertEqual(rollertrol.subtype, 0) self.assertEqual(rollertrol.type_string, "RollerTrol") self.assertEqual(rollertrol.seqnbr, 0) self.assertEqual(rollertrol.id_string, "009ba8:1") self.assertEqual(rollertrol.cmnd, 1) self.assertEqual(rollertrol.cmnd_string, "Down") self.assertEqual(rollertrol.rssi_byte, 0) self.assertEqual(rollertrol.rssi, 0) rollertrol = RFXtrx.lowlevel.RollerTrol() rollertrol.set_transmit(0, 0, 0x009ba8, 1, 1) self.assertEqual(rollertrol.__repr__(), "RollerTrol [subtype=0, seqnbr=0, id=009ba8:1, cmnd=Down, rssi=0]") self.assertEqual(rollertrol.packetlength, 9) self.assertEqual(rollertrol.subtype, 0) self.assertEqual(rollertrol.type_string, "RollerTrol") self.assertEqual(rollertrol.seqnbr, 0) self.assertEqual(rollertrol.id_string, "009ba8:1") self.assertEqual(rollertrol.cmnd, 1) self.assertEqual(rollertrol.cmnd_string, "Down") self.assertEqual(rollertrol.rssi_byte, 0) self.assertEqual(rollertrol.rssi, 0) rollertrol = RFXtrx.lowlevel.RollerTrol() rollertrol.parse_id(0, "009ba8:2") self.assertEqual(rollertrol.unitcode, 2) self.assertRaises(ValueError, rollertrol.parse_id, 0, "AA") rollertrol = RFXtrx.get_device(0x19, 0, "009ba8:1") self.assertEqual(rollertrol.__str__(), " type='RollerTrol' id='009ba8:1'") self.assertEqual(rollertrol.unitcode, 1) rollertrol = RFXtrx.lowlevel.parse(bytearray(b'\x09\x19\x02\x00\x00\x9b\xa8\x01\x05\x00')) self.assertEqual(rollertrol.cmnd_string, "Unknown command (0x05)") self.assertEqual(rollertrol.type_string, "BlindsT2 / A-OK RF01") rollertrol = RFXtrx.lowlevel.parse(bytearray(b'\x09\x19\xff\x00\x00\x9b\xa8\x01\x05\x00')) self.assertEqual(rollertrol.cmnd_string, "Unknown command (0x05)") self.assertEqual(rollertrol.type_string, "Unknown type (0x19/0xff)") pyRFXtrx-0.32.0/tests/test_security.py000066400000000000000000000036501500543535500177750ustar00rootroot00000000000000from unittest import TestCase import RFXtrx class SecurityTestCase(TestCase): def test_parse(self): data = [0x08, 0x20, 0x00, 0x4D, 0xD3, 0xDC, 0x54, 0x00, 0x89] packet = RFXtrx.lowlevel.parse(data) self.assertEqual(RFXtrx.lowlevel.Security1, type(packet)) self.assertEqual(packet.packetlength, 8) self.assertEqual(packet.packettype, 32) self.assertEqual(packet.subtype, 0) self.assertEqual(packet.seqnbr, 77) self.assertEqual(packet.type_string, 'X10 Security') self.assertEqual(packet.id_string, 'd3dc54:32') self.assertEqual(packet.battery, 9) self.assertEqual(packet.rssi, 8) self.assertEqual(packet.security1_status, 0) self.assertEqual(packet.security1_status_string, 'Normal') def test_set_transmit(self): packet = RFXtrx.lowlevel.Security1() packet.set_transmit(0x00, 77, 13884500, 0x00) self.assertEqual(packet.packetlength, 8) self.assertEqual(packet.packettype, 32) self.assertEqual(packet.subtype, 0) self.assertEqual(packet.seqnbr, 77) self.assertEqual(packet.type_string, 'X10 Security') self.assertEqual(packet.id_string, 'd3dc54:32') self.assertEqual(packet.battery, 0) self.assertEqual(packet.rssi, 0) self.assertEqual(packet.security1_status, 0) self.assertEqual(packet.security1_status_string, 'Normal') def test_parse_id(self): packet = RFXtrx.lowlevel.Security1() packet.parse_id(0, "d3dc54:32") self.assertEqual(packet.id1, 211) self.assertEqual(packet.id2, 220) self.assertEqual(packet.id3, 84) self.assertRaisesRegex(ValueError, "Invalid id_string", packet.parse_id, 0, "G:234") self.assertRaisesRegex(ValueError, "Invalid id_string", packet.parse_id, 0, "10234") self.assertRaisesRegex(ValueError, "Invalid id_string", packet.parse_id, 0, "1:23X") pyRFXtrx-0.32.0/tests/test_status.py000066400000000000000000000021021500543535500174400ustar00rootroot00000000000000from unittest import TestCase import RFXtrx class StatusTestCase(TestCase): def setUp(self): self.data = bytearray(b'\x0D\x01\x00\x01\x02\x53\x45\x00\x0C' b'\x2F\x01\x01\x00\x00') self.parser = RFXtrx.lowlevel.Status() def test_parse_bytes(self): status = RFXtrx.lowlevel.parse(self.data) self.assertEqual(RFXtrx.lowlevel.Status, type(status)) self.assertEqual(status.devices, ['ac', 'arc', 'hideki', 'homeeasy', 'keeloq', 'lacrosse', 'oregon', 'x10']) self.assertEqual(status.type_string,'433.92MHz') self.assertEqual(status.firmware_version,69) self.assertEqual(status.output_power,0) self.assertTrue(status.has_value('devices')) def test_validate_bytes_short(self): data = self.data[:1] status = RFXtrx.lowlevel.parse(data) self.assertEqual(status, None) def test_validate_unkown_packet_type(self): self.data[1] = 0xFF status = RFXtrx.lowlevel.parse(self.data) self.assertEqual(status, None) pyRFXtrx-0.32.0/tests/test_temphum.py000066400000000000000000000034321500543535500176030ustar00rootroot00000000000000from unittest import TestCase import RFXtrx class TempHumidityTestCase(TestCase): def setUp(self): self.data = bytearray(b'\x0A\x52\x02\x11\x70\x02\x00\xA7' b'\x2D\x00\x89') self.parser = RFXtrx.lowlevel.TempHumid() def test_parse_bytes(self): temphum = RFXtrx.lowlevel.parse(self.data) self.assertEqual(RFXtrx.lowlevel.TempHumid, type(temphum)) self.assertEqual(temphum.temp,16.7) self.assertEqual(temphum.humidity,45) self.assertEqual(temphum.type_string,'THGR810, THGN800') self.assertEqual(temphum.id_string,'70:02') def test_negative_temp(self): self.data = bytearray(b'\x0A\x52\x02\x11\x70\x02\x80\xA7' b'\x2D\x00\x89') temphum = RFXtrx.lowlevel.parse(self.data) self.assertEqual(RFXtrx.lowlevel.TempHumid, type(temphum)) self.assertEqual(temphum.temp,-16.7) def test_validate_bytes_short(self): data = self.data[:1] temphum = RFXtrx.lowlevel.parse(data) self.assertEqual(temphum, None) def test_validate_unkown_packet_type(self): self.data[1] = 0xFF temphum = RFXtrx.lowlevel.parse(self.data) self.assertEqual(temphum, None) def test_validate_unknown_sub_type(self): self.data[2] = 0xEE temphum = RFXtrx.lowlevel.parse(self.data) self.assertEqual(temphum.type_string,'Unknown type (0x52/0xee)') def test_equal(self): temphum = RFXtrx.lowlevel.parse(self.data) self.data = bytearray(b'\x0A\x52\x02\x11\x70\x02\x80\xA7' b'\x2D\x00\x89') temphum2 = RFXtrx.lowlevel.parse(self.data) self.assertTrue(temphum==temphum2) self.assertFalse(temphum==None)pyRFXtrx-0.32.0/tests/test_temprain.py000066400000000000000000000017401500543535500177430ustar00rootroot00000000000000from unittest import TestCase import RFXtrx class TempRainTestCase(TestCase): def test_parse_bytes(self): data = [0x0a, 0x4f, 0x01, 0x06, 0xee, 0x09, 0x00, 0x65, 0x00, 0x03, 0x69] temprain = RFXtrx.lowlevel.parse(data) self.assertEqual(RFXtrx.lowlevel.TempRain, type(temprain)) self.assertEqual(temprain.temp, 10.1) self.assertEqual(temprain.raintotal, 0.3) self.assertEqual(temprain.type_string,'TR1 - WS1200') self.assertEqual(temprain.id_string,'ee:09') def test_parse_bytes_negative_temp(self): data = [0x0a, 0x4f, 0x01, 0x05, 0xef, 0x09, 0x80, 0x50, 0x01, 0x06, 0x79] temprain = RFXtrx.lowlevel.parse(data) self.assertEqual(RFXtrx.lowlevel.TempRain, type(temprain)) self.assertEqual(temprain.temp, -8.0) self.assertEqual(temprain.raintotal, 26.2) self.assertEqual(temprain.type_string,'TR1 - WS1200') self.assertEqual(temprain.id_string,'ef:09')pyRFXtrx-0.32.0/tests/test_transport_network.py000066400000000000000000000052511500543535500217320ustar00rootroot00000000000000 import pytest import RFXtrx import socket import dataclasses import threading from typing import Tuple, List @pytest.fixture(name="server_socket") def fixture_server_socket(): sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(('127.0.0.1', 0)) sock.settimeout(1) sock.listen(1) try: yield sock finally: sock.close() @dataclasses.dataclass class Server: address: Tuple connections: List[socket.socket] event = threading.Event() @pytest.fixture(name="server") def fixture_server(server_socket: socket.socket): server = Server(address=server_socket.getsockname(), connections=[]) def runner(): while True: try: connection, address = server_socket.accept() server.connections.append(connection) server.event.set() except socket.timeout: continue except socket.error: return thread = threading.Thread(target=runner, daemon=True) thread.start() try: yield server finally: server_socket.close() for connection in server.connections: connection.close() thread.join() def connected_transport(server: Server): server.event.clear() transport = RFXtrx.PyNetworkTransport(server.address) transport.sock.settimeout(10) transport.connect() assert server.event.wait(10) return transport, server.connections[-1] def test_transport_shutdown_between_packet(server: Server): transport, connection = connected_transport(server) connection.sendall(bytes([0x09, 0x03, 0x01, 0x04, 0x28, 0x0a, 0xb7, 0x66, 0x04, 0x70])) connection.shutdown(socket.SHUT_RDWR) pkt = transport.receive_blocking() assert isinstance(pkt, RFXtrx.SensorEvent) with pytest.raises(RFXtrx.RFXtrxTransportError): transport.receive_blocking() def test_transport_shutdown_mid_packet(server: Server): transport, connection = connected_transport(server) connection.sendall(bytes([0x09, 0x03, 0x01, 0x04])) connection.shutdown(socket.SHUT_RDWR) with pytest.raises(RFXtrx.RFXtrxTransportError): transport.receive_blocking() def test_transport_close_mid_packet(server: Server): transport, connection = connected_transport(server) connection.sendall(bytes([0x09, 0x03, 0x01, 0x04])) connection.close() with pytest.raises(RFXtrx.RFXtrxTransportError): transport.receive_blocking() def test_transport_empty_packet(server: Server): transport, connection = connected_transport(server) connection.sendall(bytes([0x00])) assert transport.receive_blocking() is None pyRFXtrx-0.32.0/tests/test_undecoded.py000066400000000000000000000012211500543535500200500ustar00rootroot00000000000000from unittest import TestCase import RFXtrx class UndecodedTestCase(TestCase): def setUp(self): self.parser = RFXtrx.lowlevel.Undecoded() def test_parse_bytes(self): self.data = bytearray([0x09, 0x03, 0x01, 0x04, 0x28, 0x0a, 0xb7, 0x66, 0x04, 0x70]) undecoded = RFXtrx.lowlevel.parse(self.data) self.assertEqual(RFXtrx.lowlevel.Undecoded, type(undecoded)) self.assertEqual(undecoded.subtype, 0x01) self.assertEqual(undecoded.type_string, 'arc') self.assertEqual(undecoded.payload, bytearray([0x28, 0x0a, 0xb7, 0x66, 0x04, 0x70])) self.assertEqual(undecoded.id_string,'Undecoded') pyRFXtrx-0.32.0/tests/test_wind.py000066400000000000000000000026651500543535500170740ustar00rootroot00000000000000from unittest import TestCase import RFXtrx class WindTestCase(TestCase): def test_parse_bytes_5(self): data = [0x10, 0x56, 0x07, 0x05, 0x2c, 0x01, 0x00, 0x87, 0x00, 0x04, 0x00, 0x08, 0x68, 0x74, 0x20, 0x52, 0x69] packet = RFXtrx.lowlevel.parse(data) self.assertEqual(RFXtrx.lowlevel.Wind, type(packet)) self.assertEqual(packet.type_string,'Alecto WS4500') self.assertEqual(packet.id_string,'2c:01') self.assertEqual(packet.direction, 135) self.assertEqual(packet.average_speed, 0.4) self.assertEqual(packet.gust, 0.8) self.assertEqual(packet.temperature, None) self.assertEqual(packet.chill, None) self.assertEqual(packet.battery, 9) self.assertEqual(packet.rssi, 6) def test_parse_bytes_6(self): data = [0x10, 0x56, 0x06, 0x8f, 0x4c, 0x00, 0x00, 0x43, 0x00, 0x00, 0x00, 0xf0, 0x68, 0x74, 0x20, 0x52, 0x69] packet = RFXtrx.lowlevel.parse(data) self.assertEqual(RFXtrx.lowlevel.Wind, type(packet)) self.assertEqual(packet.type_string,'WS2300') self.assertEqual(packet.id_string,'4c:00') self.assertEqual(packet.direction, 67) self.assertEqual(packet.average_speed, 0.0) self.assertEqual(packet.gust, 24.0) self.assertEqual(packet.temperature, None) self.assertEqual(packet.chill, None) self.assertEqual(packet.battery, 9) self.assertEqual(packet.rssi, 6) pyRFXtrx-0.32.0/tox.ini000066400000000000000000000011111500543535500146540ustar00rootroot00000000000000[tox] envlist = py39, py310, py310, py312, py313, lint skip_missing_interpreters = True [gh-actions] python = 3.9: py39 3.10: py310 3.11: py311 3.12: py312 3.13: py313, lint [testenv] setenv = LANG=en_US.UTF-8 PYTHONPATH = {toxinidir}:{toxinidir}/RFXtrx commands = py.test -v --timeout=30 --cov --cov-report= {posargs} py.test --doctest-modules doctest/ deps = -r{toxinidir}/requirements.txt -r{toxinidir}/requirements_test.txt [testenv:lint] basepython = python3 ignore_errors = True commands = flake8 RFXtrx pylint RFXtrx