App-RPi-EnvUI
view release on metacpan or search on metacpan
lib/App/RPi/EnvUI/API.pm view on Meta::CPAN
'id'
];
my @data;
for my $directive (keys %{ $conf->{$conf_section} }){
push @data, [
$conf->{$conf_section}{$directive},
$directive
];
# populate some internal variables from the 'core'
# config section
if ($conf_section eq 'core'){
next if $directive eq 'testing';
$self->{$directive} = $conf->{$conf_section}{$directive};
}
}
$self->db->update_bulk(@$db_struct, \@data);
}
$self->db->commit;
}
sub _reset {
my $self = shift;
# reset dynamic db attributes
my $log = $log->child('_reset');
$log->_5("reset() called");
$self->db->update_bulk_all(
'aux', 'state', [0]
);
$self->db->update_bulk_all(
'aux', 'override', [0]
);
$self->db->update_bulk_all(
'aux', 'on_time', [0]
);
# remove all statistics
$self->db->delete('stats');
}
sub _set_light_off_time {
my ($dt_on, $on_time) = @_;
my $dt_off = $dt_on->clone;
$dt_off->add(hours => $on_time);
return $dt_off;
}
sub _set_light_on_time {
my ($dt_now, $on_at) = @_;
my $dt_on = $dt_now->clone;
$dt_on->set_second(0);
$dt_on->set_hour((split(/:/, $on_at))[0]);
$dt_on->set_minute((split(/:/, $on_at))[1]);
if ($dt_on < $dt_now){
# this situation happens if the light on and off times are within the
# same 24 hour period. We check to see if the updated on time is less
# than now; if it is, we need to advance to tomorrow
$dt_on->add(hours => 24);
}
return $dt_on;
}
sub _ui_test_mode {
return -e 't/testing.lck';
}
1;
__END__
=head1 NAME
App::RPi::EnvUI::API - Core API abstraction class for the
App::RPi::EnvUI web app
=head1 SYNOPSIS
my $api = App::RPi::EnvUI::API->new;
... #FIXME: add a real example
=head1 DESCRIPTION
This class can be used outside of the L<App::RPi::EnvUI> web application to
update settings, read statuses, perform analysis and generate reports.
It's primary purpose is to act as an intermediary between the web app itself,
the asynchronous events that run within their own processes, the environment
sensors, and the application database.
=head1 METHODS
=head2 new(%args)
Instantiates a new core API object. Send any/all parameters in within hash
format (eg: C< testing =\> 1)).
Parameters:
config
Optional, String. Name of the configuration file to use. Very rarely required.
Default: C<config/envui.json>
testing
Optional, Bool. Send in C<1> to enable testing, C<0> to disable it.
Default: C<0>
test_mock
This flag is only useful when C<testing> param is set to true, and should only
be used when writing unit tests for the L<App::RPi::EnvUI::Event> class. Due to
the way the system works, the API has to avoid mocking out items in test mode,
( run in 0.684 second using v1.01-cache-2.11-cpan-39bf76dae61 )