diff --git a/lib/IntelliHome/RPC/Service/DB.pm b/lib/IntelliHome/RPC/Service/DB.pm index b0452ae..99592a4 100644 --- a/lib/IntelliHome/RPC/Service/DB.pm +++ b/lib/IntelliHome/RPC/Service/DB.pm @@ -14,34 +14,45 @@ IntelliHome::RPC::Service::DB inherits all methods from L "NODENAME", port=>"NODEPORT"}) +=item add_node({ name => "NODENAME", port=>"NODEPORT"}, {id=>$room->id }) -Add the node to the db +Add the node to the db (the id is for roomid) -=item add_room({ name => "NODENAME", port=>"NODEPORT"}) +=item add_room({name => "test", location => "bedroom first floor" }) -Add the room to the db +Add the room to the db -=item add_gpio({ name => "NODENAME", port=>"NODEPORT"}) +=item add_gpio({'pin_id' => '22','type' => '1','driver' => 'IntelliHome::Driver::GPIO::Mono'},{ id => $node->id }) -Add the node to the db +Add the gpio to the db (the id is for nodeid) -=item add_tag({ name => "NODENAME", port=>"NODEPORT"}) +=item add_tag({ tag => "test" }, { id => $gpio->id }) -Add the node to the db +Add the tag to the db (the id is for gpioid) -=item delete_node({ name => "NODENAME", port=>"NODEPORT"}) +=item add_pin({ pin => 44, type => 4, value => 0 }, { id => $gpio->id }) -Add the node to the db +Add the pin to the db (the id is for gpioid) -=item delete_gpio({ name => "NODENAME", port=>"NODEPORT"}) +=item delete_node("Node", 42) -Add the node to the db +delete the node to the db -=item delete_tag({ name => "NODENAME", port=>"NODEPORT"}) +=item delete_room("Room", 42) -Add the node to the db +delete the room to the db +=item delete_gpio("GPIO", 42) + +delete the gpio to the db + +=item delete_tag("Tag", 42) + +delete the tag to the db + +=item delete_pin("Pin", 42) + +delete the pin to the db =back @@ -62,60 +73,78 @@ use YAML qw'freeze thaw'; sub add_node { my ( $self, $tx, $node, $room ) = @_; - - return [ map { $_ = freeze $_; $_ } - $self->IntelliHome->Parser->Backend->addNode( $node, $room ) ] - if ( $self->IntelliHome->Parser->Backend->can("addNode") + my $newnode; + return + !( $self->IntelliHome->Parser->Backend->can("addNode") && defined($room) - && defined($node) ); + && defined($node) ) ? undef + : ( $newnode + = $self->IntelliHome->Parser->Backend->addNode( $node, $room ) ) + ? $newnode->serialize + : undef; } sub delete { my ( $self, $tx, $entity, $id ) = @_; - return [ - $self->IntelliHome->Parser->Backend->delete_element( $entity, $id ) - ] - if ( $self->IntelliHome->Parser->Backend->can("delete_element") + return !( $self->IntelliHome->Parser->Backend->can("delete_element") && defined($entity) - && defined($id) ); + && defined($id) ) + ? undef + : $self->IntelliHome->Parser->Backend->delete_element( $entity, $id ); } sub add_room { my ( $self, $tx, $room ) = @_; - return [ map { $_ = freeze $_; $_ } - $self->IntelliHome->Parser->Backend->add_room($room) ] - if ( $self->IntelliHome->Parser->Backend->can("add_room") - && defined($room) ); + my $newroom; + return + !( $self->IntelliHome->Parser->Backend->can("add_room") + && defined($room) ) ? undef + : ( $newroom = $self->IntelliHome->Parser->Backend->add_room($room) ) + ? $newroom->serialize + : undef; } sub add_gpio { - my ( $self, $tx,$gpio, $node ) = @_; - return [ map { $_ = freeze $_; $_ } - $self->IntelliHome->Parser->Backend->add_gpio( $gpio, $node ) ] - if ( $self->IntelliHome->Parser->Backend->can("add_gpio") + my ( $self, $tx, $gpio, $node ) = @_; + my $newgpio; + + return + !( $self->IntelliHome->Parser->Backend->can("add_gpio") && defined($gpio) - && defined($node) ); + && defined($node) ) ? undef + : ( $newgpio + = $self->IntelliHome->Parser->Backend->add_gpio( $gpio, $node ) ) + ? $newgpio->serialize + : undef; } sub add_tag { my ( $self, $tx, $tag, $gpio ) = @_; + my $newtag; - return [ map { $_ = freeze $_; $_ } - $self->IntelliHome->Parser->Backend->add_tag( $tag, $gpio ) ] - if ( $self->IntelliHome->Parser->Backend->can("add_tag") + return + !( $self->IntelliHome->Parser->Backend->can("add_tag") && defined($tag) - && defined($gpio) ); + && defined($gpio) ) ? undef + : ( $newtag + = $self->IntelliHome->Parser->Backend->add_tag( $tag, $gpio ) ) + ? $newtag->serialize + : undef; } sub add_pin { my ( $self, $tx, $pin, $gpio ) = @_; - - return [ map { $_ = freeze $_; $_ } - $self->IntelliHome->Parser->Backend->add_pin( $pin, $gpio ) ] - if ( $self->IntelliHome->Parser->Backend->can("add_pin") + my $newpin; + return + !( $self->IntelliHome->Parser->Backend->can("add_pin") && defined($pin) - && defined($gpio) ); + && defined($gpio) ) ? undef + : ( $newpin + = $self->IntelliHome->Parser->Backend->add_pin( $pin, $gpio ) ) + ? $newpin->serialize + : undef; } -__PACKAGE__->register_rpc_method_names( 'add_node', 'add_room', 'add_gpio', 'add_tag', 'add_pin', 'delete' ); +__PACKAGE__->register_rpc_method_names( 'add_node', 'add_room', 'add_gpio', + 'add_tag', 'add_pin', 'delete' ); 1;