Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feature-webui
Browse files Browse the repository at this point in the history
  • Loading branch information
skullbocks committed Jul 18, 2014
2 parents 88821ac + 9913f04 commit 7c7c5b5
Show file tree
Hide file tree
Showing 30 changed files with 861 additions and 27 deletions.
7 changes: 7 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
* Add the event collection where the master node polls information status and triggers a specified method of a plugin
* Plugins that handles physical situations must insert events in the collections to be called when necessary

* Deeme: Emit hourly, daily, half-hour by an integrated cron daemon.

* XXX: Aggiungere l'event emitter anche a StatusListener -> plugin aggiornamento di stato e Aggiungere l'event emitter anche all'rpc.

*https://metacpan.org/pod/Mojo::EventEmitter -> making a Mojo::EventEmitter binded to Mongo db collection

* Split parsing modules (Parser::*) because events would require a different Parser (Unique, just changes the DB Backend)
* With the avaibility of time, integrating Bread::Board

Expand Down
2 changes: 1 addition & 1 deletion bin/intellihome-deployer
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ my $Deployer = $Backend->new;
eval {
$Output->error("$Deployer hasn't $action") and die(EXIT_ERROR)
unless ( $Deployer->can($action) );
$Deployer->$action(@ARGV);
};
if ($@) {
$Output->error($@);
}

