I don't think it's immoral to keep livestock, I'm questioning whether the situations are analogous in an ethical sense.
Yeah, the animal is not autonomous. Do animals understand autonomy? Can they tell the difference? Maybe whales in capyivity can, but they are used to roaming the vast oceans. I think cattle would be perfectly happy in such an environment. Anthropomorphizing them is not helpful.
None of that is an argument that it is necessarily unethical or immoral to take milk from an animal.
Repeating the point: to me, the ethics of collecting milk from autonomous creatures that willingly give it are a separate thing from the ethics of taking milk from creatures that do not have autonomy.
You are, actually. You're extending a human concept, with human morals and human judgement, to a non-human animal. It is not known whether non-human animals understand the concept of autonomy, let alone value it.
Given that many humans do not understand autonomy, I doubt that any non-human animal does.
But that's all beside the point. With these automated machines, if the animal chooses not to give milk, then no milk is collected from the animal. Since the animals do choose to give milk, it can hardly be argued that they are coerced in any way.
I think dairy also applies. Yes, lots of dairy operations in business today are cruel. But they don't have to be.
There are dairy operations now that let the cattle decide when to be milked. The machines are fully automatic. The cattle need not be separated from their calves, either.
With all of those systems in place, there is no real ethical difference between the dairy operation and a human mother using a breast pump and donating the excess to a milk bank.