def projector_on(): success = False try: with Projector() as p: success = p.power_on() except: logger.exception('Unable to turn on projector. Is it connected?') finally: report_pi_status_task() return flask.jsonify(status=success)
def current_status(): """ Construct status information dictionary suitable for use with status reporting / status API """ from pivideo import (play_list, photo_overlay, encoder, transcode_queue, PI_HARDWARE_ADDRESS, cpu_temp, PI_IP_ADDRESS, version, disk_usage, file_cache_size) encoder_status = { 'active': encoder.is_active() if encoder else False, 'queue': [item for item in transcode_queue] } play_list_active = play_list is not None and not play_list.stopped play_list_status = { 'active': play_list_active, 'audio': play_list.player.audio if play_list_active and play_list.player else {}, 'video': play_list.player.video if play_list_active and play_list.player else {}, 'mediafile': play_list.player.mediafile if play_list_active and play_list.player else None, 'entries': play_list.entries if play_list_active else [], 'loop': play_list.loop if play_list_active else False } overlay_active = photo_overlay.is_active() if photo_overlay else False overlay_status = { 'active': overlay_active, 'photo': photo_overlay.photo if photo_overlay else None, 'layer': photo_overlay.layer if photo_overlay else None, 'x': photo_overlay.x if photo_overlay else None, 'y': photo_overlay.y if photo_overlay else None } projector_status = {"connected": False} try: with Projector() as p: projector_status['on'] = p.is_on() if projector_status['on']: projector_status['position'] = p.position_status() projector_status['input_source'] = p.input_source() projector_status['connected'] = True except: logger.exception( "Unable to determine current projector status. Is it connected?") scheduled_jobs = [str(job) for job in schedule.jobs] tunnel_info = {} try: tunnels_response = requests.get('http://localhost:4040/api/tunnels') if tunnels_response.status_code == 200: tunnels = tunnels_response.json().get('tunnels', []) for tunnel in tunnels: tunnel_info[tunnel['name']] = tunnel.get('public_url') except: logger.exception('Unable to determine ngrok tunnel information') sd_card = disk_usage() sd_card['file_cache'] = file_cache_size() return { 'hardware_address': PI_HARDWARE_ADDRESS, 'ip_address': PI_IP_ADDRESS, 'file_cache': glob.glob('/file_cache/*'), 'scheduled_jobs': scheduled_jobs, 'encoder': encoder_status, 'play_list': play_list_status, 'overlay': overlay_status, 'projector': projector_status, 'tunnels': tunnel_info, 'cpu_temp': cpu_temp.temperature if cpu_temp else None, 'version': version, 'sd_card': sd_card }