private static PowerMovements SolarBatteryCharge(decimal solarPower, MomentEnergy moment)
 {
     if (moment.GridExportWatts >= 0 && moment.GridImportWatts == 0)
     {
         //var gridToBattery = 0;
         //var gridToHome = 0;
         var solarToBattery = Math.Min(solarPower, moment.BatteryCharge);
         var solarToGrid = moment.GridExportWatts;
         var solarToHome = solarPower - solarToBattery - solarToGrid;
         var powerState = solarToHome < 0 ? PowerMovements.PowerStateEnum.SolarBatteryChargeUnderpowered : PowerMovements.PowerStateEnum.SolarBatteryCharge;
         return new PowerMovements(
             solarToBattery: solarToBattery,
             solarToGrid: solarToGrid,
             solarToHome: solarToHome,
             gridToHome: 0,
             powerState: powerState,
             solarPower: solarPower);
     }
     else // grid import > 0
     {
         PowerMovements? result = null;
         if (solarPower > moment.BatteryCharge)
         {
             var solarToBattery = moment.BatteryCharge;
             var solarToHome = solarPower - solarToBattery;
             var solarToGrid = 0;
             var gridToHome = moment.GridImportWatts;
             result = new PowerMovements(
                 solarToBattery: solarToBattery,
                 solarToGrid: solarToGrid,
                 solarToHome: solarToHome,
                 gridToHome: gridToHome,
                 powerState: PowerMovements.PowerStateEnum.SolarBatteryCharge,
                 solarPower: solarPower
                 );
         }
         else // solar <= battery charge
         {
             var solarToBattery = solarPower;
             var solarToHome = 0;
             var solarToGrid = 0;
             var gridToBattery = moment.BatteryCharge - solarToBattery;
             var gridToHome = moment.GridImportWatts - gridToBattery;
             result = new PowerMovements(
                 solarToBattery: solarToBattery,
                 solarToHome: solarToHome,
                 solarToGrid: solarToGrid,
                 gridToBattery: gridToBattery,
                 gridToHome: gridToHome,
                 powerState: PowerMovements.PowerStateEnum.SolarBatteryCharge,
                 solarPower: solarPower
                 );
         }
         CheckIfBatteryCausedGridImport(result);
         return result;
     }
 }
        private static void CheckIfBatteryCausedGridImport(PowerMovements result)
        {
            if (result.SolarToBattery > 0 && result.GridToHome > 0)
            {
                var powerToMove = Math.Min(result.SolarToBattery, result.GridToHome);
                result.GridToHome -= powerToMove;
                result.GridToBattery += powerToMove;

                result.SolarToBattery -= powerToMove;
                result.SolarToHome += powerToMove;
            }
        }