gate: Excange real light sensor with Astral
Signed-off-by: tkl <tkl@blackfinn.de>
This commit is contained in:
parent
ef2582dfa7
commit
387a447b99
@ -5,6 +5,7 @@ Created on Dec 19, 2016
|
|||||||
'''
|
'''
|
||||||
import datetime
|
import datetime
|
||||||
import logging
|
import logging
|
||||||
|
import pytz
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
import time
|
import time
|
||||||
@ -14,6 +15,8 @@ import gate_guard.light_sensor
|
|||||||
import gate_guard.engine
|
import gate_guard.engine
|
||||||
import gate_guard.power_sensor
|
import gate_guard.power_sensor
|
||||||
|
|
||||||
|
from astral import Astral
|
||||||
|
|
||||||
STATE_INIT_1 = "init_1"
|
STATE_INIT_1 = "init_1"
|
||||||
STATE_INIT_2 = "init_2"
|
STATE_INIT_2 = "init_2"
|
||||||
STATE_INIT_3 = "init_3"
|
STATE_INIT_3 = "init_3"
|
||||||
@ -67,6 +70,25 @@ def check_to_close(light_avg):
|
|||||||
ret = True
|
ret = True
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
class FakeLight(object):
|
||||||
|
'''Simulate light sensor time based in order to eliminate defect light sensor.'''
|
||||||
|
def __init__(self, bus, addr):
|
||||||
|
self.astral = Astral()
|
||||||
|
self.astral.solar_depression = 'civil'
|
||||||
|
self.city = self.astral['Berlin']
|
||||||
|
self.opening_hour = 8
|
||||||
|
|
||||||
|
def read(self):
|
||||||
|
fake_light = 0
|
||||||
|
now = datetime.datetime.now(pytz.timezone(self.city.timezone))
|
||||||
|
|
||||||
|
sun = self.city.sun(now, local=True)
|
||||||
|
sunset = sun['sunset']
|
||||||
|
|
||||||
|
if now.hour >= self.opening_hour and now < sunset:
|
||||||
|
fake_light = 1
|
||||||
|
return fake_light
|
||||||
|
|
||||||
|
|
||||||
class Gate(object):
|
class Gate(object):
|
||||||
'''Main class of the chickenhouse gates.'''
|
'''Main class of the chickenhouse gates.'''
|
||||||
@ -83,8 +105,9 @@ class Gate(object):
|
|||||||
STATE_CLOSING_2:self.__closing_2_handler}
|
STATE_CLOSING_2:self.__closing_2_handler}
|
||||||
self.__next_state = STATE_INIT_1
|
self.__next_state = STATE_INIT_1
|
||||||
self.__last_state = STATE_OPENED
|
self.__last_state = STATE_OPENED
|
||||||
self.__light_sensor = gate_guard.light_sensor.LightSensor(
|
# self.__light_sensor = gate_guard.light_sensor.LightSensor(
|
||||||
LIGHT_SENSOR_I2C_BUS, LIGHT_SENSOR_I2C_ADDRESS)
|
# LIGHT_SENSOR_I2C_BUS, LIGHT_SENSOR_I2C_ADDRESS)
|
||||||
|
self.__light_sensor = FakeLight(LIGHT_SENSOR_I2C_BUS, LIGHT_SENSOR_I2C_ADDRESS)
|
||||||
self.__light_data = gate_guard.data_buffer.DataBuffer(
|
self.__light_data = gate_guard.data_buffer.DataBuffer(
|
||||||
LIGHT_CONSECUTIVE_READS)
|
LIGHT_CONSECUTIVE_READS)
|
||||||
self.__engine_1 = gate_guard.engine.Engine(gpio_1=ENGINE_1_PIN_1, gpio_2=ENGINE_1_PIN_2)
|
self.__engine_1 = gate_guard.engine.Engine(gpio_1=ENGINE_1_PIN_1, gpio_2=ENGINE_1_PIN_2)
|
||||||
|
Loading…
Reference in New Issue
Block a user