Diagnostics of batteries and energy storage