# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2018-02-07 13:48
from __future__ import unicode_literals

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


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('contenttypes', '0002_remove_content_type_name'),
    ]

    operations = [
        migrations.CreateModel(
            name='AutomationRules',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Identifier', models.CharField(max_length=50, unique=True)),
                ('Active', models.BooleanField(default=False)),
                ('OnError', models.PositiveSmallIntegerField(choices=[(0, 'False'), (1, 'True')], default=0)),
                ('OperatorPrev', models.CharField(blank=True, choices=[('&', 'AND'), ('|', 'OR')], max_length=2, null=True)),
                ('Action', models.CharField(blank=True, max_length=500)),
                ('PreviousRule', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='previous_rule', to='MainAPP.AutomationRules')),
            ],
            options={
                'verbose_name': 'Automation rule',
                'verbose_name_plural': 'Automation rules',
                'permissions': (('view_rules', 'Can see available automation rules'), ('activate_rules', 'Can change the state of the rules'), ('edit_rules', 'Can create and edit a rule')),
            },
        ),
        migrations.CreateModel(
            name='AutomationVariables',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Label', models.CharField(max_length=50)),
                ('Tag', models.CharField(max_length=50)),
                ('Device', models.CharField(max_length=50)),
                ('Table', models.CharField(max_length=50)),
                ('BitPos', models.PositiveSmallIntegerField(blank=True, null=True)),
                ('Sample', models.PositiveSmallIntegerField(default=0)),
                ('Units', models.CharField(blank=True, help_text='Units of the variable.', max_length=10, null=True)),
            ],
            options={
                'verbose_name': 'Automation variable',
                'verbose_name_plural': 'Automation variables',
            },
        ),
        migrations.CreateModel(
            name='RuleItems',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('order', models.PositiveSmallIntegerField(help_text='Order of execution')),
                ('PreVar1', models.CharField(blank=True, choices=[('', 'None'), ('not ', 'NOT')], default='', max_length=3)),
                ('Operator12', models.CharField(choices=[('==', '=='), ('>', '>'), ('>=', '>='), ('<', '<'), ('<=', '<='), ('!=', '!='), ('&', 'AND'), ('|', 'OR')], max_length=2)),
                ('PreVar2', models.CharField(blank=True, choices=[('', 'None'), ('not ', 'NOT')], default='', max_length=3)),
                ('Var2Hyst', models.DecimalField(decimal_places=2, default=0.5, max_digits=6)),
                ('IsConstant', models.BooleanField(default=False)),
                ('Constant', models.FloatField(blank=True, null=True)),
                ('Operator3', models.CharField(blank=True, choices=[('&', 'AND'), ('|', 'OR')], max_length=2, null=True)),
                ('Rule', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='MainAPP.AutomationRules')),
                ('Var1', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='var1', to='MainAPP.AutomationVariables')),
                ('Var2', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='var2', to='MainAPP.AutomationVariables')),
            ],
            options={
                'verbose_name': 'Automation expression',
                'verbose_name_plural': 'Automation expressions',
            },
        ),
        migrations.CreateModel(
            name='Subsystems',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('object_id', models.CharField(max_length=50)),
                ('Name', models.PositiveSmallIntegerField(choices=[(0, 'Heating/Cooling'), (1, 'Garden'), (2, 'Alarm')])),
                ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
            ],
            options={
                'verbose_name': 'Subsystem',
                'verbose_name_plural': 'Subsystems',
            },
        ),
        migrations.AlterUniqueTogether(
            name='automationvariables',
            unique_together=set([('Tag', 'BitPos', 'Table')]),
        ),
        migrations.AddField(
            model_name='automationrules',
            name='RuleItems',
            field=models.ManyToManyField(to='MainAPP.RuleItems'),
        ),
    ]
