Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated lib/items with POD from 'Old' docs #103

Merged
merged 2 commits into from
Mar 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions lib/Group.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,55 @@ use strict;

package Group;

=head1 NAME

B<Group> - You can use this object to group and operate on groups of items:

=head1 SYNOPSIS

$outside_lights = new Group($light1, $light2, $light3);
$outside_lights-> add($light4, $light5);
$outside_lights-> add($light6);
set $outside_lights ON if time_now("$Time_Sunset + 0:15");

for my $item (list $outside_lights) {
print "member = $item->{object_name}\n";
}

if (my $member_name = member_changed $outside_lights) {
my $member = &get_object_by_name($member_name);
print_log "Group member $member_name changed to $member->{state}"
}

my @members = member_changed_log $sensors;

# turn off all but the bedroom light when we are getting ready for bed
if( state_now $bedroom_control eq ON ) {
my $all = new Group(list $All_Lights);
$all -> remove ( $master_bedroom );
set $master_bedroom ON;
set $all OFF;
}

See mh/code/examples/test_group.pl and mh/code/public/monitor_occupancy_jason.pl for more examples.

=head1 DESCRIPTION

=head1 INHERITS

B<Generic_Item>

=head1 METHODS

=over

=cut

@Group::ISA = ('Generic_Item');

=item C<new(@item_list)>
=cut

