├── .gitignore
├── LICENSE
├── README.md
├── doc
├── pyvcontrol.class.jet
├── pyvcontrol.class.png
├── pyvcontrol.usecase.jet
├── pyvcontrol.usecase.png
├── pyvcontrol_main.sequence.jet
├── pyvcontrol_main.sequence.png
├── pyvcontrol_read.sequence.jet
├── pyvcontrol_read.sequence.png
├── pyvcontrol_write.sequence.jet
└── pyvcontrol_write.sequence.png
├── pyvcontrol
├── __init__.py
├── viCommand.py
├── viControl.py
├── viData.py
├── viTelegram.py
└── viTools.py
├── setup.py
└── tests
├── __init__.py
├── testViCommand.py
├── testViControl.py
├── testViData.py
├── testViTelegram.py
├── testViTools.py
├── testViessmann.py
└── viControlMock.py
/.gitignore:
--------------------------------------------------------------------------------
1 | /deploy_pi
2 | /tests/Monitor.log
3 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Communication with Viessmann heating via Optolink interface
2 |
3 |
4 | 
5 |
6 | Python package to communicate with Viessmann heatings via the optolink serial interface.
7 | Replacement for vcontrold when using a python environment.
8 |
9 | Python package zur Kommunikation mit Viessmann-Heizungen über die Optolink serielle Schnittstelle.
10 | Geeignet um vcontrold zu ersetzen wenn ohnehin mit Python gearbeitet wird.
11 |
12 | Neuentwicklung basierend auf
13 | - [SmartHomeNG plugin (Python)][SHNGpyPlugin]
14 | - [vcontrold][vcontrold]
15 |
16 | Motivation:
17 | - Python-Modul um direkt auf die Viessmann-Heizung zugreifen zu können (ohne Umweg über vcontrold)
18 |
19 | Einschränkungen/known issues:
20 | - Die Parameter (z.B. Kommandodefinitionen) sind Teil der Klassen und nicht mehr zentral abgelegt.
21 | Nachteil ist die geringere Anwenderfreundlichkeit - Konfigurationen sollten eigentlich vom Code getrennt sein
22 | - nur V200WO1C/P300 implementiert.
23 |
24 | Beispielcode:
25 | - testViessmann.py: führt einen Lesezugriff für alle definierten Kommandos durch.
26 |
27 | [vcontrold]: https://github.com/openv (vcontrold)
28 | [SHNGpyPlugin]: https://github.com/sisamiwe/myplugins/tree/master/viessmann (SmartHomeNG python Plugin)
29 | [packaging guide]: https://packaging.python.org
30 | [distribution tutorial]: https://packaging.python.org/tutorials/packaging-projects/
31 | [src]: https://github.com/
32 | [rst]: http://docutils.sourceforge.net/rst.html
33 | [md]: https://tools.ietf.org/html/rfc7764#section-3.5 "CommonMark variant"
34 | [md use]: https://packaging.python.org/specifications/core-metadata/#description-content-type-optional
35 |
--------------------------------------------------------------------------------
/doc/pyvcontrol.class.jet:
--------------------------------------------------------------------------------
1 | {"diagram":"ClassDiagram","nodes":[{"methods":"","x":110,"name":"viTelegramException","y":360,"attributes":"","id":2,"type":"ClassNode"},{"contents":"","children":[15,16,17],"x":60,"name":"viControl.py","y":90,"id":14,"type":"PackageNode"},{"methods":"connect\ndisconnect\nsend(packet)\nread(length)","x":100,"name":"viSerial","y":180,"attributes":"","id":16,"type":"ClassNode"},{"contents":"","children":[1,4,7,14],"x":690,"name":"pyvcontrol","y":140,"id":0,"type":"PackageNode"},{"contents":"","children":[2,3],"x":100,"name":"viTelegram.py","y":330,"id":1,"type":"PackageNode"},{"methods":"","x":340,"name":"viCommandException","y":370,"attributes":"","id":5,"type":"ClassNode"},{"methods":"__init__(cmdname)\nfrombytes(b)\n__responselen__(mode)\n","x":340,"name":"viCommand","y":480,"attributes":"commandset: Dictionary\n...","id":6,"type":"ClassNode"},{"methods":"","x":630,"name":"viDataException","y":80,"attributes":"","id":8,"type":"ClassNode"},{"methods":"","x":810,"name":"...","y":340,"attributes":"","id":13,"type":"ClassNode"},{"methods":"InitComm()\nexecReadCmd(cmdname) -> viData\nexecWriteCmd(cmdname,value) -> viData","x":330,"name":"viControl","y":130,"attributes":"isInitialized","id":17,"type":"ClassNode"},{"methods":"frombytes(b)\n","x":120,"name":"viTelegram","y":480,"attributes":"__responselen__: int\nTelegramMode\nTelegramType","id":3,"type":"ClassNode"},{"methods":"","x":810,"name":"viDataDT","y":260,"attributes":"unit\ndevicetypes","id":11,"type":"ClassNode"},{"methods":"","x":100,"name":"viControlException","y":90,"attributes":"","id":15,"type":"ClassNode"},{"methods":"","x":810,"name":"viDataBA","y":110,"attributes":"unit\noperatingmodes","id":10,"type":"ClassNode"},{"methods":"__init__\n__fromraw__\n__fromtype__\ncreate","x":630,"name":"viData","y":190,"attributes":"unitset\nvalue","id":9,"type":"ClassNode"},{"methods":"","x":810,"name":"viDataES","y":190,"attributes":"unit\nerrorset","id":12,"type":"ClassNode"},{"contents":"","children":[5,6],"x":320,"name":"viCommand.py","y":330,"id":4,"type":"PackageNode"},{"contents":"","children":[8,9,10,11,12,13],"x":620,"name":"viData.py","y":50,"id":7,"type":"PackageNode"}],"edges":[{"Generalization Type":"Inheritance","startLabel":"","middleLabel":"","start":10,"end":9,"endLabel":"","type":"GeneralizationEdge"},{"startLabel":"","middleLabel":"","start":17,"end":16,"endLabel":"","type":"AggregationEdge","Aggregation Type":"Composition"},{"startLabel":"","middleLabel":"","start":17,"end":15,"endLabel":"","type":"AggregationEdge","Aggregation Type":"Composition"},{"startLabel":"","middleLabel":"","start":17,"end":3,"endLabel":"","type":"AggregationEdge","Aggregation Type":"Composition"},{"startLabel":"","middleLabel":"","start":17,"end":9,"endLabel":"","type":"AggregationEdge","Aggregation Type":"Aggregation"},{"startLabel":"","middleLabel":"","start":6,"end":5,"endLabel":"","type":"AggregationEdge","Aggregation Type":"Composition"},{"startLabel":"","middleLabel":"","start":3,"end":2,"endLabel":"","type":"AggregationEdge","Aggregation Type":"Composition"},{"startLabel":"","middleLabel":"","start":9,"end":8,"endLabel":"","type":"AggregationEdge","Aggregation Type":"Composition"},{"Generalization Type":"Inheritance","startLabel":"","middleLabel":"","start":12,"end":9,"endLabel":"","type":"GeneralizationEdge"},{"Generalization Type":"Inheritance","startLabel":"","middleLabel":"","start":11,"end":9,"endLabel":"","type":"GeneralizationEdge"},{"Generalization Type":"Inheritance","startLabel":"","middleLabel":"","start":13,"end":9,"endLabel":"","type":"GeneralizationEdge"},{"startLabel":"","middleLabel":"","start":3,"end":6,"endLabel":"","type":"AggregationEdge","Aggregation Type":"Composition"}],"version":"2.6"}
2 |
--------------------------------------------------------------------------------
/doc/pyvcontrol.class.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joppi588/pyvcontrol/06c5c473bcc69c7c943744d953404e354d2de44e/doc/pyvcontrol.class.png
--------------------------------------------------------------------------------
/doc/pyvcontrol.usecase.jet:
--------------------------------------------------------------------------------
1 | {"diagram":"UseCaseDiagram","nodes":[{"x":540,"name":"Read Data","y":170,"id":0,"type":"UseCaseNode"},{"x":270,"name":"The use cases are very simple: Read data from the Viessmann heating or write a value","y":330,"id":3,"type":"NoteNode"},{"x":550,"name":"Write Data","y":250,"id":2,"type":"UseCaseNode"},{"x":340,"name":"Actor","y":190,"id":1,"type":"ActorNode"}],"edges":[{"start":1,"end":0,"type":"UseCaseAssociationEdge"},{"start":1,"end":2,"type":"UseCaseAssociationEdge"}],"version":"2.6"}
2 |
--------------------------------------------------------------------------------
/doc/pyvcontrol.usecase.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joppi588/pyvcontrol/06c5c473bcc69c7c943744d953404e354d2de44e/doc/pyvcontrol.usecase.png
--------------------------------------------------------------------------------
/doc/pyvcontrol_main.sequence.jet:
--------------------------------------------------------------------------------
1 | {"diagram":"SequenceDiagram","nodes":[{"x":0,"y":0,"openBottom":false,"id":10,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":11,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":8,"type":"CallNode"},{"children":[1],"x":80,"name":"main","y":20,"id":0,"type":"ImplicitParameterNode"},{"children":[3,4,5],"x":330,"name":":viControl","y":20,"id":2,"type":"ImplicitParameterNode"},{"x":0,"y":0,"openBottom":false,"id":7,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":4,"type":"CallNode"},{"children":[7,8,9,10,11],"x":710,"name":"viSerial","y":50,"id":6,"type":"ImplicitParameterNode"},{"x":0,"y":0,"openBottom":false,"id":9,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":5,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":1,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":3,"type":"CallNode"}],"edges":[{"middleLabel":"«create»","start":1,"end":3,"type":"ConstructorEdge","signal":false},{"middleLabel":"initComm","start":1,"end":4,"type":"CallEdge","signal":false},{"middleLabel":"","start":4,"end":1,"type":"ReturnEdge"},{"middleLabel":"«create»","start":3,"end":7,"type":"ConstructorEdge","signal":false},{"middleLabel":"connect","start":3,"end":8,"type":"CallEdge","signal":false},{"middleLabel":"read or write Command","start":1,"end":5,"type":"CallEdge","signal":false},{"middleLabel":"","start":5,"end":1,"type":"ReturnEdge"},{"middleLabel":"send reset","start":4,"end":9,"type":"CallEdge","signal":false},{"middleLabel":"","start":9,"end":4,"type":"ReturnEdge"},{"middleLabel":"send sync command","start":4,"end":10,"type":"CallEdge","signal":false},{"middleLabel":"","start":10,"end":4,"type":"ReturnEdge"},{"middleLabel":"","start":4,"end":11,"type":"CallEdge","signal":false},{"middleLabel":"read response (err/ack/not initialised)","start":11,"end":4,"type":"ReturnEdge"}],"version":"2.6"}
2 |
--------------------------------------------------------------------------------
/doc/pyvcontrol_main.sequence.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joppi588/pyvcontrol/06c5c473bcc69c7c943744d953404e354d2de44e/doc/pyvcontrol_main.sequence.png
--------------------------------------------------------------------------------
/doc/pyvcontrol_read.sequence.jet:
--------------------------------------------------------------------------------
1 | {"diagram":"SequenceDiagram","nodes":[{"x":0,"y":0,"openBottom":false,"id":16,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":5,"type":"CallNode"},{"children":[1],"x":210,"name":":viControl","y":420,"id":0,"type":"ImplicitParameterNode"},{"children":[10],"x":350,"name":":viCommand","y":110,"id":9,"type":"ImplicitParameterNode"},{"x":0,"y":0,"openBottom":false,"id":7,"type":"CallNode"},{"x":-10,"y":0,"openBottom":false,"id":1,"type":"CallNode"},{"x":-160,"y":0,"openBottom":false,"id":12,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":10,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":6,"type":"CallNode"},{"children":[3],"x":80,"name":"main","y":20,"id":2,"type":"ImplicitParameterNode"},{"children":[14],"x":680,"name":":viTelegram (response)","y":250,"id":13,"type":"ImplicitParameterNode"},{"children":[5,6,7,8],"x":820,"name":"viSerial","y":250,"id":4,"type":"ImplicitParameterNode"},{"x":0,"y":0,"openBottom":false,"id":14,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":3,"type":"CallNode"},{"children":[16],"x":540,"name":":viTelegram (request)","y":70,"id":15,"type":"ImplicitParameterNode"},{"x":0,"y":0,"openBottom":false,"id":8,"type":"CallNode"},{"children":[12],"x":450,"name":"viData","y":-760,"id":11,"type":"ImplicitParameterNode"}],"edges":[{"middleLabel":"Read","start":3,"end":1,"type":"CallEdge","signal":false},{"middleLabel":"«create»","start":1,"end":10,"type":"ConstructorEdge","signal":false},{"middleLabel":"«create»","start":1,"end":16,"type":"ConstructorEdge","signal":false},{"middleLabel":"send read telegram","start":1,"end":5,"type":"CallEdge","signal":false},{"middleLabel":"read acknowledge","start":1,"end":8,"type":"CallEdge","signal":false},{"middleLabel":"read raw response","start":1,"end":6,"type":"CallEdge","signal":false},{"middleLabel":"send acknowledge","start":1,"end":7,"type":"CallEdge","signal":false},{"middleLabel":"«create»","start":1,"end":14,"type":"ConstructorEdge","signal":false},{"middleLabel":"«create»","start":1,"end":12,"type":"ConstructorEdge","signal":false},{"middleLabel":"","start":12,"end":1,"type":"ReturnEdge"},{"middleLabel":"","start":6,"end":1,"type":"ReturnEdge"},{"middleLabel":"","start":8,"end":1,"type":"ReturnEdge"},{"middleLabel":"","start":16,"end":1,"type":"ReturnEdge"},{"middleLabel":"","start":10,"end":1,"type":"ReturnEdge"},{"middleLabel":"return viData","start":1,"end":3,"type":"ReturnEdge"},{"middleLabel":"","start":14,"end":1,"type":"ReturnEdge"}],"version":"2.6"}
2 |
--------------------------------------------------------------------------------
/doc/pyvcontrol_read.sequence.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joppi588/pyvcontrol/06c5c473bcc69c7c943744d953404e354d2de44e/doc/pyvcontrol_read.sequence.png
--------------------------------------------------------------------------------
/doc/pyvcontrol_write.sequence.jet:
--------------------------------------------------------------------------------
1 | {"diagram":"SequenceDiagram","nodes":[{"children":[1],"x":210,"name":":viControl","y":420,"id":0,"type":"ImplicitParameterNode"},{"children":[3],"x":80,"name":"main","y":20,"id":2,"type":"ImplicitParameterNode"},{"children":[9],"x":640,"name":":viTelegram (request)","y":40,"id":8,"type":"ImplicitParameterNode"},{"children":[5],"x":350,"name":":viCommand","y":110,"id":4,"type":"ImplicitParameterNode"},{"x":0,"y":0,"openBottom":false,"id":7,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":9,"type":"CallNode"},{"children":[13],"x":460,"name":"viData(response)","y":200,"id":12,"type":"ImplicitParameterNode"},{"children":[11],"x":640,"name":":viTelegram (response)","y":10,"id":10,"type":"ImplicitParameterNode"},{"x":0,"y":0,"openBottom":false,"id":18,"type":"CallNode"},{"children":[15,16,17,18],"x":850,"name":"viSerial","y":280,"id":14,"type":"ImplicitParameterNode"},{"x":0,"y":0,"openBottom":false,"id":13,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":15,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":16,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":17,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":11,"type":"CallNode"},{"x":0,"y":0,"openBottom":false,"id":3,"type":"CallNode"},{"x":-10,"y":0,"openBottom":false,"id":1,"type":"CallNode"},{"children":[7],"x":460,"name":"viData","y":-820,"id":6,"type":"ImplicitParameterNode"},{"x":0,"y":0,"openBottom":false,"id":5,"type":"CallNode"}],"edges":[{"middleLabel":"Write","start":3,"end":1,"type":"CallEdge","signal":false},{"middleLabel":"«create»","start":1,"end":5,"type":"ConstructorEdge","signal":false},{"middleLabel":"«create»","start":1,"end":7,"type":"ConstructorEdge","signal":false},{"middleLabel":"«create»","start":1,"end":9,"type":"ConstructorEdge","signal":false},{"middleLabel":"send write telegram","start":1,"end":15,"type":"CallEdge","signal":false},{"middleLabel":"read acknowledge","start":1,"end":18,"type":"CallEdge","signal":false},{"middleLabel":"read raw response","start":1,"end":16,"type":"CallEdge","signal":false},{"middleLabel":"send acknowledge","start":1,"end":17,"type":"CallEdge","signal":false},{"middleLabel":"","start":16,"end":1,"type":"ReturnEdge"},{"middleLabel":"","start":18,"end":1,"type":"ReturnEdge"},{"middleLabel":"","start":9,"end":1,"type":"ReturnEdge"},{"middleLabel":"","start":5,"end":1,"type":"ReturnEdge"},{"middleLabel":"return viData","start":1,"end":3,"type":"ReturnEdge"},{"middleLabel":"","start":7,"end":1,"type":"ReturnEdge"},{"middleLabel":"«create»","start":1,"end":11,"type":"ConstructorEdge","signal":false},{"middleLabel":"","start":11,"end":1,"type":"ReturnEdge"},{"middleLabel":"«create»","start":1,"end":13,"type":"ConstructorEdge","signal":false},{"middleLabel":"","start":13,"end":1,"type":"ReturnEdge"}],"version":"2.6"}
2 |
--------------------------------------------------------------------------------
/doc/pyvcontrol_write.sequence.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joppi588/pyvcontrol/06c5c473bcc69c7c943744d953404e354d2de44e/doc/pyvcontrol_write.sequence.png
--------------------------------------------------------------------------------
/pyvcontrol/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joppi588/pyvcontrol/06c5c473bcc69c7c943744d953404e354d2de44e/pyvcontrol/__init__.py
--------------------------------------------------------------------------------
/pyvcontrol/viCommand.py:
--------------------------------------------------------------------------------
1 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
2 | # Copyright 2021 Jochen Schmähling
3 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
4 | # Python Module for communication with viControl heatings using the serial Optolink interface
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see .
18 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
19 |
20 |
21 | import logging
22 |
23 | ACCESS_MODE = 'access_mode'
24 | UNIT = 'unit'
25 | LENGTH = 'length'
26 | ADDRESS = 'address'
27 |
28 | VITOCAL_WO1C = {
29 | # All Parameters are tested and working on Vitocal 200S WO1C (Baujahr 2019)
30 |
31 | # ------ Statusinfos (read only) ------
32 |
33 | # Warmwasser: Warmwassertemperatur oben (0..95)
34 | 'Warmwassertemperatur': {ADDRESS: '010d', LENGTH: 2, UNIT: 'IS10'},
35 |
36 | # Aussentemperatur (-40..70)
37 | 'Aussentemperatur': {ADDRESS: '0101', LENGTH: 2, UNIT: 'IS10'},
38 |
39 | # Heizkreis HK1: Vorlauftemperatur Sekundaer 1 (0..95)
40 | 'VorlauftempSek': {ADDRESS: '0105', LENGTH: 2, UNIT: 'IS10'},
41 |
42 | # Ruecklauftemperatur Sekundaer 1 (0..95)
43 | 'RuecklauftempSek': {ADDRESS: '0106', LENGTH: 2, UNIT: 'IS10'},
44 |
45 | # Sekundaerpumpe [%] (including one status byte)
46 | 'Sekundaerpumpe': {ADDRESS: 'B421', LENGTH: 2, UNIT: 'IUNON'},
47 |
48 | # Faktor Energiebilanz(1 = 0.1kWh, 10 = 1kWh, 100 = 10kWh)
49 | 'FaktorEnergiebilanz': {ADDRESS: '163F', LENGTH: 1, UNIT: 'IUNON'},
50 |
51 | # Heizwärme "Heizbetrieb", Verdichter 1
52 | 'Heizwaerme': {ADDRESS: '1640', LENGTH: 4, UNIT: 'IUNON'},
53 |
54 | # Elektroenergie "Heizbetrieb", Verdichter 1
55 | 'Heizenergie': {ADDRESS: '1660', LENGTH: 4, UNIT: 'IUNON'},
56 |
57 | # Heizwärme "WW-Betrieb", Verdichter 1
58 | 'WWwaerme': {ADDRESS: '1650', LENGTH: 4, UNIT: 'IUNON'},
59 |
60 | # Elektroenergie "WW-Betrieb", Verdichter 1
61 | 'WWenergie': {ADDRESS: '1670', LENGTH: 4, UNIT: 'IUNON'},
62 |
63 | # Verdichter [%] (including one status byte)
64 | 'Verdichter': {ADDRESS: 'B423', LENGTH: 4, UNIT: 'IUNON'},
65 |
66 | # Druck Sauggas [bar] (including one status byte) - Kühlmittel
67 | 'DruckSauggas': {ADDRESS: 'B410', LENGTH: 3, UNIT: 'IS10'},
68 |
69 | # Druck Heissgas [bar] (including one status byte)- Kühlmittel
70 | 'DruckHeissgas': {ADDRESS: 'B411', LENGTH: 3, UNIT: 'IS10'},
71 |
72 | # Temperatur Sauggas [bar] (including one status byte)- Kühlmittel
73 | 'TempSauggas': {ADDRESS: 'B409', LENGTH: 3, UNIT: 'IS10'},
74 |
75 | # Temperatur Heissgas [bar] (including one status byte)- Kühlmittel
76 | 'TempHeissgas': {ADDRESS: 'B40A', LENGTH: 3, UNIT: 'IS10'},
77 |
78 | # Anlagentyp (muss 204D sein)
79 | 'Anlagentyp': {ADDRESS: '00F8', LENGTH: 4, UNIT: 'DT'},
80 |
81 | # --------- Menüebene -------
82 |
83 | # Betriebsmodus
84 | 'Betriebsmodus': {ADDRESS: 'B000', LENGTH: 1, UNIT: 'BA', ACCESS_MODE: 'write'},
85 |
86 | # getManuell / setManuell -- 0 = normal, 1 = manueller Heizbetrieb, 2 = 1x Warmwasser auf Temp2
87 | 'WWeinmal': {ADDRESS: 'B020', LENGTH: 1, UNIT: 'OO', ACCESS_MODE: 'write'},
88 |
89 | # Warmwassersolltemperatur (10..60 (95))
90 | 'SolltempWarmwasser': {ADDRESS: '6000', LENGTH: 2, UNIT: 'IS10', ACCESS_MODE: 'write', 'min_value': 10,
91 | 'max_value': 60},
92 |
93 | # --------- Codierebene 2 ---------
94 |
95 | # Hysterese Vorlauf ein: Verdichter schaltet im Heizbetrieb ein
96 | 'Hysterese_Vorlauf_ein': {ADDRESS: '7304', LENGTH: 2, UNIT: 'IU10', ACCESS_MODE: 'write'},
97 |
98 | # Hysterese Vorlauf aus: Verdichter schaltet im Heizbetrieb ab
99 | 'Hysterese_Vorlauf_aus': {ADDRESS: '7313', LENGTH: 2, UNIT: 'IU10', ACCESS_MODE: 'write'},
100 |
101 | # --------- Function Call --------
102 | 'Energiebilanz': {ADDRESS: 'B800', LENGTH: 16, UNIT: 'F_E', ACCESS_MODE: 'call'},
103 |
104 | }
105 |
106 |
107 | class viCommandException(Exception):
108 | pass
109 |
110 |
111 | class viCommand(bytearray):
112 | """Representation of a command. Object value is a bytearray of address and length."""
113 |
114 | # =============================================================
115 | # CHANGE YOUR COMMAND SET HERE:
116 | command_set = VITOCAL_WO1C
117 |
118 | # =============================================================
119 |
120 | def __init__(self, command_name):
121 | """initialize object using the attributes of the chosen command."""
122 |
123 | try:
124 | command = self.command_set[command_name]
125 | except:
126 | raise viCommandException(f'Unknown command {command_name}')
127 | self._command_code = command[ADDRESS]
128 | self._value_bytes = command[LENGTH]
129 | self.unit = command[UNIT]
130 | self.access_mode = self._get_access_mode(command)
131 | self.command_name = command_name
132 |
133 | # create bytearray representation
134 | b = bytes.fromhex(self._command_code) + self._value_bytes.to_bytes(1, 'big')
135 | super().__init__(b)
136 |
137 | def _get_access_mode(self, command):
138 | if ACCESS_MODE in command.keys():
139 | return command[ACCESS_MODE]
140 | else:
141 | return 'read'
142 |
143 | @classmethod
144 | def _from_bytes(cls, b: bytearray):
145 | """Create command from address b given as byte, only the first two bytes of b are evaluated."""
146 | try:
147 | logging.debug(f'Convert {b.hex()} to command')
148 | command_name = next(key for key, value in cls.command_set.items() if value[ADDRESS].lower() == b[0:2].hex())
149 | except:
150 | raise viCommandException(f'No Command matching {b[0:2].hex()}')
151 | return viCommand(command_name)
152 |
153 | def response_length(self, access_mode='read'):
154 | """Returns the number of bytes in the response."""
155 | # request_response:
156 | # 2 'address'
157 | # 1 'Anzahl der Bytes des Wertes'
158 | # x 'Wert'
159 | if access_mode.lower() == 'read':
160 | return 3 + self._value_bytes
161 | elif access_mode.lower() == 'write':
162 | # in write mode the written values are not returned
163 | return 3
164 | else:
165 | return 3 + self._value_bytes
166 |
--------------------------------------------------------------------------------
/pyvcontrol/viControl.py:
--------------------------------------------------------------------------------
1 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
2 | # Copyright 2021 Jochen Schmähling
3 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
4 | # Python Module for communication with viControl heatings using the serial Optolink interface
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see .
18 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
19 |
20 |
21 | from pyvcontrol.viCommand import viCommand
22 | from pyvcontrol.viTelegram import viTelegram
23 | from pyvcontrol.viData import viData
24 | import logging
25 | import serial
26 | from threading import Lock
27 | from deprecated import deprecated
28 |
29 | control_set = {
30 | 'Baudrate': 4800,
31 | 'Bytesize': 8, # 'EIGHTBITS'
32 | 'Parity': 'E', # 'PARITY_EVEN',
33 | 'Stopbits': 2, # 'STOPBITS_TWO',
34 | }
35 |
36 | ctrlcode = {
37 | 'reset_cmd': b'\x04',
38 | 'sync_cmd': b'\x16\x00\x00',
39 | 'acknowledge': b'\x06',
40 | 'not_init': b'\x05',
41 | 'error': b'\x15',
42 | }
43 |
44 |
45 | class viControlException(Exception):
46 | def __init__(self, msg):
47 | super().__init__(msg)
48 |
49 |
50 | class viControl:
51 | # class to connect to viControl heating directly via Optolink
52 | # only supports WO1C with protocol P300
53 | def __init__(self, port='/dev/ttyUSB0'):
54 | self.vs = viSerial(control_set, port)
55 | self.vs.connect()
56 | self.is_initialized = False
57 |
58 | def __del__(self):
59 | # destructor, releases serial port
60 | self.vs.disconnect()
61 |
62 | @deprecated(version='1.3', reason="replaced by execute_read_command")
63 | def execReadCmd(self, cmdname) -> viData:
64 | """ sends a read command and gets the response."""
65 | return self.execute_read_command(cmdname)
66 |
67 | def execute_read_command(self, command_name) -> viData:
68 | """ sends a read command and gets the response."""
69 | vc = viCommand(command_name)
70 | return self.execute_command(vc, 'read')
71 |
72 | @deprecated(version='1.3', reason="replaced by execute_write_command")
73 | def execWriteCmd(self, cmdname, value) -> viData:
74 | """ sends a write command and gets the response."""
75 | return self.execute_write_command(cmdname, value=value)
76 |
77 | def execute_write_command(self, command_name, value) -> viData:
78 | """ sends a write command and gets the response."""
79 | vc = viCommand(command_name)
80 | vd = viData.create(vc.unit, value)
81 | return self.execute_command(vc, 'write', payload=vd)
82 |
83 | @deprecated(version='1.3', reason="replaced by execute_write_command")
84 | def execFunctionCall(self, cmdname, *function_args) -> viData:
85 | """ sends a function call command and gets response."""
86 | payload = bytearray((len(function_args), *function_args))
87 | return self.execute_command(cmdname, 'call', payload=payload)
88 |
89 | def execute_function_call(self, command_name, *function_args) -> viData:
90 | """ sends a function call command and gets response."""
91 | payload = bytearray((len(function_args), *function_args))
92 | vc = viCommand(command_name)
93 | return self.execute_command(vc, 'call', payload=payload)
94 |
95 | def execute_command(self, vc, access_mode, payload=bytes(0)) -> viData:
96 |
97 | # prepare command
98 | allowed_access_mode = {'read': ['read'], 'write': ['read', 'write'], 'call': ['call']}
99 | if access_mode not in allowed_access_mode[vc.access_mode]:
100 | raise viControlException(
101 | f'command {vc.command_name} allows only {allowed_access_mode[vc.access_mode]} access')
102 |
103 | # send Telegram
104 | vt = viTelegram(vc, access_mode, payload=payload)
105 | logging.debug(f'Send telegram {vt.hex()}')
106 | self.vs.send(vt)
107 |
108 | # Check if sending was successful
109 | ack = self.vs.read(1)
110 | logging.debug(f'Received {ack.hex()}')
111 | if ack != ctrlcode['acknowledge']:
112 | raise viControlException(f'Expected acknowledge byte, received {ack}')
113 |
114 | # Receive response and evaluate data
115 | vr = self.vs.read(vt.response_length) # receive response
116 | vt = viTelegram.from_bytes(vr)
117 | logging.debug(f'Requested {vt.response_length} bytes. Received telegram {vr.hex()}')
118 | if vt.tType == viTelegram.tTypes['error']:
119 | raise viControlException(f'{access_mode} command returned an error')
120 | self.vs.send(ctrlcode['acknowledge']) # send acknowledge
121 |
122 | # return viData object from payload
123 | return viData.create(vt.vicmd.unit, vt.payload)
124 |
125 | @deprecated(version='1.3', reason="replaced by initialize_communication.")
126 | def initComm(self):
127 | self.initialize_communication()
128 |
129 | def initialize_communication(self):
130 | logging.debug('Init Communication to viControl....')
131 | self.is_initialized = False
132 |
133 | # loop cases
134 | # 1 - ii=0: read timeout -> send reset / ii=1: not_init, send sync / ii=2: Initialization successful
135 | # 1 - ii=0: error -> send reset / ii=1: not_init, send sync / ii=2: Initialization successful
136 | # 2 - ... ii=10: exit loop, give up
137 |
138 | for ii in range(0, 10):
139 | # loop until interface is initialized
140 | read_byte = self.vs.read(1)
141 | if read_byte == ctrlcode['acknowledge']:
142 | # Schnittstelle hat auf den Initialisierungsstring mit OK geantwortet. Die Abfrage von Werten kann beginnen.
143 | logging.debug(f'Step {ii}: Initialization successful')
144 | self.is_initialized = True
145 | break
146 | elif read_byte == ctrlcode['not_init']:
147 | # Schnittstelle ist zurückgesetzt und wartet auf Daten; Antwort b'\x05' = Warten auf Initialisierungsstring
148 | logging.debug(f'Step {ii}: Viessmann ready, not initialized, send sync')
149 | self.vs.send(ctrlcode['sync_cmd'])
150 | elif read_byte == ctrlcode['error']:
151 | # in case of error try to reset
152 | logging.error(f'The interface has reported an error (\x15), loop increment {ii}')
153 | logging.debug(f'Step {ii}: Send reset')
154 | self.vs.send(ctrlcode['reset_cmd'])
155 | else:
156 | # send reset
157 | logging.debug(f'Received [{read_byte}]. Step {ii}: Send reset')
158 | self.vs.send(ctrlcode['reset_cmd'])
159 |
160 | if not self.is_initialized:
161 | # initialisation not successful
162 | raise viControlException('Could not initialize communication')
163 |
164 | logging.debug('Communication initialized')
165 | return True
166 |
167 |
168 | class viSerial():
169 | # low-level communication interface
170 | # FIXME: control sets nicht übernommen
171 | _viessmann_lock = Lock()
172 |
173 | # viControl socket: implement raw communication
174 | def __init__(self, control_set, port):
175 | self._connected = False
176 | self._control_set = control_set
177 | self._serial_port = port
178 | self._serial = serial.Serial()
179 |
180 | def connect(self):
181 | # setup serial connection
182 | # if not connected, try to acquire lock
183 | if self._connected:
184 | # do nothing
185 | logging.debug('Connect: Already connected')
186 | return
187 | if self._viessmann_lock.acquire(timeout=10):
188 | try:
189 | # initialize serial connection
190 | logging.debug('Connecting ...')
191 | self._serial.baudrate = self._control_set['Baudrate']
192 | self._serial.parity = self._control_set['Parity']
193 | self._serial.bytesize = self._control_set['Bytesize']
194 | self._serial.stopbits = self._control_set['Stopbits']
195 | self._serial.port = self._serial_port
196 | self._serial.timeout = 0.25 # read method will try 10 times -> 2.5s max waiting time
197 | self._serial.open()
198 | self._connected = True
199 | logging.debug('Connected to {}'.format(self._serial_port))
200 | except Exception as e:
201 | logging.error('Could not connect to {}; Error: {}'.format(self._serial_port, e))
202 | self._viessmann_lock.release()
203 | self._connected = False
204 | else:
205 | logging.error('Could not acquire lock')
206 |
207 | def disconnect(self):
208 | # release serial line and lock
209 | self._serial.close()
210 | self._serial = None
211 | self._viessmann_lock.release()
212 | self._connected = False
213 | logging.debug('Disconnected from viControl')
214 |
215 | def send(self, packet):
216 | # if connected send the packet
217 | if self._connected:
218 | self._serial.write(packet)
219 | return True
220 | else:
221 | return False
222 |
223 | def read(self, length):
224 | # read bytes from serial connection
225 | total_read_bytes = bytearray(0)
226 | failed_count = 0
227 | # FIXME: read length bytes and try ten times if nothing received
228 | while failed_count < 10:
229 | # try to get one or more bytes
230 | read_byte = self._serial.read()
231 | total_read_bytes += read_byte
232 | if len(total_read_bytes) >= length:
233 | # exit loop if all bytes are received
234 | break
235 | if len(read_byte) == 0:
236 | # if nothing received, wait and retry
237 | failed_count += 1
238 | logging.debug(f'Serial read: retry ({failed_count})')
239 | logging.debug(f'Received {len(total_read_bytes)}/{length} bytes')
240 | return bytes(total_read_bytes)
241 |
--------------------------------------------------------------------------------
/pyvcontrol/viData.py:
--------------------------------------------------------------------------------
1 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
2 | # Copyright 2021 Jochen Schmähling
3 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
4 | # Python Module for communication with viControl heatings using the serial Optolink interface
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see .
18 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
19 |
20 | import logging
21 | from collections import namedtuple
22 | from struct import unpack
23 |
24 |
25 | class viDataException(Exception):
26 | def __init__(self, msg):
27 | super().__init__(msg)
28 |
29 |
30 | class viData(bytearray):
31 | # implements representations of viControl data types
32 | # erzeugen eines Datentypes über benannte Klasse -> setze code und codiere Parameter als bytes
33 |
34 | # konstruktor __init__ accepts byte-encoded input or real data
35 | # property value returns the decoded value (str,int,fixed-point,...)
36 | # method _create_from_raw initializes the object with raw byte data
37 | # method _create_from_value initializes the object with a typed value
38 |
39 | # Implemented units:
40 | # BA : Betriebsart
41 | # ES : Errorset
42 | # DT : Devicetype
43 | # IS10 : Int signed, base 10 (i.e. 1 digit fixed point)
44 | # IU10 : Int unsigned, base 10 (i.e. 1 digit fixed point)
45 | # IUNON : Int unsigned, no base
46 | # IU3600: Int unsigned, base 3600 (i.e. hours & seconds)
47 | # OO : On Off,
48 | # RT : Return Type
49 | # FIXME: implemented all units -> create own classes
50 | # FIXME: Units für Temperatur, h, etc. erzeugen
51 |
52 | # units not implemented so far:
53 | unitset = {
54 | 'CT': {'description': 'CycleTime', 'type': 'timer', 'signed': False, 'read_value_transform': 'non'},
55 | # vito unit: CT
56 | 'IU2': {'description': 'INT unsigned 2', 'type': 'integer', 'signed': False, 'read_value_transform': '2'},
57 | # vito unit: UT1U, PR1
58 | 'IUBOOL': {'description': 'INT unsigned bool', 'type': 'integer', 'signed': False,
59 | 'read_value_transform': 'bool'}, # vito unit:
60 | 'IUINT': {'description': 'INT unsigned int', 'type': 'integer', 'signed': False, 'read_value_transform': 'int'},
61 | # vito unit:
62 | 'IS2': {'description': 'INT signed 2', 'type': 'integer', 'signed': True, 'read_value_transform': '2'},
63 | # vito unit: UT1, PR
64 | 'IS100': {'description': 'INT signed 100', 'type': 'integer', 'signed': True, 'read_value_transform': '100'},
65 | # vito unit:
66 | 'IS1000': {'description': 'INT signed 1000', 'type': 'integer', 'signed': True, 'read_value_transform': '1000'},
67 | # vito unit:
68 | 'ISNON': {'description': 'INT signed non', 'type': 'integer', 'signed': True, 'read_value_transform': 'non'},
69 | # vito unit:
70 | 'SC': {'description': 'SystemScheme', 'type': 'list', 'signed': False, 'read_value_transform': 'non'},
71 | # vito unit:
72 | 'SN': {'description': 'Sachnummer', 'type': 'serial', 'signed': False, 'read_value_transform': 'non'},
73 | # vito unit:
74 | 'SR': {'description': 'SetReturnStatus', 'type': 'list', 'signed': False, 'read_value_transform': 'non'},
75 | # vito unit:
76 | 'TI': {'description': 'SystemTime', 'type': 'datetime', 'signed': False, 'read_value_transform': 'non'},
77 | # vito unit: TI
78 | 'DA': {'description': 'Date', 'type': 'date', 'signed': False, 'read_value_transform': 'non'}, # vito unit:
79 | }
80 |
81 | def __init__(self, value):
82 | """ to be overridden by subclass. subclass __init__ shall set default value for value and handle any extra parameters """
83 | super().__init__()
84 | if type(value) == bytes or type(value) == bytearray:
85 | self._create_from_raw(value)
86 | else:
87 | self._create_from_value(value)
88 |
89 | def _create_from_raw(self, value):
90 | # fill using byte values
91 | super().extend(value)
92 | self.len = len(value)
93 |
94 | def _create_from_value(self, value):
95 | # fill using type and value
96 | # empty declaration, must be overridden by subclass
97 | raise NotImplementedError
98 |
99 | @property
100 | def value(self):
101 | # empty declaration, must be overriden by subclass
102 | # returns value converted from raw data
103 | raise NotImplementedError
104 |
105 | @classmethod
106 | def create(cls, datatype, *args):
107 | # select data type object based on type
108 | # args are passed as such to the constructor of the function
109 | logging.debug(f'Data factory: request to produce Data type {datatype} with args {args}')
110 | datatype_object = {'BA': viDataBA, 'DT': viDataDT, 'IS10': viDataIS10, 'IU10': viDataIU10,
111 | 'IU3600': viDataIU3600, 'IUNON': viDataIUNON, 'RT': viDataRT, 'OO': viDataOO,
112 | 'ES': viDataES, 'F_E': viDataEnergy,
113 | }
114 | if datatype in datatype_object.keys():
115 | return datatype_object[datatype](*args)
116 | else:
117 | # if unit type is not implemented
118 | raise viDataException(f'Unit {datatype} not known')
119 |
120 |
121 | # ----------------------------------------
122 | # Below are the class definitions for each unit
123 |
124 | class viDataBA(viData):
125 | # Betriebsart
126 | unit = {'code': 'BA', 'description': 'Betriebsart', 'unit': ''}
127 | # operating mode codes are hex numbers
128 | operatingmodes = {
129 | 0x00: 'OFF',
130 | 0x01: 'WW',
131 | 0x02: 'HEATING_WW',
132 | }
133 |
134 | def __init__(self, value=b'\x00'):
135 | # sets operating mode (hex) based on value
136 | super().__init__(value)
137 |
138 | def _create_from_value(self, opmode):
139 | if opmode in self.operatingmodes.values():
140 | opcode = next(key for key, value in self.operatingmodes.items() if value == opmode)
141 | super().extend(opcode.to_bytes(1, 'little'))
142 | else:
143 | raise viDataException(f'Unknown operating mode {opmode}. Options are {self.operatingmodes.values()}')
144 |
145 | def _create_from_raw(self, value):
146 | # set raw value directly
147 | if int.from_bytes(value, 'little') in self.operatingmodes.keys():
148 | super().extend(value)
149 | else:
150 | raise viDataException(f'Unknown operating mode {value.hex()}')
151 |
152 | @property
153 | def value(self):
154 | # returns decoded value
155 | return self.operatingmodes[int.from_bytes(self, 'little')]
156 |
157 |
158 | class viDataES(viData):
159 | # ERROR states
160 | unit = {'code': 'ES', 'description': 'Error', 'unit': ''}
161 | # error codes are hex numbers
162 | errorset = {
163 | 0x00: 'Regelbetrieb (kein Fehler)',
164 | 0x0F: 'Wartung (fuer Reset Codieradresse 24 auf 0 stellen)',
165 | 0x10: 'Kurzschluss Aussentemperatursensor',
166 | 0x18: 'Unterbrechung Aussentemperatursensor',
167 | 0x20: 'Kurzschluss Vorlauftemperatursensor',
168 | 0x21: 'Kurzschluss Ruecklauftemperatursensor',
169 | 0x28: 'Unterbrechung Aussentemperatursensor',
170 | 0x29: 'Unterbrechung Ruecklauftemperatursensor',
171 | 0x30: 'Kurzschluss Kesseltemperatursensor',
172 | 0x38: 'Unterbrechung Kesseltemperatursensor',
173 | 0x40: 'Kurzschluss Vorlauftemperatursensor M2',
174 | 0x42: 'Unterbrechung Vorlauftemperatursensor M2',
175 | 0x50: 'Kurzschluss Speichertemperatursensor',
176 | 0x58: 'Unterbrechung Speichertemperatursensor',
177 | 0x92: 'Solar: Kurzschluss Kollektortemperatursensor',
178 | 0x93: 'Solar: Kurzschluss Sensor S3',
179 | 0x94: 'Solar: Kurzschluss Speichertemperatursensor',
180 | 0x9A: 'Solar: Unterbrechung Kollektortemperatursensor',
181 | 0x9B: 'Solar: Unterbrechung Sensor S3',
182 | 0x9C: 'Solar: Unterbrechung Speichertemperatursensor',
183 | 0x9E: 'Solar: Zu geringer bzw. kein Volumenstrom oder Temperaturwächter ausgeloest',
184 | 0x9F: 'Solar: Fehlermeldung Solarteil (siehe Solarregler)',
185 | 0xA7: 'Bedienteil defekt',
186 | 0xB0: 'Kurzschluss Abgastemperatursensor',
187 | 0xB1: 'Kommunikationsfehler Bedieneinheit',
188 | 0xB4: 'Interner Fehler (Elektronik)',
189 | 0xB5: 'Interner Fehler (Elektronik)',
190 | 0xB6: 'Ungueltige Hardwarekennung (Elektronik)',
191 | 0xB7: 'Interner Fehler (Kesselkodierstecker)',
192 | 0xB8: 'Unterbrechung Abgastemperatursensor',
193 | 0xB9: 'Interner Fehler (Dateneingabe wiederholen)',
194 | 0xBA: 'Kommunikationsfehler Erweiterungssatz fuer Mischerkreis M2',
195 | 0xBC: 'Kommunikationsfehler Fernbedienung Vitorol, Heizkreis M1',
196 | 0xBD: 'Kommunikationsfehler Fernbedienung Vitorol, Heizkreis M2',
197 | 0xBE: 'Falsche Codierung Fernbedienung Vitorol',
198 | 0xC1: 'Externe Sicherheitseinrichtung (Kessel kuehlt aus)',
199 | 0xC2: 'Kommunikationsfehler Solarregelung',
200 | 0xC5: 'Kommunikationsfehler drehzahlgeregelte Heizkreispumpe, Heizkreis M1',
201 | 0xC6: 'Kommunikationsfehler drehzahlgeregelte Heizkreispumpe, Heizkreis M2',
202 | 0xC7: 'Falsche Codierung der Heizkreispumpe',
203 | 0xC9: 'Stoermeldeeingang am Schaltmodul-V aktiv',
204 | 0xCD: 'Kommunikationsfehler Vitocom 100 (KM-BUS)',
205 | 0xCE: 'Kommunikationsfehler Schaltmodul-V',
206 | 0xCF: 'Kommunikationsfehler LON Modul',
207 | 0xD1: 'Brennerstoerung',
208 | 0xD4: 'Sicherheitstemperaturbegrenzer hat ausgeloest oder Stoermeldemodul nicht richtig gesteckt',
209 | 0xDA: 'Kurzschluss Raumtemperatursensor, Heizkreis M1',
210 | 0xDB: 'Kurzschluss Raumtemperatursensor, Heizkreis M2',
211 | 0xDD: 'Unterbrechung Raumtemperatursensor, Heizkreis M1',
212 | 0xDE: 'Unterbrechung Raumtemperatursensor, Heizkreis M2',
213 | 0xE4: 'Fehler Versorgungsspannung',
214 | 0xE5: 'Interner Fehler (Ionisationselektrode)',
215 | 0xE6: 'Abgas- / Zuluftsystem verstopft',
216 | 0xF0: 'Interner Fehler (Regelung tauschen)',
217 | 0xF1: 'Abgastemperaturbegrenzer ausgeloest',
218 | 0xF2: 'Temperaturbegrenzer ausgeloest',
219 | 0xF3: 'Flammensigal beim Brennerstart bereits vorhanden',
220 | 0xF4: 'Flammensigal nicht vorhanden',
221 | 0xF7: 'Differenzdrucksensor defekt',
222 | 0xF8: 'Brennstoffventil schliesst zu spaet',
223 | 0xF9: 'Geblaesedrehzahl beim Brennerstart zu niedrig',
224 | 0xFA: 'Geblaesestillstand nicht erreicht',
225 | 0xFD: 'Fehler Gasfeuerungsautomat',
226 | 0xFE: 'Starkes Stoerfeld (EMV) in der Naehe oder Elektronik defekt',
227 | 0xFF: 'Starkes Stoerfeld (EMV) in der Naehe oder interner Fehler',
228 | }
229 |
230 | def __init__(self, value=b'\x00'):
231 | # default is no error
232 | super().__init__(value)
233 |
234 | # def __fromtype__(self,errstr):
235 | # Implementation does not make sense, an error will always be raised by the Viessmann unit
236 |
237 | def _create_from_raw(self, value):
238 | # set raw value directly
239 | if int.from_bytes(value, 'big') in self.errorset.keys():
240 | super().extend(value)
241 | else:
242 | raise viDataException(f'Unknown error code {value.hex()}')
243 |
244 | @property
245 | def value(self):
246 | # returns decoded value
247 | return self.errorset[int.from_bytes(self, 'big')]
248 |
249 |
250 | class viDataDT(viData):
251 | # device types
252 | unit = {'description': 'DeviceType', 'code': 'DT', 'unit': ''} # vito unit: DT
253 | devicetypes = {
254 | 0x2098: 'V200KW2, Protokoll: KW2',
255 | 0x2053: 'GWG_VBEM, Protokoll: GWG',
256 | 0x20CB: 'VScotHO1, Protokoll: P300',
257 | 0x2094: 'V200KW1, Protokoll: KW2',
258 | 0x209F: 'V200KO1B, Protokoll: P300, KW2',
259 | 0x204D: 'V200WO1C, Protokoll: P300',
260 | 0x204B: 'Vitocal 333G, Protokoll: P300',
261 | 0x20B8: 'V333MW1, Protokoll: ',
262 | 0x20A0: 'V100GC1, Protokoll: ',
263 | 0x20C2: 'VDensHO1, Protokoll: ',
264 | 0x20A4: 'V200GW1, Protokoll: ',
265 | 0x20C8: 'VPlusHO1, Protokoll: ',
266 | 0x2046: 'V200WO1,VBC700, Protokoll: ',
267 | 0x2047: 'V200WO1,VBC700, Protokoll: ',
268 | 0x2049: 'V200WO1,VBC700, Protokoll: ',
269 | 0x2032: 'VBC550, Protokoll: ',
270 | 0x2033: 'VBC550, Protokoll: ',
271 | 0x0000: 'unknown'
272 | }
273 |
274 | def __init__(self, value=b'\x00\x00'):
275 | # sets device name (hex code). Either give value as bytearray/bytes or as device name string
276 | # usually this class would be initialized without arguments
277 | super().__init__(value)
278 |
279 | def _create_from_raw(self, value):
280 | # set raw value directly
281 | if int.from_bytes(value, 'big') in self.devicetypes.keys():
282 | super().extend(value)
283 | else:
284 | raise viDataException(f'Unknown device code {value.hex()}')
285 |
286 | def _create_from_value(self, devicename):
287 | # devicename given as string
288 | if devicename in self.devicetypes.values():
289 | devcode = next(key for key, value in self.devicetypes.items() if value == devicename)
290 | super().extend(devcode.to_bytes(2, 'big'))
291 | else:
292 | raise viDataException(f'Unknown device name {devicename}')
293 |
294 | @property
295 | def value(self):
296 | # return device type as string
297 | return self.devicetypes[int.from_bytes(self, 'big')]
298 |
299 |
300 | class viDataIS10(viData):
301 | # IS10 - signed fixed-point integer, 1 decimal
302 | unit = {'code': 'IS10', 'description': 'INT signed 10', 'unit': ''}
303 |
304 | def __init__(self, value=b'\x00\x00', len=2):
305 | # sets int representation based on input value
306 | self.len = len # length in bytes
307 | super().__init__(value)
308 |
309 | def _create_from_value(self, value):
310 | # fixed-point number given
311 | # FIXME Is it ok to overwrite its own value or should a new object be returned?
312 | super().extend(int(value * 10).to_bytes(self.len, 'little', signed=True))
313 |
314 | @property
315 | def value(self):
316 | return int.from_bytes(self, 'little', signed=True) / 10
317 |
318 |
319 | class viDataIU10(viData):
320 | # IS10 - signed fixed-point integer, 1 decimal
321 | unit = {'code': 'IU10', 'description': 'INT unsigned 10', 'unit': ''}
322 |
323 | def __init__(self, value=b'\x00\x00', len=2):
324 | # sets int representation based on input value
325 | self.len = len # length in bytes
326 | super().__init__(value)
327 |
328 | def _create_from_value(self, value):
329 | # fixed-point number given
330 | super().extend(int(value * 10).to_bytes(self.len, 'little', signed=False))
331 |
332 | @property
333 | def value(self):
334 | return int.from_bytes(self, 'little', signed=False) / 10
335 |
336 |
337 | class viDataIU3600(viData):
338 | # IU3600 - signed fixed-point integer, 1 decimal
339 | unit = {'code': 'IS10', 'description': 'INT signed 10', 'unit': 'h'}
340 |
341 | def __init__(self, value=b'\x00\x00', len=2):
342 | # sets int representation based on input value
343 | self.len = len # length in bytes
344 | super().__init__(value)
345 |
346 | def _create_from_value(self, value):
347 | # fixed-point number given
348 | super().extend(int(value * 3600).to_bytes(self.len, 'little', signed=False))
349 |
350 | @property
351 | def value(self):
352 | # FIXME round to two digits
353 | return int.from_bytes(self, 'little', signed=True) / 3600
354 |
355 |
356 | class viDataIUNON(viData):
357 | # IUNON - unsigned int
358 | unit = {'code': 'IUNON', 'description': 'INT unsigned non', 'unit': ''}, # vito unit: UTI, CO
359 |
360 | def __init__(self, value=b'\x00\x00', len=2):
361 | # sets int representation based on input value
362 | self.len = len # length in bytes
363 | super().__init__(value)
364 |
365 | def _create_from_value(self, value):
366 | # fixed-point number given
367 | super().extend(int(value).to_bytes(self.len, 'little', signed=False))
368 |
369 | @property
370 | def value(self):
371 | return int.from_bytes(self, 'little', signed=False)
372 |
373 |
374 | class viDataRT(viData):
375 | unit = {'code': 'RT', 'description': 'ReturnStatus', 'unit': ''}
376 | # operating mode codes are hex numbers
377 | returnstatus = {
378 | 0x00: '0',
379 | 0x01: '1',
380 | 0x03: '2',
381 | 0xAA: 'Not OK'
382 | }
383 |
384 | def __init__(self, value=b'\x00'):
385 | # sets operating mode (hex) based on string opmode
386 | # if opmode is skipped defaults to 'undefiniert'
387 | super().__init__(value)
388 |
389 | def _create_from_value(self, status):
390 | if status in self.returnstatus.values():
391 | opcode = next(key for key, value in self.returnstatus.items() if value == status)
392 | super().extend(opcode.to_bytes(1, 'big'))
393 | else:
394 | raise viDataException(f'Unknown return status {status}. Options are {self.returnstatus.values()}')
395 |
396 | def _create_from_raw(self, value):
397 | # set raw value directly
398 | if int.from_bytes(value, 'big') in self.returnstatus.keys():
399 | super().extend(value)
400 | else:
401 | raise viDataException(f'Unknown return status {value.hex()}')
402 |
403 | @property
404 | def value(self):
405 | return self.returnstatus[int.from_bytes(self, 'big')]
406 |
407 |
408 | class viDataOO(viData):
409 | unit = {'code': 'OO', 'description': 'OnOff', 'unit': ''}
410 | # operating mode codes are hex numbers
411 | OnOff = {
412 | 0x00: 'Off',
413 | 0x01: 'Manual',
414 | 0x02: 'On',
415 | }
416 |
417 | def __init__(self, value='Off'):
418 | super().__init__(value)
419 |
420 | def _create_from_value(self, onoff):
421 | if onoff in self.OnOff.values():
422 | opcode = next(key for key, value in self.OnOff.items() if value == onoff)
423 | super().extend(opcode.to_bytes(1, 'big'))
424 | else:
425 | raise viDataException(f'Unknown value {onoff}. Options are {self.OnOff.values()}')
426 |
427 | def _create_from_raw(self, value):
428 | # set raw value directly
429 | if int.from_bytes(value, 'big') in self.OnOff.keys():
430 | super().extend(value)
431 | else:
432 | raise viDataException(f'Unknown value {value.hex()}')
433 |
434 | @property
435 | def value(self):
436 | return self.OnOff[int.from_bytes(self, 'big')]
437 |
438 |
439 | LITTLE_ENDIAN_4_CHAR_6_SHORT = '<4B6H'
440 | MILLENIUM = 2000
441 | HEATING_ENERGY_FACTOR = 0.1
442 |
443 |
444 | class viDataEnergy(viData):
445 | """ Energy-Type ... Return from Function-Call B800 """
446 | unit = {'code': 'F_E', 'description': 'returns dictionary with energy data', 'unit': ''},
447 |
448 | def __init__(self, value=bytes(16)):
449 | super().__init__(value)
450 |
451 | def _create_from_raw(self, value):
452 | super().extend(value)
453 | self.len = len(value)
454 | raw_data = unpack(LITTLE_ENDIAN_4_CHAR_6_SHORT, value)
455 | self.day = raw_data[1]
456 | self.year = MILLENIUM + raw_data[2]
457 | self.week = raw_data[3]
458 | self.heating_energy = raw_data[4] * HEATING_ENERGY_FACTOR
459 | self.heating_electrical_energy = raw_data[5] * HEATING_ENERGY_FACTOR
460 | self.water_energy = raw_data[6] * HEATING_ENERGY_FACTOR
461 | self.water_electrical_energy = raw_data[7] * HEATING_ENERGY_FACTOR
462 | self.cooling_energy = raw_data[4] * HEATING_ENERGY_FACTOR
463 | self.cooling_electrical_energy = raw_data[5] * HEATING_ENERGY_FACTOR
464 |
465 | def _create_from_value(self, value):
466 | raise viDataException(f'viDataEnergy can only be created from bytes.')
467 |
468 | @property
469 | def value(self):
470 | """ decode the Result Record and return a dictionary. """
471 |
472 | total_energy = self.heating_energy + self.water_energy + self.cooling_energy
473 | total_electrical_energy = \
474 | self.heating_electrical_energy + self.water_electrical_energy + self.cooling_electrical_energy
475 |
476 | value_dictionary = {'day': self.day, 'week': self.week, 'year': self.year,
477 | 'heating_energy': self.heating_energy,
478 | 'heating_electrical_energy': self.heating_electrical_energy,
479 | 'water_energy': self.water_energy,
480 | 'water_electrical_energy': self.water_electrical_energy,
481 | 'cooling_energy': self.cooling_energy,
482 | 'cooling_electrical_energy': self.cooling_electrical_energy,
483 | 'total_energy': total_energy,
484 | 'total_electrical_energy': total_electrical_energy,
485 | }
486 |
487 | return value_dictionary
488 |
489 |
490 | system_schemes = {
491 | '01': 'WW',
492 | '02': 'HK + WW',
493 | '04': 'HK + WW',
494 | '05': 'HK + WW'
495 | }
496 |
--------------------------------------------------------------------------------
/pyvcontrol/viTelegram.py:
--------------------------------------------------------------------------------
1 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
2 | # Copyright 2021 Jochen Schmähling
3 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
4 | # Python Module for communication with viControl heatings using the serial Optolink interface
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see .
18 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
19 |
20 | import logging
21 | from pyvcontrol.viCommand import viCommand
22 |
23 |
24 | class viTelegramException(Exception):
25 | pass
26 |
27 |
28 | class viTelegram(bytearray):
29 | # represents a telegram (header, viCommand, payload and checksum)
30 |
31 | # P300 Protokoll (thanks to M.Wenzel, SmartHomeNG plugin)
32 | #
33 | # Beispiel
34 | #
35 | # Senden 41 5 0 1 55 25 2 82
36 | # Read Request -- - - - ----- - --
37 | # | | | | | | +------- Prüfsumme (Summe über alley Bytes ohne die 41; [hex]5+0+1+55+25+2 = [dez]5+0+1+(5x16)+5+(2x16)+5+2 = 130dez = 82hex
38 | # | | | | | +---------- XX Anzahl der Bytes, die in der Antwort erwartet werden
39 | # | | | | +-------------- XX XX 2 byte Adresse der Daten oder Prozedur
40 | # | | | +------------------ XX 01 = ReadData, 02 = WriteData, 07 = Function Call
41 | # | | +-------------------- XX 00 = Anfrage, 01 = Antwort, 03 = Fehler
42 | # | +---------------------- Länge der Nutzdaten (Anzahl der Bytes zwischen dem Telegramm-Start-Byte (0x41) und der Prüfsumme)
43 | # +------------------------ Telegramm-Start-Byte
44 | #
45 | # Empfangen : 6 ----------------------- OK (Antwort auf 0x16 0x00 0x00 und auf korrekt empfangene Telegramme)
46 | # 5 ----------------------- Schnittstelle ist aktiv und wartet auf eine Initialisierung
47 | # 15 ----------------------- Schnittstelle meldet einen Fehler zurück
48 | #
49 | # 41 7 1 1 55 25 2 EF 0 74
50 | # -- - - - ----- - ---- --
51 | # | | | | | | | +-- Prüfsumme (Summe über alley Bytes ohne die 41; [hex]7+1+1+55+25+2+EF+0 = [dez]7+1+1+(5x16)+5+(2x16)+5+2+(14*16)+(15*16)+0 = [dez]7+1+1+(80)+5+(32)+5+2+(224)+(15)+0 = 372dez = 1.74hex)
52 | # | | | | | | +------ Wert
53 | # | | | | | +---------- XX Anzahl der Bytes, die in der Antwort erwartet werden
54 | # | | | | +-------------- XX XX 2 byte Adresse der Daten oder Prozedur
55 | # | | | +------------------ XX 01 = ReadData, 02 = WriteData, 07 = Function Call
56 | # | | +-------------------- XX 00 = Anfrage, 01 = Antwort, 03 = Fehler
57 | # | +---------------------- Länge der Nutzdaten (Anzahl der Bytes zwischen dem Telegramm-Start-Byte (0x41) und der Prüfsumme)
58 | # +------------------------ Telegramm-Start-Byte
59 |
60 | # Kommunikationsbeispiele
61 | # Information Kessel Außentemperatur read 2-Byte -60..60 0x5525
62 | # DATA TX: 41 5 0 1 55 25 2 82
63 | # DATA RX: 41 7 1 1 55 25 2 EF 0 74 --> 00EF = 239 --> 23.9°C (Faktor 0.1)
64 | # --> Senden 41 5 0 1 55 25 2 82
65 | # -- - - - ----- - --
66 | # | | | | | | +-- Prüfsumme (Summe über alley Bytes ohne die 41; [hex]5+0+1+55+25+2 = [dez]5+0+1+(5x16)+5+(2x16)+5+2 = 130dez = 82hex
67 | # | | | | | +----- XX Anzahl der Bytes, die in der Antwort erwartet werden
68 | # | | | | +--------- XX XX 2 byte Adresse der Daten oder Prozedur
69 | # | | | +------------- XX 01 = ReadData, 02 = WriteData, 07 = Function Call
70 | # | | +--------------- XX 00 = Anfrage, 01 = Antwort, 03 = Fehler
71 | # | +----------------- Länge der Nutzdaten (Anzahl der Bytes zwischen dem Telegramm-Start-Byte (0x41) und der Prüfsumme)
72 | # +------------------- Telegramm-Start-Byte
73 | #
74 | # --> Empfangen 6 41 7 1 1 55 25 2 EF 0 74
75 | # - -- - - - ----- - ---- --
76 | # | | | | | | | | +-- Prüfsumme (Summe über alley Bytes ohne die 41; [hex]7+1+1+55+25+2+EF+0 = [dez]7+1+1+(5x16)+5+(2x16)+5+2+(14*16)+(15*16)+0 = [dez]7+1+1+(80)+5+(32)+5+2+(224)+(15)+0 = 372dez = 1.74hex)
77 | # | | | | | | | +------ Wert
78 | # | | | | | | +---------- XX Anzahl der Bytes, die in der Antwort erwartet werden
79 | # | | | | | +-------------- XX XX 2 byte Adresse der Daten oder Prozedur
80 | # | | | | +------------------ XX 01 = ReadData, 02 = WriteData, 07 = Function Call
81 | # | | | +-------------------- XX 00 = Anfrage, 01 = Antwort, 03 = Fehler
82 | # | | +---------------------- Länge der Nutzdaten (Anzahl der Bytes zwischen dem Telegramm-Start-Byte (0x41) und der Prüfsumme)
83 | # | +------------------------ Telegramm-Start-Byte
84 | # +--------------------------- OK (Antwort auf 0x16 0x00 0x00 und auf korrekt empfangene Telegramme)
85 | #
86 | # --> Antwort: 0x00EF = 239 = 23.9°
87 |
88 | # Telegram type
89 | tTypes = {'request': b'\x00',
90 | 'response': b'\x01',
91 | 'error': b'\x03', }
92 | # Telegram mode
93 | tModes = {'read': b'\x01',
94 | 'write': b'\x02',
95 | 'call': b'\x07'}
96 | tStartByte = b'\x41'
97 |
98 | def __init__(self, vc: viCommand, tMode='Read', tType='Request', payload=bytearray(0)):
99 | # creates a telegram for sending as a combination of header, viCommand, payload and checksum
100 | # payload is optional, usually of type viData
101 | # tType and tMode must be strings or bytes. Be careful when extracting from bytearray b - b[x] will be int not byte!
102 | self.vicmd = vc
103 | self.tType = self.tTypes[tType.lower()] if type(tType) == str else tType # translate to byte or use raw value
104 | self.tMode = self.tModes[tMode.lower()] if type(tMode) == str else tMode # translate to byte or use raw value
105 | self.payload = payload # fixme payload length not validated against expected length by command unit
106 | # fixme: no payload for read commands
107 |
108 | # -- create bytearray representation
109 | b = self._header() + self.vicmd + self.payload
110 | super().__init__(b + self._checksum_byte(b))
111 |
112 | def _header(self):
113 | """ Create viTelegram header"""
114 | # 1 byte - type
115 | # 1 byte - mode
116 | #
117 | # Data length (bytes): type (1), mode (1), command code (x), payload viData (x)
118 | data_length = 2 + len(self.vicmd) + len(self.payload)
119 | return self.tStartByte + data_length.to_bytes(1, 'big') + self.tType + self.tMode
120 |
121 | @property
122 | def response_length(self):
123 | # length of response telegram in bytes
124 | # 1 - Startbyte
125 | # 1 - length of data from (excluding) startbyte until (excluding) checksum
126 | # 1 - type
127 | # 1 - mode
128 | # x - command
129 | # 1 - checksum
130 | return 4 + self.vicmd.response_length(self.telegram_mode) + 1
131 |
132 | @property
133 | def telegram_mode(self):
134 | # returns mode (read, write, function call)
135 | return next(key for key, value in self.tModes.items() if value == self.tMode)
136 |
137 | @property
138 | def telegram_type(self):
139 | # Request/response/Error
140 | return next(key for key, value in self.tTypes.items() if value == self.tType)
141 |
142 | @classmethod
143 | def from_bytes(cls, b: bytearray):
144 | # parses a byte array and returns the corresponding telegram with properties vicmd etc.
145 | # when parsing a response telegram, the first byte (ACK Acknowledge) must be stripped first
146 | # Telegram bytes are [0:4]->header, [4:6]->command code, [6]->payload length, [7:-2]-> payload, [-1]:-> checksum
147 | # header bytes are [0]-> Startbyte, [1]:total value byte length,[2]: type, [3] mode
148 |
149 | # validate checksum
150 | if b[-1:] != viTelegram._checksum_byte(b[0:-1]):
151 | raise viTelegramException(
152 | f'Checksum not valid. Expected {b[-1:]}, Calculated {viTelegram._checksum_byte(b[0:-1])}')
153 | # validate Startbyte
154 | if b[0:1] != cls.tStartByte:
155 | raise viTelegramException('Startbyte not found')
156 |
157 | header = b[0:4]
158 | logging.debug(
159 | f'Header: {header.hex()}, tType={header[2:3].hex()}, tMode={header[3:4].hex()}, payload={b[7:-1].hex()}')
160 | vicmd = viCommand._from_bytes(b[4:6])
161 | vt = viTelegram(vicmd, tType=header[2:3], tMode=header[3:4], payload=b[7:-1])
162 | return vt
163 |
164 | @classmethod
165 | def _checksum_byte(cls, packet):
166 | # checksum is the last byte of the sum of all bytes in packet
167 | checksum = 0
168 | if len(packet) == 0:
169 | logging.error('No bytes received to calculate checksum')
170 | elif packet[0:1] != cls.tStartByte:
171 | logging.error('bytes to calculate checksum from does not start with start byte')
172 | else:
173 | checksum = sum(packet[1:]) % 256
174 | return checksum.to_bytes(1, 'big')
175 |
--------------------------------------------------------------------------------
/pyvcontrol/viTools.py:
--------------------------------------------------------------------------------
1 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
2 | # Copyright 2021 Jochen Schmähling
3 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
4 | # Tools for communication with viControl heatings using the serial Optolink interface
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see .
18 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
19 |
20 | from pyvcontrol.viControl import viControl, viTelegram, ctrlcode, viControlException
21 | import logging
22 | import curses
23 | import time
24 |
25 |
26 | def viscancommands(addressrange):
27 | # brute force command scanner
28 | # hilft v.a. um die richtige Payload-Länge für bekannte Kommandos herauszufinden
29 |
30 | logging.basicConfig(filename='scancommands.log', filemode='w', level=logging.DEBUG)
31 |
32 | vo = viControl()
33 | vo.initialize_communication()
34 |
35 | for addr in addressrange:
36 | for kk in range(1, 5):
37 | # TODO: Inneren Teil ausschneiden und in separate Funktion? ("low level read command")
38 | logging.debug(f'---{hex(addr)}-{kk}------------------')
39 | vc = addr.to_bytes(2, 'big') + kk.to_bytes(1, 'big')
40 | vt = viTelegram(vc, 'read') # create read Telegram
41 | vo.vs.send(vt) # send Telegram
42 | logging.debug(f'Send telegram {vt.hex()}')
43 |
44 | try:
45 | # Check if sending was successfull
46 | ack = vo.vs.read(1)
47 | if ack != ctrlcode['acknowledge']:
48 | logging.debug(f'Viessmann returned {ack.hex()}')
49 | vo.initialize_communication()
50 | raise viControlException(f'Expected acknowledge byte, received {ack}')
51 |
52 | # Receive response and evaluate data
53 | vr1 = vo.vs.read(2) # receive response
54 | vr2 = vo.vs.read(vr1[1] + 1) # read rest of telegram
55 | # FIXME: create Telegram instead of low-level access (for better readability)
56 | logging.debug(f'received telegram {vr1.hex()} {vr2.hex()}')
57 |
58 | if vr2[0].to_bytes(1, 'little') == viTelegram.tTypes['response']:
59 | v = int.from_bytes(vr2[-1 - kk:-1], 'little')
60 | print(f'Found working command 0x{hex(addr)}, payload length {kk}, value {v}')
61 |
62 |
63 | except Exception as e:
64 | logging.error({e})
65 | print(f'An exception occurred: {e}')
66 |
67 |
68 | def vimonitor(command_list, updateinterval=30):
69 | # repeatedly executes commands
70 | # commandlist is a list of strings (command names from viCommand)
71 |
72 | # TODO: accept also addresses & length as commands
73 | # Option 1) "Generic command" based on addr and length 2) add command to command set first
74 | if not isinstance(command_list, list):
75 | # wrap single commands into a list
76 | command_list = [command_list]
77 |
78 | logging.basicConfig(filename='Monitor.log', filemode='w', level=logging.DEBUG)
79 | vo = viControl()
80 |
81 | standard_screen = curses.initscr()
82 | curses.noecho()
83 | curses.cbreak()
84 | standard_screen.nodelay(True)
85 |
86 | loop_monitor = True
87 | while loop_monitor:
88 | standard_screen.clear()
89 | standard_screen.addstr(0, 0, 'Reading values...')
90 | standard_screen.refresh()
91 | standard_screen.addstr(1, 0, "--- Viessmann monitor ---\n")
92 | try:
93 | vo.initialize_communication()
94 | for c in command_list:
95 | v = vo.execReadCmd(c).value
96 | standard_screen.addstr(f"{c}: ", curses.A_BOLD)
97 | standard_screen.addstr(f"{v}\n")
98 | except Exception as e:
99 | standard_screen.addstr(f'Error: {e}')
100 |
101 | standard_screen.addstr('\n-----------------------\nPress any key to abort')
102 | for k in range(updateinterval):
103 | time.sleep(1)
104 | standard_screen.addstr(0, 0, f"[Update in {updateinterval - k}s] ")
105 | standard_screen.refresh()
106 | if standard_screen.getch() > 0:
107 | loop_monitor = False
108 | break
109 |
110 | curses.nocbreak()
111 | curses.echo()
112 | curses.endwin()
113 |
114 |
115 | def vi_scan_function_call(commandname, functionrange):
116 | # scans the function call with all parameters and print HEX and decoded OUTPUT in terminal
117 |
118 | vo = viControl()
119 | vo.initialize_communication()
120 |
121 | for func in functionrange: # First Parameter is Byte
122 | print(f"==========Function # {func}===========")
123 | for day in range(0, 6):
124 | try:
125 | print(vo.execFunctionCall(commandname, func, day).valueScan)
126 | except Exception as e:
127 | logging.error({e})
128 | print(f'Day {day}: An exception occurred: {e}')
129 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | from setuptools import setup
2 |
3 | setup(name='pyvcontrol',
4 | version='1.4.5',
5 | description='Communication with Viessmann heating via Optolink interface.',
6 | url='http://github.com/',
7 | author='Jochen Schmaehling',
8 | author_email='j_ochen_573@freenet.de',
9 | packages=['pyvcontrol'],
10 | zip_safe=False,
11 | install_requires=['pyserial', 'pyyaml', 'deprecated'],
12 | classifiers=[
13 | # 3 - Alpha
14 | # 4 - Beta
15 | # 5 - Production/Stable
16 | 'Development Status :: 4 - Beta',
17 |
18 | # Indicate who your project is intended for
19 | 'Intended Audience :: Developers',
20 | 'Topic :: Software Development :: Build Tools',
21 |
22 | 'License :: OSI Approved :: GPL-3',
23 |
24 | # Specify the Python versions you support here. In particular, ensure
25 | # that you indicate whether you support Python 2, Python 3 or both.
26 | 'Programming Language :: Python :: 3.7',
27 | 'Programming Language :: Python :: 3.8',
28 | ],
29 | )
30 |
--------------------------------------------------------------------------------
/tests/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joppi588/pyvcontrol/06c5c473bcc69c7c943744d953404e354d2de44e/tests/__init__.py
--------------------------------------------------------------------------------
/tests/testViCommand.py:
--------------------------------------------------------------------------------
1 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
2 | # Copyright 2021 Jochen Schmähling
3 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
4 | # Python Module for communication with viControl heatings using the serial Optolink interface
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see .
18 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
19 |
20 | import unittest
21 | from pyvcontrol.viCommand import viCommand,viCommandException
22 | from pyvcontrol.viData import viData
23 |
24 |
25 | class testViCommand(unittest.TestCase):
26 |
27 | def test_vicmdnomatch(self):
28 | # Command not existing
29 | with self.assertRaises(viCommandException):
30 | vc = viCommand._from_bytes(b'\xF1\x00')
31 | with self.assertRaises(viCommandException):
32 | vc = viCommand('foo')
33 |
34 | def test_vicmdfrombytes(self):
35 | # create command from raw bytes
36 | vc = viCommand._from_bytes(b'\x00\xf8')
37 | self.assertEqual(vc.command_name, 'Anlagentyp')
38 |
39 | def test_vicmdAnlagentyp(self):
40 | # create command from string
41 | vc = viCommand('Anlagentyp')
42 | self.assertEqual(vc.hex(), '00f804')
43 |
44 | def test_vicmdWWeinmal(self):
45 | # create command from string
46 | vc = viCommand('WWeinmal')
47 | self.assertEqual(vc.hex(), 'b02001')
48 |
49 | def test_vicmdAussentemperatur(self):
50 | # create command from string
51 | vc = viCommand('Aussentemperatur')
52 | self.assertEqual(vc.hex(), '010102')
53 |
54 | def test_vicmdWarmwassertemperatur(self):
55 | # create command from string
56 | vc = viCommand('Warmwassertemperatur')
57 | self.assertEqual(vc.hex(), '010d02')
58 |
59 | def test_vicmdBetriebsmodus(self):
60 | #Given: When: Then: Correct viData is returned
61 | vc = viCommand('Betriebsmodus')
62 | self.assertEqual(vc.unit,'BA')
63 |
64 | if __name__ == '__main__':
65 | unittest.main()
66 |
--------------------------------------------------------------------------------
/tests/testViControl.py:
--------------------------------------------------------------------------------
1 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
2 | # Copyright 2022 Jochen Schmähling
3 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
4 | # Python Module for communication with viControl heatings using the serial Optolink interface
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see .
18 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
19 |
20 | # test cases for class viControl
21 |
22 | import unittest
23 | from unittest.mock import patch
24 | from pyvcontrol.viControl import viControl, viControlException, control_set, ctrlcode
25 |
26 |
27 | class MockViSerial:
28 |
29 | def __init__(self):
30 | self._connected = False
31 | self._control_set = control_set
32 | self._serial_port = ''
33 | self._serial = []
34 | self.sink = bytearray(0)
35 | self.source = bytearray(0)
36 | self.source_cursor = 0
37 |
38 | def connect(self):
39 | self._connected = True
40 | self.sink = bytearray(0)
41 |
42 | def disconnect(self):
43 | self._connected = False
44 |
45 | def send(self, payload):
46 | self.sink = self.sink + bytearray(payload)
47 | print(f"received {payload}, in total received {self.sink}")
48 |
49 | def read(self, length):
50 | answer = self.source[self.source_cursor:self.source_cursor + length]
51 | self.source_cursor += length
52 | return answer
53 |
54 |
55 | class TestViControl(unittest.TestCase):
56 |
57 | @patch('pyvcontrol.viControl.viSerial', return_value=MockViSerial())
58 | def test_exec_forbidden_write_command(self, mock1):
59 | mock1.return_value.source = ctrlcode['acknowledge'] + bytes.fromhex('41 07 01 01 01 0d 02 65 00 7e')
60 | vc = viControl()
61 | with self.assertRaises(viControlException):
62 | vc.execute_write_command('Warmwassertemperatur', 5)
63 |
64 | @patch('pyvcontrol.viControl.viSerial', return_value=MockViSerial())
65 | def test_exec_write_command(self, mock1):
66 | mock1.return_value.source = ctrlcode['acknowledge'] + bytes.fromhex('41 07 01 01 01 0d 02 19 00 7e')
67 | vc = viControl()
68 | vc.execute_write_command('SolltempWarmwasser', 35)
69 |
70 | @patch('pyvcontrol.viControl.viSerial', return_value=MockViSerial())
71 | def test_exec_read_command(self, mock1):
72 | mock1.return_value.source = ctrlcode['acknowledge'] + bytes.fromhex('41 07 01 01 01 0d 02 65 00 7e')
73 | vc = viControl()
74 | data = vc.execute_read_command('Warmwassertemperatur')
75 | self.assertEqual(data.value, 10.1)
76 |
77 | @patch('pyvcontrol.viControl.viSerial', return_value=MockViSerial())
78 | def test_exec_function_call(self, mock1):
79 | vc = viControl()
80 | self.assertFalse(True)
81 |
82 | @patch('pyvcontrol.viControl.viSerial', return_value=MockViSerial())
83 | def test_exec_forbidden_function_call(self, mock1):
84 | mock1.return_value.source = ctrlcode['acknowledge'] + bytes.fromhex('41 07 01 01 01 0d 02 65 00 7e')
85 | vc = viControl()
86 | with self.assertRaises(viControlException):
87 | vc.execute_function_call('Warmwassertemperatur', 5)
88 |
--------------------------------------------------------------------------------
/tests/testViData.py:
--------------------------------------------------------------------------------
1 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
2 | # Copyright 2021 Jochen Schmähling
3 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
4 | # Python Module for communication with viControl heatings using the serial Optolink interface
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see .
18 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
19 |
20 | # test cases for class viData
21 |
22 | import unittest
23 | from pyvcontrol.viData import viData as vd, viDataException
24 |
25 |
26 | class viDataTestCaseBA(unittest.TestCase):
27 | def test_BAEmpty(self):
28 | # create empty class and check mode
29 | dBA = vd.create('BA')
30 | self.assertEqual(dBA.value, 'OFF') # defaults to mode 'OFF'
31 |
32 | def test_BA02raw(self):
33 | # create class with defined operation mode from raw byte
34 | dBA = vd.create('BA', b'\x02')
35 | self.assertEqual(dBA.value, 'HEATING_WW')
36 |
37 | def test_BA01(self):
38 | # create class with constructor and parameter
39 | dBA = vd.create('BA', 'WW')
40 | self.assertEqual(dBA, b'\x01')
41 |
42 | def test_BA6666Empty(self):
43 | # test call with non-existent mode
44 | with self.assertRaises(viDataException):
45 | vd.create('BA', b'\x66\x66')
46 |
47 | def test_BAfoobar(self):
48 | # test call with non-existent mode
49 | with self.assertRaises(viDataException):
50 | vd.create('BA', 'foobar')
51 |
52 |
53 | class viDataTestCaseDT(unittest.TestCase):
54 | def test_DTempty(self):
55 | # initialize empty device type (standard)
56 | dDT = vd.create('DT')
57 | self.assertEqual(dDT.value, 'unknown')
58 |
59 | def test_DTraw(self):
60 | # initialize from raw data
61 | dDT = vd.create('DT', b'\x20\x4D')
62 | self.assertEqual(dDT.value, 'V200WO1C, Protokoll: P300')
63 |
64 | def test_DTstr(self):
65 | dDT = vd.create('DT', 'unknown')
66 | self.assertEqual(dDT, b'\x00\x00')
67 |
68 |
69 | class viDataTestCaseIS10(unittest.TestCase):
70 | def test_IS10(self):
71 | dIS10 = vd.create('IS10', 10.15)
72 | self.assertEqual(dIS10.value, 10.1)
73 |
74 | def test_IS10raw(self):
75 | dIS10 = vd.create('IS10', b'e\x00')
76 | self.assertEqual(dIS10.value, 10.1)
77 |
78 | def test_IS10minus(self):
79 | f = -9.856
80 | dIS10 = vd.create('IS10', f)
81 | print(f'Hex representation of {f} is {dIS10.hex()}')
82 | self.assertEqual(dIS10.value, -9.8)
83 |
84 | # TODO add test playing with different len arguments and limit values
85 |
86 |
87 | class viDataTestCaseIUNON(unittest.TestCase):
88 | def test_IUNON(self):
89 | f = 415
90 | dIUNON = vd.create('IUNON', f)
91 | print(f'Hex representation of {f} is {dIUNON.hex()}')
92 | self.assertEqual(dIUNON.value, f)
93 |
94 | def test_IUNONraw(self):
95 | dIUNON = vd.create('IUNON', b'\x9f\x01')
96 | self.assertEqual(dIUNON.value, 415)
97 |
98 |
99 | class viDataTestCaseOO(unittest.TestCase):
100 | def test_OO(self):
101 | f = 'On'
102 | dOO = vd.create('OO', f)
103 | print(f'Hex representation of {f} is {dOO.hex()}')
104 | self.assertEqual(dOO.value, f)
105 |
106 | def test_OOraw(self):
107 | dOO = vd.create('OO', b'\x02')
108 | self.assertEqual(dOO.value, 'On')
109 |
110 | def test_OO_unknown_value(self):
111 | with self.assertRaises(viDataException):
112 | dOO = vd.create('OO', 'foo')
113 |
114 | def test_OO_default_value(self):
115 | dOO = vd.create('OO')
116 | self.assertEqual(dOO.value, 'Off')
117 |
118 |
119 | class viDataTestCaseEnergy(unittest.TestCase):
120 | def test_default(self):
121 | data_energy = vd.create('F_E')
122 | self.assertEqual(data_energy.day, 0)
123 | self.assertEqual(data_energy.week, 0)
124 | self.assertEqual(data_energy.year, 2000)
125 | self.assertEqual(data_energy.water_energy, 0)
126 | self.assertEqual(data_energy.heating_energy, 0)
127 | self.assertEqual(data_energy.cooling_energy, 0)
128 | self.assertEqual(data_energy.water_electrical_energy, 0)
129 | self.assertEqual(data_energy.heating_electrical_energy, 0)
130 | self.assertEqual(data_energy.cooling_electrical_energy, 0)
131 |
132 | def test_typical_values(self):
133 | example_data = bytes.fromhex('02 02 16 09 92 03 aa 00 99 00 2d 00 00 00 00 00')
134 |
135 | data_energy = vd.create('F_E', example_data)
136 | value_dictionary = data_energy.value
137 | reference_dictionary = {
138 | 'day': 2,
139 | 'week': 9,
140 | 'year': 2022,
141 | 'heating_energy': 91.4,
142 | 'heating_electrical_energy': 17.0,
143 | 'water_energy': 15.3,
144 | 'water_electrical_energy': 4.5,
145 | 'cooling_energy': 91.4,
146 | 'cooling_electrical_energy': 17.0,
147 | 'total_energy': 91.4 + 15.3 + 91.4,
148 | 'total_electrical_energy': 38.5,
149 | }
150 |
151 | self.assertEqual(value_dictionary, reference_dictionary)
152 |
153 | def test_failed_init(self):
154 | example_data = 1.2
155 | with self.assertRaises(viDataException):
156 | vd.create('F_E', example_data)
157 |
158 |
159 | if __name__ == '__main__':
160 | unittest.main()
161 |
--------------------------------------------------------------------------------
/tests/testViTelegram.py:
--------------------------------------------------------------------------------
1 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
2 | # Copyright 2021 Jochen Schmähling
3 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
4 | # Python Module for communication with viControl heatings using the serial Optolink interface
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see .
18 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
19 |
20 |
21 | import unittest
22 | from pyvcontrol import viControl as v, viCommand as c
23 | from pyvcontrol.viData import viData as d
24 | from pyvcontrol.viTelegram import viTelegramException
25 |
26 |
27 | class testviTelegram(unittest.TestCase):
28 | def test_readTelegram(self):
29 | vc = c.viCommand('Anlagentyp')
30 | vt = v.viTelegram(vc, 'read')
31 | self.assertEqual('4105000100f80402', vt.hex())
32 | vc = c.viCommand('Warmwassertemperatur')
33 | vt = v.viTelegram(vc, 'read')
34 | self.assertEqual('41050001010d0216', vt.hex())
35 |
36 | def test_checksumEmpty(self):
37 | # raise error
38 | b = bytes(0)
39 | c = v.viTelegram._checksum_byte(b)
40 | self.assertEqual(b'\x00', c)
41 |
42 | def test_checksumStartbyte(self):
43 | # raise error
44 | c = v.viTelegram._checksum_byte(b'\x42\x41')
45 | self.assertEqual(b'\x00', c)
46 |
47 |
48 | class testviTelegram_resp(unittest.TestCase):
49 | def test_wrongchecksum(self):
50 | b = bytes.fromhex('4105000100f80201')
51 | with self.assertRaises(viTelegramException):
52 | vt = v.viTelegram.from_bytes(b)
53 |
54 | def test_telegramtype(self):
55 | b = bytes.fromhex('41 05 00 01 01 0d 02 00 00 16')
56 | vt = v.viTelegram.from_bytes(b)
57 | self.assertEqual(vt.telegram_mode, 'read')
58 | b = bytes.fromhex('41 05 00 02 01 0d 02 00 00 17')
59 | vt = v.viTelegram.from_bytes(b)
60 | self.assertEqual(vt.telegram_mode, 'write')
61 | b = bytes.fromhex('41 05 00 07 01 0d 02 00 00 1c')
62 | vt = v.viTelegram.from_bytes(b)
63 | self.assertEqual(vt.telegram_mode, 'call')
64 |
65 | def test_telegramtype(self):
66 | b = bytes.fromhex('41 05 00 01 01 0d 02 00 00 16')
67 | vt = v.viTelegram.from_bytes(b)
68 | self.assertEqual(vt.telegram_type, 'request')
69 | b = bytes.fromhex('41 05 01 02 01 0d 02 00 00 18')
70 | vt = v.viTelegram.from_bytes(b)
71 | self.assertEqual(vt.telegram_type, 'response')
72 | b = bytes.fromhex('41 05 03 07 01 0d 02 00 00 1f')
73 | vt = v.viTelegram.from_bytes(b)
74 | self.assertEqual(vt.telegram_type, 'error')
75 |
76 | def test_telegramdata1(self):
77 | b = bytes.fromhex('41 07 01 01 01 0d 02 65 00 7e')
78 | vt = v.viTelegram.from_bytes(b)
79 | vd = d.create(vt.vicmd.unit, vt.payload)
80 | self.assertEqual(vt.vicmd.unit, 'IS10')
81 | self.assertEqual(vd.value, 10.1)
82 |
83 | def test_telegramdata2(self):
84 | # 'Read' telegram
85 | b = bytes.fromhex('41 09 01 01 16 50 04 e4 29 00 00 82')
86 | vt = v.viTelegram.from_bytes(b)
87 | vd = d.create(vt.vicmd.unit, vt.payload)
88 | self.assertEqual('read', vt.telegram_mode)
89 | self.assertEqual(12, vt.response_length)
90 | self.assertEqual(vt.vicmd.command_name, 'WWwaerme')
91 | self.assertEqual(vt.vicmd.unit, 'IUNON')
92 | self.assertEqual(vd.value, 10724)
93 |
94 | def test_telegramdata3(self):
95 | # 'write' telegram
96 | b = bytes.fromhex('41 09 01 02 16 50 04 76')
97 | vt = v.viTelegram.from_bytes(b)
98 | vd = d.create(vt.vicmd.unit, vt.payload)
99 | self.assertEqual('write', vt.telegram_mode)
100 | self.assertEqual(8, vt.response_length)
101 | self.assertEqual(vt.vicmd.command_name, 'WWwaerme')
102 | self.assertEqual(vt.vicmd.unit, 'IUNON')
103 |
104 |
105 | if __name__ == '__main__':
106 | unittest.main()
107 |
--------------------------------------------------------------------------------
/tests/testViTools.py:
--------------------------------------------------------------------------------
1 | import unittest
2 | from unittest.mock import patch
3 | from pyvcontrol.viControl import viControl
4 | from pyvcontrol.viTools import vimonitor
5 | from viControlMock import viControlMock
6 |
7 |
8 | class testviTools(unittest.TestCase):
9 |
10 | @patch('pyvcontrol.viTools.viControl', return_value=viControlMock())
11 | def test_monitor(self, mock1):
12 | vimonitor(['Warmwassertemperatur', 'VorlauftempSek'])
13 | self.assertEqual(True, True) # add assertion here
14 |
15 | @patch('pyvcontrol.viTools.viControl', return_value=viControlMock())
16 | def test_monitor_unknown_command(self, mock1):
17 | vimonitor(['Warmwassertemperatur', 'Vorlauftemperatur'])
18 | self.assertEqual(True, True) # add assertion here
19 |
20 |
21 | if __name__ == '__main__':
22 | unittest.main()
23 |
--------------------------------------------------------------------------------
/tests/testViessmann.py:
--------------------------------------------------------------------------------
1 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
2 | # Copyright 2021 Jochen Schmähling
3 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
4 | # Python Module for communication with viControl heatings using the serial Optolink interface
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see .
18 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
19 |
20 | # Tests the connection to Viessmann. Needs a physical connection
21 |
22 | import unittest
23 | import logging
24 | from pyvcontrol.viControl import viControl
25 | from pyvcontrol.viCommand import viCommand
26 |
27 |
28 | class MyTestCase(unittest.TestCase):
29 | def test_readsequence(self):
30 | vo = viControl()
31 | vo.initialize_communication()
32 |
33 | for cmd in viCommand.command_set.keys():
34 | vd = vo.execReadCmd(cmd)
35 | print(f'{cmd} : {vd.value}')
36 |
37 | def test_readonly(self):
38 | pass
39 |
40 | def test_writesequence(self):
41 | # Ändert einen Datensatz und stellt ursprüngl. Wert wieder her
42 | vo = viControl()
43 | vo.initialize_communication()
44 | cmd = 'RaumsolltempParty'
45 | v_orig = vo.execReadCmd(cmd).value
46 |
47 | vdw = vo.execWriteCmd(cmd, v_orig + 1)
48 | vdr = vo.execReadCmd(cmd)
49 | print(f'Read {cmd} : {vdr.value}')
50 | self.assertEqual(v_orig + 1, vdr.value)
51 |
52 | vdw = vo.execWriteCmd(cmd, v_orig)
53 | vdr = vo.execReadCmd(cmd)
54 | print(f'Read {cmd} : {vdr.value}')
55 | self.assertEqual(v_orig, vdr.value)
56 |
57 |
58 | if __name__ == '__main__':
59 | logging.basicConfig(filename='testViessmann.log', filemode='w', level=logging.DEBUG)
60 | unittest.main()
61 |
--------------------------------------------------------------------------------
/tests/viControlMock.py:
--------------------------------------------------------------------------------
1 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
2 | # Copyright 2021-2022 Jochen Schmähling
3 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
4 | # Python Module for communication with viControl heatings using the serial Optolink interface
5 | #
6 | # This program is free software: you can redistribute it and/or modify
7 | # it under the terms of the GNU General Public License as published by
8 | # the Free Software Foundation, either version 3 of the License, or
9 | # (at your option) any later version.
10 | #
11 | # This program is distributed in the hope that it will be useful,
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | # GNU General Public License for more details.
15 | #
16 | # You should have received a copy of the GNU General Public License
17 | # along with this program. If not, see .
18 | # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
19 |
20 | # Provides a mock class to simulate the behavior of viControl class on a machine not connected to Viessmann
21 | # Usage: @patch('pyvcontrol.viTools.viControl', return_value=viControlMock())
22 |
23 |
24 | from pyvcontrol.viData import viData
25 | from pyvcontrol.viCommand import viCommand
26 | import random
27 |
28 |
29 | class viControlMock:
30 | def initialize_communication(self):
31 | return True
32 |
33 | def execute_read_command(self, cmdName):
34 | vc = viCommand(cmdName)
35 | return viData.create('IUNON', random.randint(0, 50))
36 |
37 | def execute_write_command(self, cmdName, value):
38 | vc = viCommand(cmdName)
39 | return None
40 |
--------------------------------------------------------------------------------