Custom sensor: changing state API vs Service API

I’ve implemented a custom component and I needed to change the state from automation.
It is possible to change the state using the API (set_state) and debug console but this state is changed when the API self.async_schedule_update_ha_state() is called (it seems somthing else is changed and when this API is called the old internal state is updated back to the GUI)

So I’ve implemented a service API for that and it works (the code to update the state using service is here)

My questions:

  1. Is it possible to have a way to change the internal state without service API?
  2. In which case the set_state is used is it change only UI state