$Deployer->$action(@ARGV);
sub help {
$Output->info(
"At least an argument to --cmd it's required : [install,upgrade,prepare] "
Expand Down
4 changes: 4 additions & 0 deletions config/rpc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
rpc_host: 'localhost'
rpc_port: '3000'

10 changes: 9 additions & 1 deletion cpanfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
requires 'AnyEvent';
requires 'AnyEvent::Filesys::Notify';
requires 'Carp::Always';
requires 'DBIx::Class::Core';
requires 'DBIx::Class::DeploymentHandler';
requires 'DBIx::Class::Schema';
requires 'Deeme';
requires 'Deeme::Backend::Mango';
requires 'Deeme::Backend::Memory';
requires 'Digest::SHA1';
requires 'Encode';
requires 'File::Find::Object';
requires 'File::Path';
requires 'Getopt::Long';
requires 'LWP::UserAgent';
requires 'Log::Any';
Expand All @@ -22,7 +28,6 @@ requires 'Moo::Role';
requires 'MooX::Singleton';
requires 'Moose';
requires 'Moose::Role';
requires 'MooseX::Singleton';
requires 'Net::SSH::Any';
requires 'Term::ANSIColor';
requires 'Time::HiRes';
Expand All @@ -31,12 +36,15 @@ requires 'URI';
requires 'Unix::PID';
requires 'YAML::Tiny';
requires 'feature';
requires 'forks';
requires 'namespace::autoclean';
requires 'perl', '5.010';

on configure => sub {
requires 'ExtUtils::MakeMaker';
};

on test => sub {
requires 'MojoX::JSON::RPC::Client';
requires 'Test::More';
};
90 changes: 90 additions & 0 deletions ex/insertdb.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/perl

use strict;
use warnings;
use lib './lib';
use IntelliHome::Schema::SQLite::Schema;

my $schema = IntelliHome::Schema::SQLite::Schema->connect(
'dbi:SQLite:/var/lib/intellihome/intellihome.db');

my $room_data = {
'name' => "cucina",
'location' => "cucina"
};

my $room = $schema->resultset('Room')->create($room_data);

my $node_data1 = {
'roomid' => $room->id,
'name' => 'master',
'host' => 'localhost',
'port' => 23459,
'type' => 'master',
'username' => 'username',
'password' => 'passwd'
};

my $node_data2 = {
'roomid' => $room->id,
'name' => 'master',
'host' => '127.0.0.1',
'port' => 23456,
'type' => 'node',
'username' => 'username',
'password' => 'passwd'
};

my $node_one = $schema->resultset('Node')->create($node_data1);
my $node_two = $schema->resultset('Node')->create($node_data2);

my $gpio_data1 = {
'nodeid' => $node_two->id,
'num_gpio' => 1,
'type' => 3,
'value' => 0,
'driver' => "IntelliHome::Driver::GPIO::Mono"
};

my $gpio_data2 = {
'nodeid' => $node_two->id,
'num_gpio' => 2,
'type' => 1,
'value' => 1,
'driver' => "IntelliHome::Driver::GPIO::Dual"
};

my $gpio_one = $schema->resultset('GPIO')->create($gpio_data1);
my $gpio_two = $schema->resultset('GPIO')->create($gpio_data2);

my $tag_data1 = {
'gpioid' => $gpio_one->id,
'tag' => "serranda 1"
};

my $tag_data2 = {
'gpioid' => $gpio_two->id,
'tag' => "serranda 2"
};

my $tag_one = $schema->resultset('Tag')->create($tag_data1);
my $tag_two = $schema->resultset('Tag')->create($tag_data2);

my $user_data1 = {
'username' => "user1",
'password' => "password",
'name' => "User 1",
'admin' => 0
};

my $user_data2 = {
'username' => "user2",
'password' => "password",
'name' => "User 2",
'admin' => 1
};

my $user_one = $schema->resultset('User')->create($user_data1);
my $user_two = $schema->resultset('User')->create($user_data2);


49 changes: 35 additions & 14 deletions lib/IntelliHome/Config.pm
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,20 @@ use Moo;
with 'MooX::Singleton';

has 'Nodes' => ( is => "rw" );
has 'RPCConfiguration' => ( is => "rw", default => sub { {} } );
has 'DBConfiguration' => ( is => "rw", default => sub { {} } );

has 'Dirs' => ( is => "rw" );
has 'Dirs' => ( is => "rw", default=>sub{['./config']});
has 'Output' => (
is => "rw",
default => sub { return IntelliHome::Interfaces::Terminal->instance}
default => sub { return IntelliHome::Interfaces::Terminal->instance }
);
sub BUILD{
my $self=shift;

sub BUILD {
my $self = shift;
$self->read;
}

sub read {
my $self = shift;
my $output = $self->Output;
Expand All @@ -40,22 +43,28 @@ sub read {
#Importing data in my hash with an index by host (for convenience)
foreach my $Key ( @{$yaml} ) {

if ( exists( $Key->{db_dsn} )
and exists( $Key->{db_name} )
and exists( $Key->{database_backend} )
if (exists(
$Key->{database_backend})
and exists( $Key->{language} )


# and exists($Key->{username})
# and exists ($Key->{password})

)
{
$self->DBConfiguration->{'db_dsn'} = $Key->{'db_dsn'};
$output->info( "Database: "
. $self->DBConfiguration->{'db_dsn'} );
$self->DBConfiguration->{'db_name'}
= $Key->{'db_name'};
$output->info( "Database: "
. $self->DBConfiguration->{'db_name'} );
if ( exists( $Key->{db_dsn} )
and exists( $Key->{db_name} ) )
{
$self->DBConfiguration->{'db_dsn'}
= $Key->{'db_dsn'};
$output->info( "Database: "
. $self->DBConfiguration->{'db_dsn'} );
$self->DBConfiguration->{'db_name'}
= $Key->{'db_name'};
$output->info( "Database: "
. $self->DBConfiguration->{'db_name'} );
}
$self->DBConfiguration->{'database_backend'}
= $Key->{'database_backend'};
$output->info( "Database backend: "
Expand Down Expand Up @@ -125,6 +134,18 @@ sub read {
= $Key->{mic_step}
if ( exists( $Key->{mic_step} ) );
}

if ( exists( $Key->{rpc_host} )
and exists( $Key->{rpc_port} )
)
{
$self->RPCConfiguration->{'rpc_host'} = $Key->{'rpc_host'};
$output->info( "RPC-Host: "
. $self->RPCConfiguration->{'rpc_host'} );
$self->RPCConfiguration->{'rpc_port'} = $Key->{'rpc_port'};
$output->info( "RPC-Port: "
. $self->RPCConfiguration->{'rpc_port'} );
}
}

}
Expand Down
70 changes: 70 additions & 0 deletions lib/IntelliHome/Deployer/Schema/SQLite.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package IntelliHome::Deployer::Schema::SQLite;

use strict;
use Carp::Always;
use warnings;
use 5.010;
use DBIx::Class::DeploymentHandler;
use lib '../../';
use IntelliHome::Schema::SQLite::Schema;
use File::Path qw(make_path);
use constant DBDIR => "/var/lib/intellihome/";
use Moo;

has 'dh' => (
is => "rw",
lazy => 1,
default => sub {
make_path DBDIR unless -d DBDIR;
return DBIx::Class::DeploymentHandler->new(
{ schema => IntelliHome::Schema::SQLite::Schema->connect(
'dbi:SQLite:' . DBDIR . 'intellihome.db'
),
script_directory => DBDIR . 'db_upgrades',
databases => 'SQLite',
force_overwrite => 1,
schema_version => 1 #TODO pass version
}
);
}
);

sub prepare {
my $self = shift;
my $from_version = shift;
my $to_version = shift;
$self->dh->prepare_install;

if ( defined $from_version && defined $to_version ) {
$self->dh->prepare_upgrade(
{ from_version => $from_version,
to_version => $to_version,
}
);
}
}

sub install {
my $self = shift;
my $version = shift;
if ( defined $version ) {
$self->dh->install( { schema_version => $version } );
}
else {
$self->dh->install;
}
}

sub upgrade {
return shift->upgrade;
}

sub database_version {
return shift->database_version;
}

sub schema_version {
return shift->schema_version;
}

1;
1 change: 1 addition & 0 deletions lib/IntelliHome/IntelliHomeNode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require IntelliHome::Workers::Node::AudioProcess;
require IntelliHome::Schema::YAML::Node;
require IntelliHome::Workers::Node::MicAdjust;
require AnyEvent;
use Carp::Always;
use base qw(Exporter);
use IntelliHome::Utils qw(daemonize cleanup);
use Moo;
Expand Down
Loading

0 comments on commit 7c7c5b5

Please sign in to comment.