Пример #1
0
 public static TuyaBaseResponse SendRequest(TuyaDevice device, IReadOnlyCollection <byte> payload)
 {
     return(new TuyaBaseResponse(Send(new TuyaBaseBaseRequest
     {
         OpCode = 10,
         Payload = payload,
         Size = payload.Count
     }.Serialize(), device.IpAddress.ToString(), device.Port).Result));
 }
Пример #2
0
        public DeviceActor(string id)
        {
            var device = new TuyaDevice {
                Id = id
            };

            var logger = Context.GetLogger();

            Receive <Add>(
                command =>
            {
                device.Name      = command.Name;
                device.IpAddress = command.IpAddress;
                device.SecretKey = command.SecretKey;

                logger.Info(
                    $"{command.Id} actor been added.");
            });

            Receive <Update>(
                command =>
            {
                device.Name      = command.Name;
                device.IpAddress = command.IpAddress;
                device.SecretKey = command.SecretKey;

                logger.Info(
                    $"{command.Id} actor has been updated.");
            });

            Receive <Get>(
                command =>
            {
                logger.Info(
                    $"{command.Id} actor getting Device");

                device.GetInfo();

                Sender.Tell(device);
            });

            Receive <Remove>(
                command =>
            {
                logger.Info(
                    $"{command.Id} actor is taking a poison pill.");

                Self.Tell(PoisonPill.Instance);
            });
        }