X10::Config::printConfig(lib/X10/Config.pm:161):
161: if ( $struct->type =~ /BATTERY|SECURITY|STATE|MOTION|LIGHT|FAN|CAMERA|CHRISTMAS/ ) {
DB<1> p $type
ZONE
DB<2> p $name
Indoor
DB<3> p $action
G3
DB<4> n
X10::Config::printConfig(lib/X10/Config.pm:173):
173: if ( $struct->type =~ /ZONE/ ) {
DB<4> n
X10::Config::printConfig(lib/X10/Config.pm:174):
174: select((select(OUTFILE), $~ = "outputFormatZone")[0]);
DB<4> p $type
ZONE
DB<5> n
X10::Config::printConfig(lib/X10/Config.pm:175):
175: write(OUTFILE);
DB<5> p $type
ZONE
DB<6> n
Variable "$action" is not available at lib/X10/Config.pm line 175.
at lib/X10/Config.pm line 175.
X10::Config::printConfig("/home/mora/Projects/X10/NEWX10/X10/Config", X10::Zone=HASH(0x1793008)) called at bin/X10.pl line 46
Variable "$name" is not available at lib/X10/Config.pm line 175.
at lib/X10/Config.pm line 175.
X10::Config::printConfig("/home/mora/Projects/X10/NEWX10/X10/Config", X10::Zone=HASH(0x1793008)) called at bin/X10.pl line 46
Variable "$type" is not available at lib/X10/Config.pm line 175.
at lib/X10/Config.pm line 175.
X10::Config::printConfig("/home/mora/Projects/X10/NEWX10/X10/Config", X10::Zone=HASH(0x1793008)) called at bin/X10.pl line 46
X10::Config::printConfig(lib/X10/Config.pm:48):
48: $type, $name, $action
49: .
DB<6> q
####
package X10::Zone;
#------------------------------------------------------------------------------#
# Libraries. #
#------------------------------------------------------------------------------#
use 5.006;
use version; our $VERSION = qv('0.01');
use lib qw'lib/ ../lib';
use strict;
use warnings;
use Data::Dumper;
#------------------------------------------------------------------------------#
# Attributes. #
#------------------------------------------------------------------------------#
sub new {
my $self = {};
$self->{TYPE} = undef;
$self->{PARENT} = undef;
$self->{NAME} = undef;
$self->{SECURITY} = undef;
$self->{STATE} = undef;
$self->{BATTERY} = undef;
$self->{HU} = undef;
$self->{LIST} = {};
bless($self);
return $self;
}
sub type {
my $self = shift;
if (@_) { $self->{TYPE} = shift }
return $self->{TYPE};
}
sub parent {
my $self = shift;
if (@_) { $self->{PARENT} = shift }
return $self->{PARENT};
}
sub name {
my $self = shift;
if (@_) { $self->{NAME} = shift }
return $self->{NAME};
}
sub security {
my $self = shift;
if (@_) { $self->{SECURITY} = shift }
return $self->{SECURITY};
}
sub state {
my $self = shift;
if (@_) { $self->{STATE} = shift }
return $self->{STATE};
}
sub battery {
my $self = shift;
if (@_) { $self->{BATTERY} = shift }
return $self->{BATTERY};
}
sub hu {
my $self = shift;
if (@_) { $self->{HU} = shift }
return $self->{HU};
}
sub list {
my $self = shift;
if (@_) { $self->{LIST} = shift }
return $self->{LIST};
}
sub add_to_list {
my ($self, $name, $zone) = @_;
my $zone_list = $self->list;
$zone_list->{$name} = $zone;
$self->list($zone_list);
}
####
package X10::Config;
#------------------------------------------------------------------------------#
# Libraries. #
#------------------------------------------------------------------------------#
use 5.006;
use version; our $VERSION = qv('0.01');
use lib qw'lib/ ../lib';
use strict;
use warnings;
use Data::Dumper;
#------------------------------------------------------------------------------#
# Attributes. #
#------------------------------------------------------------------------------#
use IO::Handle;
use X10::Zone;
use X10::Item;
my $configfile = "/home/mora/Projects/X10/NEWX10/X10/Config";
my $type = "";
my $name = "";
my $action = "";
#2345678901234567890123456789012345678901234567890
format outputFormatZone =
@<<<<<<<< @<<<<<<<<<<<<<<<<<<<< @<<<<
$type, $name, $action
.
format outputFormatGroup =
@<<<<<<<< @<<<<<<<<<<<<<<<<<<<< @<<<<
$type, $name, $action
.
format outputFormatArea =
@<<<<<<<< @<<<<<<<<<<<<<<<<<<<<
$type, $name
.
format outputFormatItem =
@<<<<<<<< @<<<<<<<<<<<<<<<<<<<< @<<<<
$type, $name, $action
.
sub new {
my ($self) = {};
$self->{HOUSE} = X10::Zone->new();
bless($self);
return $self
}
sub loadConfig {
my $configfile = shift;
my $house = shift;
my $prevStruct = '';
my $struct = $house;
open(INFILE, "<$configfile");
while() {
chomp();
s/^\s+//g;
s/\s+/ /;
($type,$name,$action) = split / /, $_;
/ZONE|GROUP|AREA/ && do {
$prevStruct = $struct;
$struct = X10::Zone->new(
type => $type,
parent => $prevStruct,
name => $name,
hu => $action,
);
};
/BATTERY/ && do {
$struct->{battery} = $action;
};
/SECURITY/ && do {
$struct->{security} = $action;
};
/STATE/ && do {
$struct->{state} = $action;
};
/LIGHT|FAN|CAMERA|CHRISTMAS/ && do {
my $item = X10::Item->new(
parent => $struct,
type => $type,
name => $name,
state => 'OFF',
hu => $action,
dimlevel => 0,
);
};
}
close(INFILE);
return $house;
}
sub dumpList {
my $self = shift;
my $space = shift;
my $fh = shift;
foreach my $type (values %{$self->list}) {
printf $fh "%s%s %s %s\n", $space,$type->type,$type->name,$type->hu;
my $tspace = "$space ";
printf $fh "%sSECURITY %s %s\n", $tspace,$type->name,$type->security;
printf $fh "%sSTATE %s %s\n", $tspace,$type->name,$type->state;
printf $fh "%sBATTERY %s %s\n", $tspace,$type->name,$type->battery;
if ($type->type =~ /ZONE|GROUP/) {
&dumpList($type,$tspace,$fh);
} elsif ( $type->type =~ /AREA/ ) {
foreach my $item (values %{$type->list}) {
printf $fh "%s%s %s %s\n", $tspace,$item->type,$item->name,$item->hu;
}
}
}
}
sub dumpConfig {
my $configfile = shift;
my $house = shift;
open(my $fh, ">$configfile");
my $space = "";
&dumpList($house,$space,$fh);
close($fh);
}
sub printConfig {
my $configfile = shift;
my $house = shift;
open(OUTFILE, ">$configfile");
select(OUTFILE);
foreach my $struct (values %{$house->list}) {
$type = $struct->type;
$name = $struct->name;
$action = $struct->hu;
if ( $struct->type =~ /BATTERY|SECURITY|STATE|MOTION|LIGHT|FAN|CAMERA|CHRISTMAS/ ) {
if ( $struct->type =~ /BATTERY/ ) {
$action = $struct->battery;
} elsif ( $struct->type =~ /SECURITY/ ) {
$action = $struct->security;
} elsif ( $struct->type =~ /STATE/ ) {
$action = $struct->state;
} elsif ( $struct->type =~ /MOTION|LIGHT|FAN|CAMERA|CHRISTMAS/ ) {
$action = $struct->hu;
}
write(OUTFILE);
}
if ( $struct->type =~ /ZONE/ ) {
select((select(OUTFILE), $~ = "outputFormatZone")[0]);
write(OUTFILE);
}
if ( $struct->type =~ /GROUP/ ) {
select((select(OUTFILE), $~ = "outputFormatGroup")[0]);
write(OUTFILE);
}
if ( $struct->type =~ /AREA/ ) {
select((select(OUTFILE), $~ = "outputFormatArea")[0]);
write(OUTFILE);
select((select(OUTFILE), $~ = "outputFormatItem")[0]);
}
}
# close($fh);
}
sub defaultConfig {
my ($self) = shift;
my $master = X10::Zone->new();
$master->type('ZONE');
$master->parent(undef);
$master->name('Master');
$master->security('OFF');
$master->state('OFF');
$master->battery('20180410');
$master->hu('G1');
my $outdoors = X10::Zone->new();
$outdoors->type('ZONE');
$outdoors->parent($master);
$outdoors->name('Outdoor');
$outdoors->security('OFF');
$outdoors->state('OFF');
$outdoors->battery('20180410');
$outdoors->hu('G2');
my $indoors = X10::Zone->new();
$indoors->type('ZONE');
$indoors->parent($master);
$indoors->name('Indoor');
$indoors->security('OFF');
$indoors->state('OFF');
$indoors->battery('20180410');
$indoors->hu('G3');
my $garage = X10::Zone->new();
$garage->type('ZONE');
$garage->parent($master);
$garage->name('Garage');
$garage->security('OFF');
$garage->state('OFF');
$garage->battery('20180410');
$garage->hu('G4');
$master->add_to_list($outdoors->name, $outdoors);
$master->add_to_list($indoors->name, $indoors);
$master->add_to_list($garage->name, $garage);
my $frontdoor = X10::Zone->new();
$frontdoor->type('GROUP');
$frontdoor->parent($outdoors);
$frontdoor->name('Frontdoor');
$frontdoor->security('OFF');
$frontdoor->state('OFF');
$frontdoor->battery('20180410');
$frontdoor->hu('G5');
my $deck = X10::Zone->new();
$deck->type('GROUP');
$deck->parent($outdoors);
$deck->name('Deck');
$deck->security('OFF');
$deck->state('OFF');
$deck->battery('20180410');
$deck->hu('G6');
my $basement = X10::Zone->new();
$basement->type('GROUP');
$basement->parent($outdoors);
$basement->name('Basement');
$basement->security('OFF');
$basement->state('OFF');
$basement->battery('20180410');
$basement->hu('G7');
$outdoors->add_to_list($frontdoor->name, $frontdoor);
$outdoors->add_to_list($deck->name, $deck);
$outdoors->add_to_list($basement->name, $basement);
my $attic = X10::Zone->new();
$attic->type('GROUP');
$attic->parent($indoors);
$attic->name('Attic');
$attic->security('OFF');
$attic->state('OFF');
$attic->battery('20180410');
$attic->hu('G8');
my $firstfloor = X10::Zone->new();
$firstfloor->type('GROUP');
$firstfloor->parent($indoors);
$firstfloor->name('FirstFloor');
$firstfloor->security('OFF');
$firstfloor->state('OFF');
$firstfloor->battery('20180410');
$firstfloor->hu('G9');
my $secondfloor = X10::Zone->new();
$secondfloor->type('GROUP');
$secondfloor->parent($indoors);
$secondfloor->name('SecondFloor');
$secondfloor->security('OFF');
$secondfloor->state('OFF');
$secondfloor->battery('20180410');
$secondfloor->hu('G10');
my $Basement = X10::Zone->new();
$Basement->type('GROUP');
$Basement->parent($indoors);
$Basement->name('Basement');
$Basement->security('OFF');
$Basement->state('OFF');
$Basement->battery('20180410');
$Basement->hu('G11');
$indoors->add_to_list($attic->name, $attic);
$indoors->add_to_list($firstfloor->name, $firstfloor);
$indoors->add_to_list($secondfloor->name, $secondfloor);
$indoors->add_to_list($Basement->name, $Basement);
my $Attic = X10::Zone->new();
$Attic->type('GROUP');
$Attic->parent($attic);
$Attic->name('Attic');
$Attic->security('OFF');
$Attic->state('OFF');
$Attic->battery('20180410');
$Attic->hu('G12');
$Attic->add_to_list($Attic->name, $Attic);
my $entryway = X10::Zone->new();
$entryway->type('AREA');
$entryway->parent($firstfloor);
$entryway->name('EntryWay');
$entryway->security('OFF');
$entryway->state('OFF');
$entryway->battery('20180410');
$entryway->hu('G13');
my $entrywaylight = X10::Item->new();
$entrywaylight->parent($entryway);
$entrywaylight->type('LIGHT');
$entrywaylight->name('Entryway Light');
$entrywaylight->state('OFF');
$entrywaylight->hu('N1');
$entrywaylight->dimlevel(0);
$entryway->add_to_list($entrywaylight->name, $entrywaylight);
my $livingroom = X10::Zone->new();
$livingroom->type('AREA');
$livingroom->parent($firstfloor);
$livingroom->name('Livingroom');
$livingroom->security('OFF');
$livingroom->state('OFF');
$livingroom->battery('20180410');
$livingroom->hu('G14');
$firstfloor->add_to_list($entryway->name, $entryway);
$firstfloor->add_to_list($livingroom->name, $livingroom);
print Dumper $master;
return $master;
}
####
#!/usr/bin/perl
use Getopt::Long;
use version; our $VERSION = qv('0.01');
use lib qw'lib/ ../lib';
use warnings;
use strict;
use X10::Config;
use X10::Zone;
use X10::Item;
use Data::Dumper;
my $configfile = "/home/mora/Projects/X10/NEWX10/X10/Config";
my $house = X10::Config->new();
if ( not -e $configfile ) {
my $master = X10::Config::defaultConfig(X10::Config::defaultConfig,$house);
X10::Config::printConfig($configfile, $master);
}
####
ZONE Master G1
SECURITY Master OFF
STATE Master OFF
BATTERY Master 20180506
ZONE Garage G2
SECURITY Garage OFF
STATE Garage OFF
BATTERY Garage 20180506
GROUP Garage G3
SECURITY Garage OFF
STATE Garage OFF
BATTERY Garage 20180506
AREA Garage G4
SECURITY Garage OFF
STATE Garage OFF
BATTERY Garage 20180506
LIGHT Garage_Light N1
FAN Garage_Fan N2
GROUP Garage_Outside G5
SECURITY Garage_Outside OFF
STATE Garage_Outside OFF
BATTERY Garage_Outside 20180506
AREA Garage_Outside_Front G6
SECURITY Garage_Outside_Front OFF
STATE Garage_Outside_Front OFF
BATTERY Garage_Outside_Front 20180506
LIGHT Garage_Outside_Light N3
CAMERA Garage_Outside_Camera N4