Inheritance: HA4IoT.Contracts.Services.ServiceBase
コード例 #1
0
        public OpenWeatherMapWeatherStationApiDispatcher(OpenWeatherMapService weatherStation, IApiController apiController)
        {
            if (weatherStation == null)
            {
                throw new ArgumentNullException(nameof(weatherStation));
            }
            if (apiController == null)
            {
                throw new ArgumentNullException(nameof(apiController));
            }

            _weatherStation = weatherStation;
            _apiController  = apiController;
        }
コード例 #2
0
        protected override async Task ConfigureAsync(IDeviceService deviceService)
        {
            var pi2PortController = new Pi2GpioService();
            
            var openWeatherMapService = new OpenWeatherMapService(
                ServiceLocator.GetService<IDateTimeService>(),
                ServiceLocator.GetService<ISchedulerService>(),
                ServiceLocator.GetService<ISystemInformationService>());

            ServiceLocator.RegisterService(typeof(IOutdoorTemperatureService), new OutdoorTemperatureService(openWeatherMapService, ServiceLocator.GetService<IDateTimeService>()));
            ServiceLocator.RegisterService(typeof(IOutdoorHumidityService), new OutdootHumidityService(openWeatherMapService, ServiceLocator.GetService<IDateTimeService>()));
            ServiceLocator.RegisterService(typeof(IDaylightService), new DaylightService(openWeatherMapService, ServiceLocator.GetService<IDateTimeService>()));
            ServiceLocator.RegisterService(typeof(IWeatherService), new WeatherService(openWeatherMapService, ServiceLocator.GetService<IDateTimeService>()));
            ServiceLocator.RegisterService(typeof(OpenWeatherMapService), openWeatherMapService);

            var ccToolsFactory = new CCToolsBoardService(this, GetDevice<II2CBusService>());
            var hsrt16 = ccToolsFactory.CreateHSRT16(Device.CellarHSRT16, new I2CSlaveAddress(32));

            var garden = this.CreateArea(RoomId.Garden)
                .WithLamp(Garden.LampTerrace, hsrt16[HSRT16Pin.Relay15])
                .WithLamp(Garden.LampGarage, hsrt16[HSRT16Pin.Relay14])
                .WithLamp(Garden.LampTap, hsrt16[HSRT16Pin.Relay13])
                .WithLamp(Garden.SpotlightRoof, hsrt16[HSRT16Pin.Relay12])
                .WithLamp(Garden.LampRearArea, hsrt16[HSRT16Pin.Relay11])
                .WithSocket(Garden.SocketPavillion, hsrt16[HSRT16Pin.Relay10])
                // 9 = free
                .WithLamp(Garden.LampParkingLot, new LogicalBinaryOutput().WithOutput(hsrt16[HSRT16Pin.Relay8]).WithOutput(hsrt16[HSRT16Pin.Relay6]).WithOutput(hsrt16[HSRT16Pin.Relay7]))
                .WithButton(Garden.Button, pi2PortController.GetInput(4).WithInvertedState())
                .WithStateMachine(Garden.StateMachine, SetupStateMachine);

            garden.GetStateMachine(Garden.StateMachine).ConnectMoveNextAndToggleOffWith(garden.GetButton(Garden.Button));

            garden.SetupConditionalOnAutomation()
                .WithActuator(garden.GetLamp(Garden.LampParkingLot))
                .WithOnAtNightRange()
                .WithOffBetweenRange(TimeSpan.Parse("22:30:00"), TimeSpan.Parse("05:00:00"));

            TimerService.Tick += (s, e) => { pi2PortController.PollOpenInputPorts(); };

            await base.ConfigureAsync();
        }