dnd 5e – Can a Charmed Ranger Beast Master’s Primal Companion attack the Charmer?

If a Ranger should have a Primal Companion, can the Charmed Ranger to their Primal Companion to attack the Charmer?

I ask this because it is specifically stated that a Ranger must use their Bonus Action (or one of their Attacks) to have said Primal Companion take the Attack option, which would count as a harmful effect against the Charmer, so I’m wondering if that’s the correct interpretation of how to take the dynamics of the situation.