sub new {
my ($class, @items) = @_;
my $self = {state => undef};
Expand All @@ -16,6 +63,9 @@ sub new {
return $self;
}

=item C<add(@item_list)>
=cut

sub add {
my ($self, @items) = @_;
my @item_states = ();
Expand Down Expand Up @@ -96,6 +146,9 @@ sub include_in_group { #check if X10 item is affected by group
}


=item C<set>
=cut

sub set {
my ($self, $state, $set_by) = @_;
print "Group set: $self set to $state members @{$$self{members}}\n" if $main::Debug{group};
Expand Down Expand Up @@ -400,6 +453,8 @@ sub set_group_items {
}
}

=item C<list>
=cut

sub list {
my ($self, $memberList, $groupList, $no_child_members ) = @_;
Expand Down Expand Up @@ -442,6 +497,11 @@ sub list {
return sort @$memberList; # Hmmm, to sort or not to sort.
}

=item C<member_changed>

Returns a member object name whenever one changes

=cut

sub member_changed {
my ($self) = @_;
Expand All @@ -451,12 +511,23 @@ sub member_changed {
}
}

=item C<member_changed_log>

Returns a list of recenty changed members. The first one was the most recently changed.

=cut

sub member_changed_log {
my ($self) = @_;
return unless $$self{member_changed_log};
return @{$$self{member_changed_log}};
}

=item C<remove>

Remove an item from a group

=cut

sub remove {
my ($self, @items) = @_;
Expand All @@ -469,6 +540,46 @@ sub remove {
}
}

=back

=head1 INHERITED METHODS

=over

=item C<state>

=item C<state_now>

Like the Generic_Item methods, these return the last state that the group was set to. If a group member changed, these methods will return 'member $state_name' rather than just '$state_name'. You can use the member_changed or get_set_by methods to see which member changed.

=item C<state_log>

Returns a list array of the last max_state_log_entries (mh.ini parm) time_date stamped states.


=back

=head1 INI PARAMETERS

NONE

=head1 AUTHOR

UNK

=head1 SEE ALSO

NONE

=head1 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.

=cut

#
# $Log: Group.pm,v $
Expand Down
76 changes: 50 additions & 26 deletions lib/HVweb_Item.pm
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
#
# HVweb_Item.pm
#
# Package to control Homevision controller via the Homevision web server
#
# Set homevision_url=<your homevision web server url> in mh.ini
#
# Create items as follows:
#
# $kitchen_light = new HVweb_Item('On','X10 G1 On','X10 G1 state level%','Main Kitchen Light');
# $kitchen_light -> add ('Off', 'X10 G1 Off');
# $vcr = new HVweb_Item('Power', 'IR 45 1 time');
# $vcr -> add ('Play', 'IR 46 1 time');
#
# See Homevision documentation for complete list of command formats
# Configure Homevision Webserver to report command results
#
# Operate devices as follows:
#
# set $kitchen_light 'On';
# set $vcr 'Play';
#
# By Joseph Gaston ([email protected])
#
#

use strict;

package HVweb_Item;

=head1 NAME

B<HVweb_Item> - Control Homevision controller via the Homevision web server

=head1 SYNOPSIS

$kitchen_light = new HVweb_Item('On', 'X10 G1 On');
$kitchen_light -> add ('Off', 'X10 G1 Off');
$vcr = new HVweb_Item('Power', 'IR 45 1 time');
$vcr -> add ('Play', 'IR 46 1 time');

set $kitchen_light 'On';
set $vcr 'Play';



=head1 DESCRIPTION

See Homevision documentation for complete list of command formats
Configure Homevision Webserver to report command results

=head1 INHERITS

B<Generic_Item>

=head1 METHODS
=cut

@HVweb_Item::ISA = ('Generic_Item');

sub new {
Expand Down Expand Up @@ -107,3 +109,25 @@ sub list { ### Some web functions (list_items.pl) need this routine

return 1;

=head1 INI PARAMETERS

Set homevision_url=<your homevision web server url> in mh.ini

=head1 AUTHOR

Joseph Gaston ([email protected])

=head1 SEE ALSO

See Homevision documentation for complete list of command formats

=head1 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.

=cut

120 changes: 120 additions & 0 deletions lib/IR_Item.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,37 @@ use strict;

package IR_Item;

=head1 NAME

B<IR_Item> - Controls IR transmiters

=head1 SYNOPSIS

$TV = new IR_Item 'TV';
$v_tv_control = new Voice_Cmd("tv [power,on,off,mute,vol+,vol-,ch+,ch-]");
set $TV $state if $state = said $v_tv_control;

$VCR = new IR_Item 'vcr', '3digit';
set $VCR "12,RECORD" if time_cron('59 19 * * 3');
set $VCR "STOP" if time_cron('00 20 * * 3');

=head1 DESCRIPTION

This object controls IR transmiters. The devices currently supported are the X10 IR Commander, HomeVision, CPU-XA/Ocelot/Leopard, and UIRT2 (http://www.fukushima.us/UIRT2/).

The X10 IR Commander (http://www.x10.com/products/ux17a_bj2.htm) receives commands from the wireless CM17 (firecracker) interface. Currently, you must use the X10 supplied software (http://www.x10.com/commander.htm and/or ftp://ftp.x10.com/pub/applications/commander/) to program the IR Commander to use the codes for your various remotes.

=head1 INHERITS

B<Generic_Item>

=head1 METHODS

=over

=cut


@IR_Item::ISA = ('Generic_Item');

my %default_map = qw(
Expand All @@ -13,6 +44,27 @@ my %default_map = qw(

my ($hooks_added, @objects_xap);

=item C<new($type, $code, $interface, $mapref)> - Creates a new Item.

$type is the type of device being controlled. Default is TV. Here are the only valid types for the X10 IR Commander; TV, VCR, CAB, CD, SAT, DVD

$code specifies how numbers will be treated. Default is 2digit.
- noPad : numbers are not modified
- 2digit : single digits will be padded with a leading zero
- 3digit : numbers will be padded to 3 digits with leading zeros
- addEnter: adds an ENTER command after any numbers, to make changing channels faster on devices that wait for a timeout (e.g. Sony TVs).

$interface is the transmitter to be used. Default is cm17.
- cm17 : X10 IR Commander
- homevision: HomeVision
- ncpuxa : CPU-XA/Ocelot/Leopard
- uirt2 : UIRT2 (http://www.fukushima.us/UIRT2/)
- xAP : Sends / receives data via the xAP protocol.

$mapref is a reference to a hash that specifies commands to be mapped to other commands. This is useful for transmitters like the Ocelot which use slot numbers instead of device and function name pairs. Default is a reference to a hash containing ( ON => POWER, OFF => POWER ) Which you would not want if you had descrete ON and OFF codes.

=cut

sub new {
my ($class, $device, $code, $interface, $mapref) = @_;
my $self = {};
Expand Down Expand Up @@ -136,6 +188,74 @@ sub default_setstate {
}
}


=back

=head1 INHERITED METHODS

=over

=item C<state>

Returns the last state that was sent

=item C<state_now>

Returns the state that was sent in the current pass.

=item C<state_log>

Returns a list array of the last max_state_log_entries (mh.ini parm) time_date stamped states.

=item C<set($command)>

Sends out commands to the IR device. Here is a list of valid commands for the X10 IR Commander::
Note: Commands are not case insensitive
POWER MUTE
CH+ CH-
VOL+ VOL-
1 2
3 4
5 6
7 8
9 0
MENU ENTER
FF REW
RECORD PAUSE
PLAY STOP
AVSWITCH DISPLAY
UP DOWN
LEFT RIGHT
SKIPDOWN SKIPUP
TITLE SUBTITLE
EXIT OK
RETURN

=back

=head1 INI PARAMETERS

NONE

=head1 AUTHOR

UNK

=head1 SEE ALSO

NONE

=head1 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.

=cut


#
# $Log: IR_Item.pm,v $
# Revision 1.17 2004/07/18 22:16:37 winter
Expand Down
Loading