# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2018-02-05 16:19
from __future__ import unicode_literals

import DevicesAPP.models
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
    ]

    operations = [
        migrations.CreateModel(
            name='Beacons',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Identifier', models.CharField(error_messages={'unique': 'Invalid Beacon name - This name already exists in the DB.'}, max_length=20, unique=True)),
                ('Latitude', models.FloatField()),
                ('Longitude', models.FloatField()),
            ],
        ),
        migrations.CreateModel(
            name='DatagramItems',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Tag', models.CharField(max_length=20, unique=True)),
                ('DataType', models.CharField(choices=[('integer', 'Analog Integer'), ('float', 'Analog Float'), ('digital', 'Digital')], max_length=20)),
                ('PlotType', models.PositiveSmallIntegerField(choices=[(0, 'Hard Line'), (1, 'Smoothed Line'), (2, 'Bars'), (3, 'Area')], default=1)),
                ('Units', models.CharField(blank=True, max_length=10, null=True)),
            ],
            options={
                'verbose_name': 'Datagram item',
                'verbose_name_plural': 'Datagram items',
            },
        ),
        migrations.CreateModel(
            name='Datagrams',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Identifier', models.CharField(max_length=20)),
                ('Code', models.PositiveSmallIntegerField(help_text='Identifier byte-type code')),
                ('Type', models.PositiveSmallIntegerField(choices=[(0, 'Synchronous'), (1, 'Asynchronous')])),
            ],
            options={
                'verbose_name': 'Datagram',
                'verbose_name_plural': 'Datagrams',
            },
        ),
        migrations.CreateModel(
            name='DeviceCommands',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Identifier', models.CharField(max_length=10)),
                ('HumanTag', models.CharField(max_length=50)),
            ],
            options={
                'verbose_name': 'Command',
                'verbose_name_plural': 'Commands',
            },
        ),
        migrations.CreateModel(
            name='Devices',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Name', models.CharField(error_messages={'unique': 'Invalid device name - This name already exists in the DB.'}, help_text='Unique identifier of the device. Limited to 50 characters.', max_length=50, unique=True)),
                ('Code', models.PositiveSmallIntegerField(blank=True, error_messages={'unique': 'Invalid device code - This code already exists in the DB.'}, help_text='Unique byte-type identifier of the device. It is used to identify the device within the communication frames.', null=True, unique=True)),
                ('IP', models.GenericIPAddressField(blank=True, error_messages={'unique': 'Invalid IP - This IP already exists in the DB.'}, null=True, protocol='IPv4', unique=True)),
                ('State', models.PositiveSmallIntegerField(choices=[(0, 'STOPPED'), (1, 'RUNNING')], default=0, help_text='Polling state of the device. STOPPED = no polling.')),
                ('Sampletime', models.PositiveSmallIntegerField(default=600, help_text='Elapsed time between two polls to the device.')),
                ('RTsampletime', models.PositiveSmallIntegerField(default=60, help_text='Elapsed time between two polls to the device on realtime polling.')),
                ('LastUpdated', models.DateTimeField(blank=True, null=True)),
                ('NextUpdate', models.DateTimeField(blank=True, null=True)),
                ('Connected', models.BooleanField(default=False)),
                ('CustomLabels', models.CharField(blank=True, default='', max_length=1500)),
                ('Error', models.CharField(blank=True, default='', max_length=100)),
            ],
            options={
                'verbose_name': 'Slave Device',
                'verbose_name_plural': 'Slave Devices',
                'permissions': (('view_devices', 'Can see available devices'), ('scan_devices', 'Can scan for new devices'), ('change_state_devices', 'Can change the state of the devices')),
            },
        ),
        migrations.CreateModel(
            name='DeviceTypes',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Code', models.CharField(help_text='Unique identifier of the device type. Usually between 5 and 8 characters.', max_length=20, unique=True)),
                ('Description', models.CharField(max_length=100)),
                ('MinSampletime', models.PositiveSmallIntegerField(default=10, help_text='Minimum accepted time between two polls. Refer to the device type documentation.')),
                ('Connection', models.PositiveSmallIntegerField(choices=[(0, 'LOCAL'), (1, 'REMOTE OVER TCP'), (2, 'MEMORY')], help_text='The connection can be: \n                                                                    - LOCAL for devices that connect to a pin of the Master unit.\n                                                                    - REMOTE OVER TCP for devices communicating through the WiFi interface.\n                                                                    - MEMORY for devices that reside in the memory of the Master unit.')),
                ('Picture', models.ImageField(blank=True, null=True, upload_to=DevicesAPP.models.path_file_name, verbose_name='DeviceType picture')),
            ],
            options={
                'verbose_name': 'Device type',
                'verbose_name_plural': 'Device types',
                'permissions': (('view_devicetypes', 'Can see available device types'),),
            },
        ),
        migrations.CreateModel(
            name='ItemOrdering',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Order', models.PositiveSmallIntegerField(help_text='Position in the dataframe 1-based')),
                ('DG', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='DevicesAPP.Datagrams')),
                ('ITM', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='DevicesAPP.DatagramItems')),
            ],
            options={
                'verbose_name': 'Item',
                'verbose_name_plural': 'Items',
                'ordering': ('Order',),
            },
        ),
        migrations.CreateModel(
            name='MainDeviceVars',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Label', models.CharField(help_text='Unique identifier for the variable.', max_length=50, unique=True)),
                ('Value', models.DecimalField(decimal_places=2, help_text='Value of the variable.', max_digits=6, null=True)),
                ('DataType', models.CharField(choices=[('integer', 'Analog Integer'), ('float', 'Analog Float'), ('digital', 'Digital')], help_text='Type of data of the variable.', max_length=20)),
                ('PlotType', models.PositiveSmallIntegerField(choices=[(0, 'Hard Line'), (1, 'Smoothed Line'), (2, 'Bars'), (3, 'Area')], default=0, help_text='The type of plot desired for the variable.')),
                ('Units', models.CharField(help_text='Units of the variable.', max_length=10)),
                ('UserEditable', models.BooleanField(default=True)),
            ],
            options={
                'verbose_name': 'Main device var',
                'verbose_name_plural': 'Main device vars',
            },
        ),
        migrations.CreateModel(
            name='MasterGPIOs',
            fields=[
                ('Pin', models.PositiveSmallIntegerField(help_text='The number of the pin following BCM notation.', primary_key=True, serialize=False, unique=True)),
                ('Label', models.CharField(help_text='Label describing the GPIO functional meaning.', max_length=50, unique=True)),
                ('Direction', models.PositiveSmallIntegerField(choices=[(0, 'Output'), (1, 'Input'), (2, 'Sensor')], help_text='Choose wether the GPIO is to be an output, an input or a sensor interface.')),
                ('Value', models.PositiveSmallIntegerField(choices=[(0, 'LOW'), (1, 'HIGH')], default=0, help_text='Set the value of the GPIO (only applies to outputs)')),
            ],
            options={
                'verbose_name': 'Input/Output',
                'verbose_name_plural': 'Inputs/Outputs',
                'permissions': (('view_mastergpios', 'Can see available gpios'), ('change_state_mastergpios', 'Can change the state of the GPIOs')),
            },
        ),
        migrations.AddField(
            model_name='devices',
            name='DVT',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='deviceType', to='DevicesAPP.DeviceTypes'),
        ),
        migrations.AddField(
            model_name='devices',
            name='IO',
            field=models.OneToOneField(blank=True, help_text='The pin of the Master unit to which the device is connected. Only applies to locally connected devices.', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='pin2device', to='DevicesAPP.MasterGPIOs'),
        ),
        migrations.AddField(
            model_name='devicecommands',
            name='DVT',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='DevicesAPP.DeviceTypes'),
        ),
        migrations.AddField(
            model_name='datagrams',
            name='DVT',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='DevicesAPP.DeviceTypes'),
        ),
        migrations.AddField(
            model_name='datagrams',
            name='ITMs',
            field=models.ManyToManyField(through='DevicesAPP.ItemOrdering', to='DevicesAPP.DatagramItems'),
        ),
        migrations.AddField(
            model_name='beacons',
            name='WeatherObserver',
            field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='device2beacon', to='DevicesAPP.Devices'),
        ),
        migrations.AlterUniqueTogether(
            name='devicecommands',
            unique_together=set([('DVT', 'Identifier')]),
        ),
        migrations.AlterUniqueTogether(
            name='datagrams',
            unique_together=set([('DVT', 'Identifier'), ('DVT', 'Code')]),
        ),
    ]
