summaryrefslogtreecommitdiff
path: root/python-elkm1-lib.spec
blob: 03924bedb92514b81992f2244247a3d13254e9f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
%global _empty_manifest_terminate_build 0
Name:		python-elkm1-lib
Version:	2.2.2
Release:	1
Summary:	Library for interacting with ElkM1 alarm/automation panel.
License:	MIT
URL:		https://github.com/gwww/elkm1
Source0:	https://mirrors.nju.edu.cn/pypi/web/packages/a9/38/7742fe806c0bd5dc1d314556f264bd48f29328194a1149ba7db55c41c943/elkm1_lib-2.2.2.tar.gz
BuildArch:	noarch

Requires:	python3-async-timeout
Requires:	python3-pyserial-asyncio

%description
# Python ElkM1 library

[![PyPI version](https://badge.fury.io/py/elkm1-lib.svg)](https://badge.fury.io/py/elkm1-lib)
[![CI](https://github.com/gwww/elkm1/actions/workflows/code-quality.yml/badge.svg)](https://github.com/gwww/elkm1/actions/workflows/code-quality.yml)
[![Downloads](https://pepy.tech/badge/elkm1-lib)](https://pepy.tech/project/elkm1-lib)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://pypi.org/project/elkm1_lib/)

Library for interacting with ElkM1 alarm/automation panel.

https://github.com/gwww/elkm1

## Requirements

- Python 3.9 (or higher)

## Description

This package is created as a library to interact with an ElkM1 alarm/automation
pattern. The motivation to write this was to use with the Home Assistant
automation platform. The library can be used for writing other ElkM1 integration
applications. The IO with the panel is asynchronous over TCP or over the
serial port.

## Installation

```bash
    $ pip install elkm1_lib
```

## Overview

Basic connection to the Elk panel:

```python
    from elkm1_lib import Elk
    import logging

    # Print to STDOUT
    LOG = logging.getLogger(__name__)
    logging.basicConfig(level=logging.DEBUG, format='%(message)s')

    # Connect to elk
    elk = Elk({'url': 'elk://192.168.1.100'})
    elk.connect()
    elk.run()
```

The above will connect to the Elk panel at IP address 192.168.1.100. the `elk://`
prefix specifies that the connect is plaintext. Alternatively, `elks://` will
connect over TLS. In this case a userid and password must be specified
and the call to `Elk` changes to:

```python
    elk = Elk(
        {'url': 'elks://192.168.1.100', 'userid': 'test', 'password': 'pass'}
    )
```

The following ElkM1 connection protocols are supported:
- serial:// - Serial port;
- elk:// - Elk M1XEP Ethernet, non-secure
- elks:// - Elk M1XEP Ethernet, secure, TLS 1.0
- elksv1_0:// - Elk M1XEP Ethernet, secure, TLS 1.0, supported on M1XEP version < 2.0.46
- elksv1_2:// - Elk M1XEP Ethernet, secure, TLS 1.2, supported on M1XEP version = 2.0.46
- elksv1_3:// - Elk M1XEP Ethernet, secure, TLS 1.2, not yet supported on M1XEP, reserved for future

A username and password are required for any of the secure modes.

To see working example code take a look at the script `bin/simple`.

The `Elk` object supports the concept of `Elements`. An `Element`
is the base class representation of `Zones`, `Lights`, etc. So, for
example there is a list of zones: `elk.zones` and each zone can be
accessed by `elk.zones[index]`. Each element has a `__str__`
representation so that it is easy to print its contents.

All `Elements` are referenced starting at 0. Even though the Elk panel
refers to, for example, zones 1-208, the library references them
as zones 0-207. All translation from base 0 to 1 and vice-versa is
handled internally in the `elkm1_lib.message` module.

After creating the `Elk` object and connecting to the panel the
library code will synchronize all the elements to the data from the Elk panel.

Many Elk messages are handled by the library, caching their contents. When a
message causes a change to an attribute of an `Element`, registered
callbacks are called so that user use of the library can be notified
of changing elements. The following user code shows registering a callback:

```python
    def call_me(element, changeset):
       print(changeset)

    for zone_number in range(Max.ZONES.value):
      elk.zones[zone_number].add_callback(call_me)
```

The library encodes, decodes, and processes messages to/from the
Elk panel. All the encoding and decoding is done in `elkm1_lib.message` module.

Messages received are handled with callbacks. The library
internally registers callbacks so that decoded messages
can be used to update an `Element`. The user of the
library may also register callbacks. Any particular message
may have multiple callbacks.

When the message is received it is decoded
and some validation is done. The message handler is called
with the fields of from the decoded message. Each type of
message has parameters that match the message type. All handler parameters
are named parameters.

Here is an example of a message handler being registered and how it is called:

```python
    def zone_status_change_handler(zone_number, zone_status):
      print(zone_number, zone_status)

    elk.add_handler('ZC', zone_status_change_handler)
```

The above code registers a callback for 'ZC' (Elk zone status change)
messages. When a ZC message is received the handler functions are called
with the zone_number and zone_status.

There are a number of pseudo-handlers that act like the handlers. These are
called when events happen. The pseudo-handlers are:

- `connect`: When a successful connection to the ElkM1 is completed.
- `disconnect`: When a connection to a panel is disconnected.
- `login`: When a login is made to the panel (using `elks://` connection mode.
  A single boolean parameter is passed `succeeded`.
- `sync_complete`: When the panel has completed synchonizing all its elements.
- `timeout`: When a send of a message to the ElkM1 times out (fails to send).
- `unknown`: When a message from the ElkM1 is received and the library does
  not have a method to decode the message. The message is passed to this handler
  and can be decoded outside of the library.

## Utilities

The `bin` directory of the library has one utility program and
a couple of example uses of the library.

### `mkdoc`

The utility `mkdoc` creates a Markdown table of the list of Elk
messages with a check mark for those messages have encoders/decoders
and an X for those messages are not planned to be implemented.
There are no parameters to `mkdoc`. It outputs to stdout.
The data for the report comes from the ElkM1 library code mostly.
A couple of things are hard coded in the mkdoc script, notably
the "no plans to implement" list.

### `simple`

The `simple` Python script is a trivial use of the ElkM1 library.
It connects to the panel, syncs to internal memory, and continues
listening for any messages from the panel. The URL of the ElkM1 to
connect to is retrieved from an environment variable named `ELKM1_URL`.

### `elk`

The `elk` Python script is a bit of a command interpretor. It can run in
two modes. Non-interactive mode is the default. Just run the `elk` command.
The non-interactive mode is similar to `simple` except there are a
couple of message handlers (`timeout` and `unknown` handlers).

The `elk` can also be run in interactive mode by invoking it by
`elk -i`. In this mode is uses curses (full screen use of the terminal)
that has a command line and an output window. `TAB` switches between
the command line and output windows. In the output window the arrow keys
and scrollwheel scroll the contents of the window.

In the command line when running `elk -i` there are a
number of commands. Start with `help`. Then `help <command>` for
details on each command. In general there are commands to dump the internal
state of elements and to invoke any of the encoders to send a message
to the Elk panel.

For example, `light <4, 8, 12-14` would invoke the `__str__` method
for the light element to print the cached info for lights 0-3, 8, and 12-14.

Another example would be `pf 3` which issues the pf (Turn light off)
command for light number 3 (light 4 on the panel -- remember 0
versus 1 base).

All of the commands that send messages to the panel are automatically
discovered and are all the XX_encode functions in the ``elkm1_lib.message``
module. The docstring and the XX_encode's parameters are shown as part
of the help.

## Development

This project uses [poetry](https://poetry.eustace.io/) for development dependencies. Installation instructions are on their website.

To get started developing:

```
git clone https://github.com/gwww/elkm1.git
cd elkm1
poetry install
poetry shell # Or activate the created virtual environment
make test # to ensure everything installed properly
```

There is a `Makefile` in the root directory as well. The `make` command
followed by one of the targets in the `Makefile` can be used. If you don't
have or wish to use `make` the `Makefile` serves as examples of common
commands that can be run.

## Reporting a Bug

No problem ;) — report the bugs! But, logs are most often required. If you
are using Home Assistant, which is about the only use I'm aware of for
this library, then add the following to your `configuration.yaml`:
```
logger:
  default: info
  logs:
    custom_components.elkm1: debug
    elkm1_lib: debug
```

Do everything in your power to trim to logs down to their smallest. One way is
to reproduce your problem quickly so that few other logs are not generated in
between. Another recommendation is to use the simplest configuration that you
can think of to reproduce the problem.

Can you reproduce the problem in other ways? If this is a problem that is
being experienced while using Home Assistant try using the `Services` in `Developer Tools`.

Sometime logs may have sensitive information in them. You may want to
scan your logs for that info and "X" it out. In addition, you can send logs
directly to me. Support email is in the `pyproject.toml` file. You may also
send a link to somewhere you've stored/shared the file (DropBox for example).



%package -n python3-elkm1-lib
Summary:	Library for interacting with ElkM1 alarm/automation panel.
Provides:	python-elkm1-lib
BuildRequires:	python3-devel
BuildRequires:	python3-setuptools
BuildRequires:	python3-pip
%description -n python3-elkm1-lib
# Python ElkM1 library

[![PyPI version](https://badge.fury.io/py/elkm1-lib.svg)](https://badge.fury.io/py/elkm1-lib)
[![CI](https://github.com/gwww/elkm1/actions/workflows/code-quality.yml/badge.svg)](https://github.com/gwww/elkm1/actions/workflows/code-quality.yml)
[![Downloads](https://pepy.tech/badge/elkm1-lib)](https://pepy.tech/project/elkm1-lib)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://pypi.org/project/elkm1_lib/)

Library for interacting with ElkM1 alarm/automation panel.

https://github.com/gwww/elkm1

## Requirements

- Python 3.9 (or higher)

## Description

This package is created as a library to interact with an ElkM1 alarm/automation
pattern. The motivation to write this was to use with the Home Assistant
automation platform. The library can be used for writing other ElkM1 integration
applications. The IO with the panel is asynchronous over TCP or over the
serial port.

## Installation

```bash
    $ pip install elkm1_lib
```

## Overview

Basic connection to the Elk panel:

```python
    from elkm1_lib import Elk
    import logging

    # Print to STDOUT
    LOG = logging.getLogger(__name__)
    logging.basicConfig(level=logging.DEBUG, format='%(message)s')

    # Connect to elk
    elk = Elk({'url': 'elk://192.168.1.100'})
    elk.connect()
    elk.run()
```

The above will connect to the Elk panel at IP address 192.168.1.100. the `elk://`
prefix specifies that the connect is plaintext. Alternatively, `elks://` will
connect over TLS. In this case a userid and password must be specified
and the call to `Elk` changes to:

```python
    elk = Elk(
        {'url': 'elks://192.168.1.100', 'userid': 'test', 'password': 'pass'}
    )
```

The following ElkM1 connection protocols are supported:
- serial:// - Serial port;
- elk:// - Elk M1XEP Ethernet, non-secure
- elks:// - Elk M1XEP Ethernet, secure, TLS 1.0
- elksv1_0:// - Elk M1XEP Ethernet, secure, TLS 1.0, supported on M1XEP version < 2.0.46
- elksv1_2:// - Elk M1XEP Ethernet, secure, TLS 1.2, supported on M1XEP version = 2.0.46
- elksv1_3:// - Elk M1XEP Ethernet, secure, TLS 1.2, not yet supported on M1XEP, reserved for future

A username and password are required for any of the secure modes.

To see working example code take a look at the script `bin/simple`.

The `Elk` object supports the concept of `Elements`. An `Element`
is the base class representation of `Zones`, `Lights`, etc. So, for
example there is a list of zones: `elk.zones` and each zone can be
accessed by `elk.zones[index]`. Each element has a `__str__`
representation so that it is easy to print its contents.

All `Elements` are referenced starting at 0. Even though the Elk panel
refers to, for example, zones 1-208, the library references them
as zones 0-207. All translation from base 0 to 1 and vice-versa is
handled internally in the `elkm1_lib.message` module.

After creating the `Elk` object and connecting to the panel the
library code will synchronize all the elements to the data from the Elk panel.

Many Elk messages are handled by the library, caching their contents. When a
message causes a change to an attribute of an `Element`, registered
callbacks are called so that user use of the library can be notified
of changing elements. The following user code shows registering a callback:

```python
    def call_me(element, changeset):
       print(changeset)

    for zone_number in range(Max.ZONES.value):
      elk.zones[zone_number].add_callback(call_me)
```

The library encodes, decodes, and processes messages to/from the
Elk panel. All the encoding and decoding is done in `elkm1_lib.message` module.

Messages received are handled with callbacks. The library
internally registers callbacks so that decoded messages
can be used to update an `Element`. The user of the
library may also register callbacks. Any particular message
may have multiple callbacks.

When the message is received it is decoded
and some validation is done. The message handler is called
with the fields of from the decoded message. Each type of
message has parameters that match the message type. All handler parameters
are named parameters.

Here is an example of a message handler being registered and how it is called:

```python
    def zone_status_change_handler(zone_number, zone_status):
      print(zone_number, zone_status)

    elk.add_handler('ZC', zone_status_change_handler)
```

The above code registers a callback for 'ZC' (Elk zone status change)
messages. When a ZC message is received the handler functions are called
with the zone_number and zone_status.

There are a number of pseudo-handlers that act like the handlers. These are
called when events happen. The pseudo-handlers are:

- `connect`: When a successful connection to the ElkM1 is completed.
- `disconnect`: When a connection to a panel is disconnected.
- `login`: When a login is made to the panel (using `elks://` connection mode.
  A single boolean parameter is passed `succeeded`.
- `sync_complete`: When the panel has completed synchonizing all its elements.
- `timeout`: When a send of a message to the ElkM1 times out (fails to send).
- `unknown`: When a message from the ElkM1 is received and the library does
  not have a method to decode the message. The message is passed to this handler
  and can be decoded outside of the library.

## Utilities

The `bin` directory of the library has one utility program and
a couple of example uses of the library.

### `mkdoc`

The utility `mkdoc` creates a Markdown table of the list of Elk
messages with a check mark for those messages have encoders/decoders
and an X for those messages are not planned to be implemented.
There are no parameters to `mkdoc`. It outputs to stdout.
The data for the report comes from the ElkM1 library code mostly.
A couple of things are hard coded in the mkdoc script, notably
the "no plans to implement" list.

### `simple`

The `simple` Python script is a trivial use of the ElkM1 library.
It connects to the panel, syncs to internal memory, and continues
listening for any messages from the panel. The URL of the ElkM1 to
connect to is retrieved from an environment variable named `ELKM1_URL`.

### `elk`

The `elk` Python script is a bit of a command interpretor. It can run in
two modes. Non-interactive mode is the default. Just run the `elk` command.
The non-interactive mode is similar to `simple` except there are a
couple of message handlers (`timeout` and `unknown` handlers).

The `elk` can also be run in interactive mode by invoking it by
`elk -i`. In this mode is uses curses (full screen use of the terminal)
that has a command line and an output window. `TAB` switches between
the command line and output windows. In the output window the arrow keys
and scrollwheel scroll the contents of the window.

In the command line when running `elk -i` there are a
number of commands. Start with `help`. Then `help <command>` for
details on each command. In general there are commands to dump the internal
state of elements and to invoke any of the encoders to send a message
to the Elk panel.

For example, `light <4, 8, 12-14` would invoke the `__str__` method
for the light element to print the cached info for lights 0-3, 8, and 12-14.

Another example would be `pf 3` which issues the pf (Turn light off)
command for light number 3 (light 4 on the panel -- remember 0
versus 1 base).

All of the commands that send messages to the panel are automatically
discovered and are all the XX_encode functions in the ``elkm1_lib.message``
module. The docstring and the XX_encode's parameters are shown as part
of the help.

## Development

This project uses [poetry](https://poetry.eustace.io/) for development dependencies. Installation instructions are on their website.

To get started developing:

```
git clone https://github.com/gwww/elkm1.git
cd elkm1
poetry install
poetry shell # Or activate the created virtual environment
make test # to ensure everything installed properly
```

There is a `Makefile` in the root directory as well. The `make` command
followed by one of the targets in the `Makefile` can be used. If you don't
have or wish to use `make` the `Makefile` serves as examples of common
commands that can be run.

## Reporting a Bug

No problem ;) — report the bugs! But, logs are most often required. If you
are using Home Assistant, which is about the only use I'm aware of for
this library, then add the following to your `configuration.yaml`:
```
logger:
  default: info
  logs:
    custom_components.elkm1: debug
    elkm1_lib: debug
```

Do everything in your power to trim to logs down to their smallest. One way is
to reproduce your problem quickly so that few other logs are not generated in
between. Another recommendation is to use the simplest configuration that you
can think of to reproduce the problem.

Can you reproduce the problem in other ways? If this is a problem that is
being experienced while using Home Assistant try using the `Services` in `Developer Tools`.

Sometime logs may have sensitive information in them. You may want to
scan your logs for that info and "X" it out. In addition, you can send logs
directly to me. Support email is in the `pyproject.toml` file. You may also
send a link to somewhere you've stored/shared the file (DropBox for example).



%package help
Summary:	Development documents and examples for elkm1-lib
Provides:	python3-elkm1-lib-doc
%description help
# Python ElkM1 library

[![PyPI version](https://badge.fury.io/py/elkm1-lib.svg)](https://badge.fury.io/py/elkm1-lib)
[![CI](https://github.com/gwww/elkm1/actions/workflows/code-quality.yml/badge.svg)](https://github.com/gwww/elkm1/actions/workflows/code-quality.yml)
[![Downloads](https://pepy.tech/badge/elkm1-lib)](https://pepy.tech/project/elkm1-lib)
[![License](https://img.shields.io/github/license/mashape/apistatus.svg)](https://pypi.org/project/elkm1_lib/)

Library for interacting with ElkM1 alarm/automation panel.

https://github.com/gwww/elkm1

## Requirements

- Python 3.9 (or higher)

## Description

This package is created as a library to interact with an ElkM1 alarm/automation
pattern. The motivation to write this was to use with the Home Assistant
automation platform. The library can be used for writing other ElkM1 integration
applications. The IO with the panel is asynchronous over TCP or over the
serial port.

## Installation

```bash
    $ pip install elkm1_lib
```

## Overview

Basic connection to the Elk panel:

```python
    from elkm1_lib import Elk
    import logging

    # Print to STDOUT
    LOG = logging.getLogger(__name__)
    logging.basicConfig(level=logging.DEBUG, format='%(message)s')

    # Connect to elk
    elk = Elk({'url': 'elk://192.168.1.100'})
    elk.connect()
    elk.run()
```

The above will connect to the Elk panel at IP address 192.168.1.100. the `elk://`
prefix specifies that the connect is plaintext. Alternatively, `elks://` will
connect over TLS. In this case a userid and password must be specified
and the call to `Elk` changes to:

```python
    elk = Elk(
        {'url': 'elks://192.168.1.100', 'userid': 'test', 'password': 'pass'}
    )
```

The following ElkM1 connection protocols are supported:
- serial:// - Serial port;
- elk:// - Elk M1XEP Ethernet, non-secure
- elks:// - Elk M1XEP Ethernet, secure, TLS 1.0
- elksv1_0:// - Elk M1XEP Ethernet, secure, TLS 1.0, supported on M1XEP version < 2.0.46
- elksv1_2:// - Elk M1XEP Ethernet, secure, TLS 1.2, supported on M1XEP version = 2.0.46
- elksv1_3:// - Elk M1XEP Ethernet, secure, TLS 1.2, not yet supported on M1XEP, reserved for future

A username and password are required for any of the secure modes.

To see working example code take a look at the script `bin/simple`.

The `Elk` object supports the concept of `Elements`. An `Element`
is the base class representation of `Zones`, `Lights`, etc. So, for
example there is a list of zones: `elk.zones` and each zone can be
accessed by `elk.zones[index]`. Each element has a `__str__`
representation so that it is easy to print its contents.

All `Elements` are referenced starting at 0. Even though the Elk panel
refers to, for example, zones 1-208, the library references them
as zones 0-207. All translation from base 0 to 1 and vice-versa is
handled internally in the `elkm1_lib.message` module.

After creating the `Elk` object and connecting to the panel the
library code will synchronize all the elements to the data from the Elk panel.

Many Elk messages are handled by the library, caching their contents. When a
message causes a change to an attribute of an `Element`, registered
callbacks are called so that user use of the library can be notified
of changing elements. The following user code shows registering a callback:

```python
    def call_me(element, changeset):
       print(changeset)

    for zone_number in range(Max.ZONES.value):
      elk.zones[zone_number].add_callback(call_me)
```

The library encodes, decodes, and processes messages to/from the
Elk panel. All the encoding and decoding is done in `elkm1_lib.message` module.

Messages received are handled with callbacks. The library
internally registers callbacks so that decoded messages
can be used to update an `Element`. The user of the
library may also register callbacks. Any particular message
may have multiple callbacks.

When the message is received it is decoded
and some validation is done. The message handler is called
with the fields of from the decoded message. Each type of
message has parameters that match the message type. All handler parameters
are named parameters.

Here is an example of a message handler being registered and how it is called:

```python
    def zone_status_change_handler(zone_number, zone_status):
      print(zone_number, zone_status)

    elk.add_handler('ZC', zone_status_change_handler)
```

The above code registers a callback for 'ZC' (Elk zone status change)
messages. When a ZC message is received the handler functions are called
with the zone_number and zone_status.

There are a number of pseudo-handlers that act like the handlers. These are
called when events happen. The pseudo-handlers are:

- `connect`: When a successful connection to the ElkM1 is completed.
- `disconnect`: When a connection to a panel is disconnected.
- `login`: When a login is made to the panel (using `elks://` connection mode.
  A single boolean parameter is passed `succeeded`.
- `sync_complete`: When the panel has completed synchonizing all its elements.
- `timeout`: When a send of a message to the ElkM1 times out (fails to send).
- `unknown`: When a message from the ElkM1 is received and the library does
  not have a method to decode the message. The message is passed to this handler
  and can be decoded outside of the library.

## Utilities

The `bin` directory of the library has one utility program and
a couple of example uses of the library.

### `mkdoc`

The utility `mkdoc` creates a Markdown table of the list of Elk
messages with a check mark for those messages have encoders/decoders
and an X for those messages are not planned to be implemented.
There are no parameters to `mkdoc`. It outputs to stdout.
The data for the report comes from the ElkM1 library code mostly.
A couple of things are hard coded in the mkdoc script, notably
the "no plans to implement" list.

### `simple`

The `simple` Python script is a trivial use of the ElkM1 library.
It connects to the panel, syncs to internal memory, and continues
listening for any messages from the panel. The URL of the ElkM1 to
connect to is retrieved from an environment variable named `ELKM1_URL`.

### `elk`

The `elk` Python script is a bit of a command interpretor. It can run in
two modes. Non-interactive mode is the default. Just run the `elk` command.
The non-interactive mode is similar to `simple` except there are a
couple of message handlers (`timeout` and `unknown` handlers).

The `elk` can also be run in interactive mode by invoking it by
`elk -i`. In this mode is uses curses (full screen use of the terminal)
that has a command line and an output window. `TAB` switches between
the command line and output windows. In the output window the arrow keys
and scrollwheel scroll the contents of the window.

In the command line when running `elk -i` there are a
number of commands. Start with `help`. Then `help <command>` for
details on each command. In general there are commands to dump the internal
state of elements and to invoke any of the encoders to send a message
to the Elk panel.

For example, `light <4, 8, 12-14` would invoke the `__str__` method
for the light element to print the cached info for lights 0-3, 8, and 12-14.

Another example would be `pf 3` which issues the pf (Turn light off)
command for light number 3 (light 4 on the panel -- remember 0
versus 1 base).

All of the commands that send messages to the panel are automatically
discovered and are all the XX_encode functions in the ``elkm1_lib.message``
module. The docstring and the XX_encode's parameters are shown as part
of the help.

## Development

This project uses [poetry](https://poetry.eustace.io/) for development dependencies. Installation instructions are on their website.

To get started developing:

```
git clone https://github.com/gwww/elkm1.git
cd elkm1
poetry install
poetry shell # Or activate the created virtual environment
make test # to ensure everything installed properly
```

There is a `Makefile` in the root directory as well. The `make` command
followed by one of the targets in the `Makefile` can be used. If you don't
have or wish to use `make` the `Makefile` serves as examples of common
commands that can be run.

## Reporting a Bug

No problem ;) — report the bugs! But, logs are most often required. If you
are using Home Assistant, which is about the only use I'm aware of for
this library, then add the following to your `configuration.yaml`:
```
logger:
  default: info
  logs:
    custom_components.elkm1: debug
    elkm1_lib: debug
```

Do everything in your power to trim to logs down to their smallest. One way is
to reproduce your problem quickly so that few other logs are not generated in
between. Another recommendation is to use the simplest configuration that you
can think of to reproduce the problem.

Can you reproduce the problem in other ways? If this is a problem that is
being experienced while using Home Assistant try using the `Services` in `Developer Tools`.

Sometime logs may have sensitive information in them. You may want to
scan your logs for that info and "X" it out. In addition, you can send logs
directly to me. Support email is in the `pyproject.toml` file. You may also
send a link to somewhere you've stored/shared the file (DropBox for example).



%prep
%autosetup -n elkm1-lib-2.2.2

%build
%py3_build

%install
%py3_install
install -d -m755 %{buildroot}/%{_pkgdocdir}
if [ -d doc ]; then cp -arf doc %{buildroot}/%{_pkgdocdir}; fi
if [ -d docs ]; then cp -arf docs %{buildroot}/%{_pkgdocdir}; fi
if [ -d example ]; then cp -arf example %{buildroot}/%{_pkgdocdir}; fi
if [ -d examples ]; then cp -arf examples %{buildroot}/%{_pkgdocdir}; fi
pushd %{buildroot}
if [ -d usr/lib ]; then
	find usr/lib -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/lib64 ]; then
	find usr/lib64 -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/bin ]; then
	find usr/bin -type f -printf "/%h/%f\n" >> filelist.lst
fi
if [ -d usr/sbin ]; then
	find usr/sbin -type f -printf "/%h/%f\n" >> filelist.lst
fi
touch doclist.lst
if [ -d usr/share/man ]; then
	find usr/share/man -type f -printf "/%h/%f.gz\n" >> doclist.lst
fi
popd
mv %{buildroot}/filelist.lst .
mv %{buildroot}/doclist.lst .

%files -n python3-elkm1-lib -f filelist.lst
%dir %{python3_sitelib}/*

%files help -f doclist.lst
%{_docdir}/*

%changelog
* Wed May 10 2023 Python_Bot <Python_Bot@openeuler.org> - 2.2.2-1
- Package Spec generated