示例#1
0
        public MiHome(string gatewayPassword = null, string gatewaySid = null)
        {
            _commandsToActions = new Dictionary <string, Action <ResponseCommand> >
            {
                { "get_id_list_ack", DiscoverGatewayAndDevices },
                { "read_ack", ProcessReadAck },
                { "heartbeat", ProcessHeartbeat },
                { "report", ProcessReport },
            };

            _gatewaySid = gatewaySid;

            _transport = new UdpTransport(gatewayPassword);

            _devicesMap = new Dictionary <string, Func <string, MiHomeDevice> >
            {
                { "sensor_ht", sid => new ThSensor(sid) },
                { "weather.v1", sid => new WeatherSensor(sid) },
                { "motion", sid => new MotionSensor(sid) },
                { "plug", sid => new SocketPlug(sid, _transport) },
                { "magnet", sid => new DoorWindowSensor(sid) },
                { "sensor_wleak.aq1", sid => new WaterLeakSensor(sid) },
                { "smoke", sid => new SmokeSensor(sid) },
                { "switch", sid => new Switch(sid) },
                { "sensor_switch.aq2", sid => new Switch2(sid) },
                { "ctrl_neutral2", sid => new WiredDualWallSwitch(sid) },
                { "remote.b286acn01", sid => new WirelessDualWallSwitch(sid) },
            };

            _receiveTask = Task.Run(() => StartReceivingMessages(_cts.Token), _cts.Token);

            _transport.SendCommand(new DiscoverGatewayCommand());
        }
示例#2
0
        public MiHome(string gatewayPassword = null, string gatewaySid = null)
        {
            _commandsToActions = new Dictionary <string, Action <ResponseCommand> >
            {
                { "get_id_list_ack", DiscoverGatewayAndDevices },
                { "read_ack", ProcessReadAck },
                { "heartbeat", ProcessHeartbeat },
                { "report", ProcessReport },
            };

            _gatewaySid = gatewaySid;

            _transport = new UdpTransport(gatewayPassword);

            _receiveTask = Task.Run(() => StartReceivingMessages(_cts.Token), _cts.Token);

            _transport.SendCommand(new DiscoverGatewayCommand());
        }