App-RPi-EnvUI

 view release on metacpan or  search on metacpan

lib/App/RPi/EnvUI/API.pm  view on Meta::CPAN

package App::RPi::EnvUI::API;

use strict;
use warnings;
use App::RPi::EnvUI::DB;
use App::RPi::EnvUI::Event;
use Carp qw(confess);
use Crypt::SaltedHash;
use Data::Dumper;
use DateTime;
use JSON::XS;
use Logging::Simple;
use Mock::Sub no_warnings => 1;
use RPi::Const qw(:all);

our $VERSION = '0.30';

# configure handlers

BEGIN {
    if ($ENV{SUPPRESS_WARN}){
        $SIG{__WARN__} = sub {};
    }
}

# mocked sub handles for when we're in testing mode
# readPin(), writePin() and pinMode() from wiringPi

our ($temp_sub, $hum_sub, $rp_sub, $wp_sub, $pm_sub);

# class variables

my $api;
my $master_log;
my $log;
my $sensor;
my $events;

# class variables for the light operation

our ($light_on_at, $light_on_hours);
our ($dt_now_test, $dt_light_on, $dt_light_off);
our $light_initialized = 0;

# public environment methods

sub new {

    # return the stored object if we've already run new()

    if (defined $api){
        $log->_5('returning stored API object');
        return $api if defined $api;
    }

    my $self = bless {}, shift;

    my $caller = (caller)[0];
    $self->_args(@_, caller => $caller);

    warn "API in test mode\n" if $self->testing;

    $self->_init;

    $api = $self;

    $log->_5("successfully initialized the system");

    if (! $self->testing && ! defined $events){
        $self->events;
        $log->_5('successfully created new async events')



( run in 2.495 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )