# Path: auv_control_pi/components/camera.py
# class Camera(ApplicationSession):
#     """Main entry point for controling the Mothership and AUV
#     """
#     name = 'camera'
# 
#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         # TODO check if gopro connected
#         self.gopro = GoProCamera.GoPro()
#         if not self.gopro._camera:
#             logger.warning('Failed to connect to GoPro!')
#             self.gopro = None
#         else:
#             logger.info('Connected to GoPro!')
# 
#     @rpc('camera.take_snapshot')
#     def take_snapshot(self):
#         if self.gopro:
#             url = self.gopro.take_photo()
#             img_uri = download_image(url)
#             print(url)
#         else:
#             img_uri = DataURI.from_file('cat.jpg')
#         return img_uri
# 
#     async def update(self):
#         """Publish current state to anyone listening
#         """
#         while True:
#             image = self.take_snapshot()
# 
#             payload = {
#                 'img': image,
#                 # 'timestamp': timezone.now().isoformat()
#             }
#             self.publish('camera.update', payload)
# 
#             await asyncio.sleep(0.1)


import logging
from autobahn.asyncio.component import Component, run
from django.core.management.base import BaseCommand
from auv_control_pi.components.camera import Camera


logging.basicConfig(level=logging.INFO)


class Command(BaseCommand):

    def handle(self, *args, **options):
        comp = Component(
            transports="ws://crossbar:8080/ws",
            realm="realm1",

# Path: auv_control_pi/components/camera.py
# class Camera(ApplicationSession):
#     """Main entry point for controling the Mothership and AUV
#     """
#     name = 'camera'
# 
#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         # TODO check if gopro connected
#         self.gopro = GoProCamera.GoPro()
#         if not self.gopro._camera:
#             logger.warning('Failed to connect to GoPro!')
#             self.gopro = None
#         else:
#             logger.info('Connected to GoPro!')
# 
#     @rpc('camera.take_snapshot')
#     def take_snapshot(self):
#         if self.gopro:
#             url = self.gopro.take_photo()
#             img_uri = download_image(url)
#             print(url)
#         else:
#             img_uri = DataURI.from_file('cat.jpg')
#         return img_uri
# 
#     async def update(self):
#         """Publish current state to anyone listening
#         """
#         while True:
#             image = self.take_snapshot()
# 
#             payload = {
#                 'img': image,
#                 # 'timestamp': timezone.now().isoformat()
#             }
#             self.publish('camera.update', payload)
# 
#             await asyncio.sleep(0.1)


# Path: auv_control_pi/management/commands/runcamera.py
import logging
from autobahn.asyncio.component import Component, run
from django.core.management.base import BaseCommand
from auv_control_pi.components.camera import Camera



logging.basicConfig(level=logging.INFO)


class Command(BaseCommand):

    def handle(self, *args, **options):
        comp = Component(
            transports="ws://crossbar:8080/ws",
            realm="realm1",

            session_factory=Camera,