forked from krkeegan/misterhouse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEIB_Items.pm
2072 lines (1503 loc) · 44.7 KB
/
EIB_Items.pm
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
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
=head1 B<EIB_Item>
=head2 SYNOPSIS
NONE
=head2 DESCRIPTION
EIB (European Installation Bus) items.
EIB/KNX website: http://konnex.org
The following EIB types are supported: (MH Klassname, DPT Type, EIS Type, Description)
EIB1: DPT 1.001, EIS 1, Switches
EIB2: NA, EIS 2, Dimmers
EIB3: DPT 10.000, EIS 3, Time
EIB4: DPT 11.000, EIS 4, Date
EIB5: DPT 9.000, EIS 5, Values (weather stations etc)
EIB6: DPT 5.001, EIS 6, Scaling (0 - 100%)
EIB7: NA, EIS 7, Motor drives
EIB8: DPT 2.001, EIS 8, forced control 2 bit
EIB9: DPT 14.00x, EIS 9, 32-bit float
EIB10: DPT 7.001, EIS 10, 16-bit unsigned integer
EIB10_1: DPT 8.001, EIS 10.001, 16-bit signed integer
EIB11: DPT 12.001, EIS 11, 32-bit unsigned integer
EIB11_1: DPT 13.001, EIS 11.001, 32-bit signed integer
EIB14: DPT 6.001, EIS 14, 8-bit signed integer
EIB14_1: DPT 5.010, EIS 14.1; 8-bit unsigned integer
EIB15: DPT 16.000, EIS 15, 14 byte text messages
EIBW: NA, NA, summary object for 2 EIS1 Objects
to define the state of a window
(closed, tilt, open)
=head2 INHERITS
B<Generic_Item>
=head2 METHODS
=over
=cut
use strict;
package EIB_Item;
@EIB_Item::ISA = ('Generic_Item');
my %eib_items_by_id;
sub reset {
undef %eib_items_by_id; # Reset on code re-load
}
=item C<eib_items_by_id>
Lookup EIB_Item with the given address
=cut
sub eib_items_by_id {
my($id) = @_;
&main::print_log ("eib_items_by_id: asking for \'$id\'") if $main::config_parms{eib_errata} >= 8;
return unless defined $eib_items_by_id{$id};
return @{ $eib_items_by_id{$id} };
}
=item C<new>
Generic EIB_Item class. This class is not instantiated directly. It is used to inherit common EIB properties
=cut
sub new {
my ($class, $idstr, $mode) = @_;
my $self = $class->SUPER::new();
bless $self, $class;
if ($idstr =~ /\|/) {
&main::print_log ("EIB_Item: '$idstr' is a combined address vector. Ignore it") if $main::config_parms{eib_errata} >= 3;
} else {
my @ids = split /\+/, $idstr;
&main::print_log ("EIB_Item: '$idstr' is splitted into '@ids'") if $main::config_parms{eib_errata} >= 3;
$self->{groupaddr} = $ids[0];
map { $self->addEIBAddress ($_) } @ids;
}
$self->{readable} = 0;
$self->{displayonly} = 0;
map {
if ($_ eq "R" || $_ eq "r") {
$self->{readable} = 1;
} elsif ($_ eq "DO" || $_ eq "do") {
$self->{displayonly} = 1;
} elsif ($_ =~ /^label=(.*)$/) {
$self->set_label ($1);
} elsif ($_ =~ /^icon=(.*)$/) {
$self->set_icon ($1);
}
} split(/\|/, $mode) if (defined $mode);
if ($self->{readable} && defined $self->{groupaddr}) {
# trigger future EIB read command
$self->read_request();
}
return $self;
}
sub addStates {
my $self = shift;
push(@{$$self{states}}, @_) unless $self->{displayonly};
}
sub addEIBAddress {
my ($self, $addr) = @_;
&main::print_log ("addEIBAddress: registering $addr for $self") if $main::config_parms{eib_errata} >= 3;
push (@{$eib_items_by_id{$addr}}, $self);
}
=item C<printname>
Item name to appear in logs etc
=cut
sub printname {
my($name) = @_;
if ($name =~ /\d+\/\d+\/\d+/) {
my @eib_items = EIB_Item::eib_items_by_id($name);
if (@eib_items) {
$name = "";
map {
my $eib_item = $_;
$name = $name . $eib_item->{object_name} . " " if (defined $eib_item && defined $eib_item->{object_name});
} @eib_items;
}
}
return $name;
}
=item C<set_receive>
detected an EIB event on the bus. Update item state to reflect the value in the event
=cut
sub set_receive {
my ($self, $state, $set_by, $target) = @_;
&main::print_log ("EIB_Item::set_receive: state '$state' for $self") if $main::config_parms{eib_errata} >= 3;
return if &main::check_for_tied_filters($self, $state, $set_by);
# Set target to symbolic item name, if possible
$target = $self->{groupaddr} unless (defined $target);
$target = &printname($target);
&Generic_Item::set_states_for_next_pass($self, $state, $set_by, $target);
}
sub set {
my ($self, $state, $set_by, $target) = @_;
&main::print_log ("EIB_Item::set: state '$state' for '$self->{object_name}'") if $main::config_parms{eib_errata} >= 3;
return 0 if &main::check_for_tied_filters($self, $state, $set_by);
if ($state eq 'toggle') {
if ($$self{state} eq 'on') {
$state = 'off';
}
elsif ($$self{state} eq 'off') {
$state = 'on';
}
else {
&main::print_log("Can't toggle EIB_Item object $self->{object_name} in state $$self{state}");
return 0;
}
&main::print_log("Toggling EIB_Item object $self->{object_name} from $$self{state} to $state");
}
$target = $self->{groupaddr} unless (defined $target);
$target = &printname($target);
# Find all items which receives the groupaddr and notify them (including myself)
my @eib_items = EIB_Item::eib_items_by_id($self->{groupaddr});
if (@eib_items) {
map { $_->set_receive ($state, $set_by, $target);
} @eib_items;
}
return 1 if $main::Save{mode} eq 'offline';
# If encode method exists, generate and send EIB message
my $data = $self->encode($state) if $self->can("encode");
$self->send_write_msg($data) if (defined $data);
return 1;
}
sub readable {
my ($self) = @_;
return (defined $self->{readable});
}
=item C<send_write_msg>
generate EIB message to set a value
=cut
sub send_write_msg {
my ($self, $data) = @_;
my $msg;
$msg->{'type'} = 'write';
$msg->{'dst'} = $self->{groupaddr};
$msg->{'data'} = $data;
EIB_Device::send_msg($msg);
}
=item C<send_read_msg>
generate EIB message to read a value
=cut
sub send_read_msg {
my ($self, $data) = @_;
my $msg;
&main::print_log ("EIB_Item::send_read_msg: Send read message to $self->{groupaddr}") if $main::config_parms{eib_errata} >= 3;
$msg->{'type'} = 'read';
$msg->{'dst'} = $self->{groupaddr};
$msg->{'data'} = [0];
EIB_Device::send_msg($msg);
}
=item C<receive_write_msg>
process a message to set a value
=cut
sub receive_write_msg {
my ($self, $state, $set_by, $target) = @_;
&main::print_log("EIB_Item::receive_write_msg: new state $state set on $self") if $main::config_parms{eib_errata} >= 3;
$self->set_receive($state, $set_by, $target);
}
=item C<receive_reply_msg>
process a message with a reply value (read response)
=cut
sub receive_reply_msg {
my ($self, $state, $set_by, $target) = @_;
my $t;
$self->stop_read_timer();
$self->{read_attempts} = undef;
$self->set_receive($state, $set_by, $target, 1);
}
=item C<receive_msg>
entry point from device interface. Analyse message and call appropriate receive_*_msg handler
=cut
sub receive_msg {
my ($msg) = @_;
my $addr = $msg->{'dst'};
my $op = $msg->{'type'};
my @data = @{$msg->{'data'}};
my @eib_items = EIB_Item::eib_items_by_id($addr);
if (@eib_items) {
map {
my $eib_item = $_;
if (defined $eib_item->can("decode")) {
my $state = decode $eib_item @data if ($op ne 'read');
&main::print_log("EIB $op from $msg->{'src'} to $msg->{'dst'}",
$op eq 'read' ? "" : defined $state ? ": \"$state\"" : ": \"[@data]\"")
if $main::config_parms{eib_errata} >= 3;
if ($op eq 'write') {
$eib_item->receive_write_msg($state, $msg->{'src'}, $msg->{'dst'});
}
elsif ($op eq 'reply') {
$eib_item->receive_reply_msg($state, $msg->{'src'}, $msg->{'dst'});
}
}
} @eib_items;
}
else {
&main::print_log("EIB $op from $msg->{'src'} to $msg->{'dst'}",
". Item not found.") if $main::config_parms{eib_errata} >= 2;
;
}
}
=item C<start_read_timer>
set a timeout for waiting for read response
=cut
sub start_read_timer {
my ($self, $interval) = @_;
$interval = 0 + $::config_parms{eib_read_retry_interval} unless defined $interval;
$self->{get_timer} = new Timer;
$self->{get_timer}->set($interval, sub {EIB_Item::read_timeout($self);}, 1);
$self->{get_timer}->start();
}
=item C<stop_read_timer>
disable timer
=cut
sub stop_read_timer {
my ($self) = @_;
return unless defined $self->{get_timer};
$self->{get_timer}->unset();
$self->{get_timer} = undef;
}
=item C<read_timeout>
No reply to read request. Retry or give up.
=cut
sub read_timeout {
my ($self) = @_;
stop_read_timer($self);
$self->{read_timeouts}++;
if ($self->{read_timeouts} > $::config_parms{eib_max_read_attempts}) {
&main::print_log( "EIB read failure for group ", $self->{groupaddr});
}
else {
$self->send_read_msg();
start_read_timer($self);
}
}
=item C<read_request>
send a read request, and start timer
=cut
sub read_request {
my ($self) = @_;
$self->send_read_msg();
$self->{read_timeouts} = 0;
$self->start_read_timer();
}
=item C<delayed_read_request>
wait a while and then send a read request. If a read request is sent too soon, the EIB actuator may not have obtained a stable value, so we want to delay before sending the request.
=cut
sub delayed_read_request {
my ($self, $interval) = @_;
$interval = 2 unless defined $interval;
$self->{read_timeouts} = -1; # ugly...
$self->start_read_timer($interval);
}
=back
=head2 INI PARAMETERS
NONE
=head2 AUTHOR
09/09/2005 Created by Peter Sjödin [email protected]
06/01/2009 Enhanced by Ralf Klueber r(at)lf-klueber.de
08/01/2009 Listening addresses by Mike Pieper [email protected]
=head2 SEE ALSO
NONE
=head2 LICENSE
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
=head1 B<EIB Sub-Items>
=head2 INHERITS
B<EIB_Item>
=head2 EIB1_Item
=over
=cut
package EIB1_Item;
@EIB1_Item::ISA = ('EIB_Item');
sub new {
my ($class, $idstr, $mode) = @_;
my $self = $class->SUPER::new($idstr, $mode);
$self->addStates ('on', 'off');
return $self;
}
sub eis_type {
return '1';
}
=item C<decode>
translate EIS 1 data to state (on/off)
=cut
sub decode {
my ($self, @data) = @_;
unless ($#data == 0) {
&main::print_log("Not EIS type 1 data received for $self->{groupaddr}: \[@data\]") if $main::config_parms{eib_errata} >= 2;
return;
}
if ($data[0] == 0) {
return 'off';
}
else {
return 'on';
}
}
=item C<encode>
translate state to EIS 1 data
=cut
sub encode {
my ($self, $state) = @_;
&main::print_log ("EIS1::encode: state '$state' for '$self->{object_name}'") if $main::config_parms{eib_errata} >= 3;
if ($state eq 'on') {
return ([1]);
}
elsif ($state eq 'off') {
return ([0]);
}
else {
print "Invalid state for EIS type 1: \'$state\'\n";
return;
}
}
=back
=head2 EIG1G_Item
A group of EIB1 items. Setting the value of an EIB1 group will affect all members in the group. The class is used to keep track of EIB1 group memberships. If a write message is detected, all members will be updated.
=cut
package EIB1G_Item;
@EIB1G_Item::ISA = ('EIB1_Item');
sub new {
my ($class, $id, $groupstr) = @_;
my @groups = split /\|/, $groupstr;
my $self = $class->SUPER::new($id);
$self->{'linked_groups'} = \@groups;
return $self;
}
sub eis_type {
return '1';
}
sub set_receive {
my ($self, $state, $set_by, $target) = @_;
$self->SUPER::set_receive($state, $set_by, $target);
map {
my @eib_items = EIB_Item::eib_items_by_id($_);
if (@eib_items) {
map { $_->set_receive ($state, $set_by, $target);
} @eib_items;
}
} @{$self->{'linked_groups'}};
}
=head2 DIB2_Item
EIS 2: Dimming
EIB dimmers can be controlled in three different ways:
1. "control": brighten, dim, stop. Handled by class EIB21_Item
2. "value": numerical value: Handled by class EIB6_Item
3. "position": on, off. Handled by class EIB1_Item
Class EIB2_Item is a meta-item to represent dimmers, consist of the three underlying item.
The main purpose is to make a dimmer appear as a single item, while the real work is done
by the three underlying items.
The identifier for the EIB2_Item is composed of the concatenation of the addresses of
the three underlying items, with '|' between them. For example, '1/0/90|1/0/91|1/4/1' is a dimmer
with control address 1/0/90, value address 1/0/91, and position address 1/4/1.
=over
=cut
package EIB2_Item;
@EIB2_Item::ISA = ('EIB_Item');
=item C<new>
create an EIB2_Item. Instantiate the three underlying items.
=cut
sub new {
my ($class, $id, $mode) = @_;
my @groups;
my ($subid, $item);
my $self = $class->SUPER::new($id,$mode);
@groups = split(/\|/, $id);
print "Three group addresses required for dimmer. Found $#groups in $id\n" if ($#groups != 2);
$subid = $groups[0];
$item = new EIB23_Item($subid, "R", $self);
$self->{Position} = $item;
$subid = $groups[1];
$item = new EIB21_Item($subid, "", $self);
$self->{Control} = $item;
$subid = $groups[2];
$item = new EIB22_Item($subid, "R", $self);
$self->{Value} = $item;
if ($main::config_parms{eib2_menu_states}) {
$self->addStates (split ',', $main::config_parms{eib2_menu_states});
} else {
$self->addStates ('on', 'off', 'brighten', 'dim', 'stop', '5%', '30%', '60%', '100%');
}
return $self;
}
sub eis_type {
return '2';
}
=item C<position>
return "position" sub-item
=cut
sub position {
my ($self) = @_;
my $subitem;
return unless defined $self->{Position};
return $self->{Position};
}
=item C<control>
return "control" sub-item
=cut
sub control {
my ($self) = @_;
my $subitem;
return unless defined $self->{Control};
return $self->{Control};
}
=item C<value>
return "value" sub-item
=cut
sub value {
my ($self) = @_;
my $subitem;
return unless defined $self->{Value};
return $self->{Value};
}
=item C<set>
Set EIB2 item. Parse state to determine the corresponding sub-item to call.
=cut
sub set {
my ($self, $state, $set_by, $target) = @_;
my $subitem;
if ($state eq 'toggle' ||
$state eq 'on' ||
$state eq 'off') {
$subitem = $self->position();
}
elsif ($state =~ /^(stop|brighten|dim)$/) {
$subitem = $self->control();
}
elsif ($state =~ /^\d+$/ ||
$state =~ /^(\+|\-)\d+$/ ||
$state =~ /^\d+\%$/) {
$subitem = $self->value();
}
else {
&main::print_log(" $self->{object_name}: Bad EIB dimmer state \'$state\'\n");
}
$subitem->set($state, $set_by, $target) if (defined $subitem);
return 1;
}
=item C<set_receive>
received an event from one of the sub_items. If it was a numerical value ("Value"), update the "Position" subitem to 'on' or 'off'. If the value was zero, also set self to 'off'. Update level (0-100) to represent dimmer position
=cut
sub set_receive {
my ($self, $state, $set_by, $target) = @_;
my $onoff;
&main::print_log("EIB2_Item::set_receive: new state $state") if $main::config_parms{eib_errata} >= 3;
my $newstate = $state; # set SUPER state after all sub settings
if ($state =~ /(\d+)/) {
$self->{level} = $1;
$newstate = $1."%";
if ($1 eq '0') {
$onoff = 'off';
$newstate = 'off';
}
else {
$onoff = 'on';
if ($1 eq '100') {
$newstate = 'on';
}
}
my $pos = $self->position();
if (defined $pos && $pos->state_final() ne $onoff) {
$pos->set_receive($onoff, $set_by, $target);
}
}
elsif ($state eq 'on' || $state eq 'off') {
if ($state eq 'off') {
$self->{level} = 0;
my $val = $self->value();
if (defined $val && $val->state_final() != 0) {
$val->set_receive(0, $set_by, $target);
}
}
if ($state eq 'on') {
my $val = $self->value();
delayed_read_request $val if (defined $val && $val->{readable});
}
}
$self->SUPER::set_receive($newstate, $set_by, $target);
}
=item C<state_level>
return 'on', 'off' or 'dim', depending on current setting (as obtained from "value" sub-item)
=cut
sub state_level {
my ($self) = @_;
my $state = $self->{state};
my $level = $self->value()->{state};
if (!defined $state or !($state eq 'on' or $state eq 'off')) {
if (defined $level and $level =~ /^[\+\-\d\%]+$/) {
$state = 'dim';
$state = 'off' if $level == 0;
$state = 'on' if $level == 100;
}
elsif ($state =~ /^[\+\-\d\%]+$/ or $state eq 'dim' or $state eq 'brighten') {
$state = 'dim';
}
else {
$state = ''; # unknown
}
}
elsif ($state eq 'on' and defined $level and $level < 100) {
$state = 'dim';
}
return $state;
}
=back
=head2 EIB2_Subitem
A generic class for the three dimming sub-functions
=over
=cut
package EIB2_Subitem;
@EIB2_Subitem::ISA = ('EIB_Item');
sub new {
my ($class, $id, $mode, $dimmer) = @_;
my @args;
my $self = $class->SUPER::new($id, $mode);
$self->{'Dimmer'} = $dimmer;
return $self;
}
=item C<dimmer>
return "dimmer" meta-item
=cut
sub dimmer {
my ($self) = @_;
return unless defined $self->{Dimmer};
return $self->{Dimmer};
}
=item C<set_receive>
forward to meta-item
=cut
sub set_receive {
my ($self, $state, $set_by, $target) = @_;
&main::print_log("EIB2_Subitem::set_receive: new state $state") if $main::config_parms{eib_errata} >= 3;
$self->SUPER::set_receive($state, $set_by, $target);
my $dimmer = dimmer $self;
if (defined $dimmer) {
$dimmer->set_receive($state, $set_by, $target);
}
else {
&main::print_log("No dimmer defined for dimmer subitem $self->{groupaddr}");
}
}
=back
=head2 EIB21_Item
Dimming sub-function "control"
=over
=cut
package EIB21_Item;
@EIB21_Item::ISA = ('EIB2_Subitem');
sub eis_type {
return '2.1';
}
=item C<dimmer_timeout>
dimmer should have reached stable state. Issue a read request to obtain current value
=cut
sub dimmer_timeout {
my ($self) = @_;
my $value;
$value = $self->dimmer()->value();
$value->send_read_msg();
}
=item C<set>
To allow adjusting dimmer value in real-time from for example web interface: If state is set to same dim/brighten value twice before dimmer timer has expired, it means "stop". For example, first 'dim' means start dimming, second means stop dimming (This behaviour is configurable via configuration parameter "eib_dim_stop_on_repeat")
=cut
sub set {
my ($self, $state, $set_by, $target) = @_;
my $subitem;
if ($::config_parms{eib_dim_stop_on_repeat} && defined $self->{dimmer_timer}) {
if (($state eq 'brighten' && $self->{state} eq 'brighten') ||
($state eq 'dim' && $self->{state} eq 'dim')) {
$state = 'stop';
}
}
return $self->SUPER::set($state, $set_by, $target);
}
sub decode {
my ($self, @data) = @_;
unless ($#data == 0) {
&main::print_log("Not EIS type 21 data received for $self->{groupaddr}: \[@data\]") if $main::config_parms{eib_errata} >= 2;
return;
}
if (($data[0] & 0x7) == 0) {
return 'stop';
}
elsif (($data[0] & 0x8) == 0) {
return 'dim';
}
else {
return 'brighten';
}
}
sub encode {
my ($self, $state) = @_;
&main::print_log ("EIS21::encode: state '$state' for '$self->{object_name}'") if $main::config_parms{eib_errata} >= 3;
if ($state eq 'stop') {
return ([0]);
}
elsif ($state eq 'dim') {
return ([1]);
}
elsif ($state eq 'brighten') {
return ([9]);
}
else {
print "Invalid state for EIS type 2.1: \'$state\'\n";
return;
}
}
=item C<set_receive>
if it is a 'stop' event, generate a read request for the 'Value' sub-item, to learn the actual dimmer setting
=cut
sub set_receive {
my ($self, $state, $set_by, $target) = @_;
my ($dimmer, $value);
$self->SUPER::set_receive($state, $set_by, $target);
if ($state eq 'stop') {
$dimmer = dimmer $self;
$value = value $dimmer if (defined $dimmer);
if (defined $value) {
delayed_read_request $value;
}
else {
&main::print_log("No dimmer value subitem for dimmer control $self->{groupaddr}");
}
$self->{dimmer_timer}->unset() if defined $self->{dimmer_timer};
}
elsif ($state eq 'dim' || $state eq 'brighten') {
# let some time pass and then issue a read request, to find out the final dimmer level.
# The time is configurable via configuration parameter "eib_dimmmer_time".
$self->{dimmer_timer} = new Timer unless defined $self->{dimmer_timer};
if ($self->{dimmer_timer}->inactive()) {
my $interval = 0 + $::config_parms{eib_dimmer_timer};
$self->{dimmer_timer}->set($interval, sub {EIB21_Item::dimmer_timeout($self);}, 1);
}
}
}
=back
=head2 EIB22_Item
Dimming sub-function "value". Set dimmer to a given brightness level
(0-100) with 8 bit resolution
Values are coded according to EIS 6
=over
=cut
package EIB22_Item;
# Multiple inheritance -- use encode/decode methods from EIB6_Item,
# the rest from EIB2_Subitem
@EIB22_Item::ISA = ('EIB2_Subitem', 'EIB6_Item'); # order is important!
sub eis_type {
return '2.2';
}
=item C<set_receive>
detected a "read" or "write" message on the bus. For readable actuators, don't trust the values in "write" messages, as they may not have been accepted by the actuator. So if it is a write, and the actuator is readable, generate a read request to obtain the actual value from the actuator
=cut
sub set_receive {
my ($self, $state, $set_by, $target, $read) = @_;
if (!$read && $self->{readable}) {
&main::print_log("EIB22_Item::set_receive: read_request for $self->{groupaddr}") if $main::config_parms{eib_errata} >= 3;
$self->delayed_read_request();
}
else {
$self->SUPER::set_receive($state, $set_by, $target);
}
}
=back
=head2 EIB23_Item
Dimming sub-function "position". Set dimmer to on/off. Values are coded according to EIS 1
=cut
package EIB23_Item;
# Multiple inheritance -- use encode/decode methods from EIB1_Item, and the rest from
# EIB2_Subitem
@EIB23_Item::ISA = ('EIB2_Subitem', 'EIB1_Item'); # order is important!
sub eis_type {
return '2.3';
}
=head2 EIB3_Item
Uhrzeit
=cut
package EIB3_Item;
@EIB3_Item::ISA = ('EIB_Item');
my @DoW = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
sub eis_type {
return '3';
}
sub decode {
my ($self, @data) = @_;
my $res;
unless ($#data == 3) {
&main::print_log("Not EIS type 3 data received for $self->{groupaddr}: \[@data\]") if $main::config_parms{eib_errata} >= 3;
return;
}
my $weekday = ($data[1] & 0xE0) >> 5;
my $hour = $data[1] & 0x1F;
my $minute = $data[2] & 0xFF;
my $second = $data[3] & 0xFF;