App-RPi-EnvUI
view release on metacpan or search on metacpan
lib/App/RPi/EnvUI/API.pm view on Meta::CPAN
'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,
and the mocks have to be set within the test file itself. Do not use this flag
unless you are writing unit tests.
debug_level
Optional, Integer. Send in a level of C<0-7> to enable logging.
Default: C<-1> (logging disabled)
log_file
Optional, String. Name of file to log to. We log to C<STDOUT> by default. The
C<debug_level> parameter must be changed from default for this parameter to have
any effect.
Default: C<undef>
debug_sensor
Optional, Bool. Enable/disable debug print output from the L<RPi::DHT11> sensor
code. Send in C<1> to enable, and C<0> to disable.
Default: C<0> (off)
=head2 action_humidity($aux_id, $humidity)
Performs the check of the current humidity against the configured set limit, and
enables/disables any devices attached to the humidity auxillary GPIO pin, if
set.
Parameters:
lib/App/RPi/EnvUI/API.pm view on Meta::CPAN
Sets/gets the internal L<App::RPi::EnvUI::DB> object. This method allows you to
swap DB objects (and thereby DB handles) within separate processes.
Parameters:
$db_object
Optional, L<App::RPi::EnvUI::DB> object instance.
Returns: The currently loaded DB object instance.
=head2 debug_sensor($bool)
Enable/disable L<RPi::DHT11> sensor's debug print output.
Parameters:
$bool
Optional, Bool. C<1> to enable debugging, C<0> to disable.
Return: Bool. The current state of the sensor's debug state.
Default: False (C<0>)
=head2 env($temp, $humidity)
Sets/gets the current temperature and humidity pair.
Parameters:
All parameters are optional, but if one is sent in, both must be sent in.
$temp
Optional, Integer. The current temperature.
$humidity
Optional, Integer. The current humidity .
Return: A hash reference in the format C<{temp => Int, humidity => Int}>
=head2 env_humidity_aux
Returns the string name of the humidity auxillary channel (default: C<aux2>).
Takes no parameters.
=head2 env_temp_aux
Returns the string name of the temperature auxillary channel (default: C<aux1>).
Takes no parameters.
=head2 env_light_aux
Returns the string name of the light auxillary channel (default: C<aux3>).
Takes no parameters.
=head2 events
Initializes and starts the asynchronous timed events that operate in their own
processes, performing actions outside of the main thread.
Takes no parameters, has no return.
=head2 graph_data
Returns a hash reference with keys C<temp> and C<humidity>, where the values of
each are an array reference of array references with the inner arefs containing
the element number and the temp/humidity value.
It attempts to fetch data for 24 hours, sampling approximately every minute. If
no data is found far enough back, the temp/humidity will be set to C<0>.
=head2 humidity
Returns as an integer, the current humidity level.
=head2 temp
Returns as an integer, the current temperature level.
=head2 set_light_time
Sets in the database the values for lights-on and lights-off time.
Takes no parameters, there is no return.
=head2 log
Returns a pre-configured L<Logging::Simple> object, ready to be cloned with its
C<child()> method.
=head2 log_file($filename)
Sets/gets the log file for the internal logger.
Parameters:
$filename
Optional, String. The name of the log file to use. Note that this won't have any
effect when used in user space, and is mainly a convenience method. It's used
when instantiating a new object.
Return: The string name of the currently in-use log file, if set.
=head2 debug_level($level)
Sets/gets the current debug logging level.
Parameters:
$level
Optional, Integer. Sets the logging level between C<0-7>.
Return: Integer, the current level.
Default: C<-1> (logging disabled)
( run in 1.120 second using v1.01-cache-2.11-cpan-d8267643d1d )