@andrewdolphin I’ve looked at the example that you have reference, and that works even less then the “old” way of doing it.
Here is what I came up with based on the example you gave me.
async def async_setup(hass, config):
"""Setup Airscape component."""
component = hass.data[DOMAIN] = EntityComponent(
_LOGGER, DOMAIN, hass, SCAN_INTERVAL
)
component.async_setup(config)
# for conf in config["fan"]:
# if conf["platform"] == DOMAIN:
# hass.data[DOMAIN] = {
# "host": conf.get("host"),
# "name": conf.get("name"),
# "timeout": conf.get("timeout"),
# "minimum": conf.get("minimum"),
# }
hass.async_create_task(async_load_platform(hass, "fan", DOMAIN, {}, config))
component.async_register_entity_service("speed_up", None, service_speed_up)
component.async_register_entity_service("slow_down", None, "slow_down")
# Return boolean to indicate that initialization was successfully.
return True
def service_speed_up(entity, service: ServiceDataType) -> None:
_LOGGER.debug("Calling Service service_speed_up")
if entity is None:
_LOGGER.debug("Service service_speed up entity is None")
entity.speed_up()
There isn’t any evidence that those service handlers are ever called (no debug log entries). I did notice in the example that the function call for the service was either a string literal or a function name. Based on the example I interpreted that to mean, a string literal would call the defined function of the entity class, and a function reference would call the function defined in the init. I tested both and neither is ever called. The platform does get loaded, I can control it from the UI. And the services do get registered, I can see them in the developer panel and the call service button “works” but nothing happens. I have to admit I am a little lost here. The example custom service is not very complete. And it only manipulates the state of an entity.
I also tried the “old” method:
def setup(hass, config):
"""Setup Airscape Fan Component."""
def service_speed_up(call):
"""Handle speed up service call."""
_LOGGER.debug("Calling service_speed_up")
# How do I reference to the entity to call
# speed_up member
def service_slow_down(call):
"""Handle speed up service call."""
_LOGGER.debug("Calling service_speed_up")
# How do I reference to the entity to call
# slow_down member
for conf in config["fan"]:
if conf["platform"] == DOMAIN:
hass.data[DOMAIN] = {
"host": conf.get("host"),
"name": conf.get("name"),
"timeout": conf.get("timeout"),
"minimum": conf.get("minimum"),
}
hass.helpers.discovery.load_platform("fan", DOMAIN, {}, config)
hass.services.register(DOMAIN, "speed_up", service_slow_down)
hass.services.register(DOMAIN, "slow_down", service_speed_up)
return True
But the question with this style is how do I get access to the entity object to call one of its methods? At least using this style of service handler I do actually get the handler executed. I do see entries in debug.