Updating all lights in platform in one request

I’ve created a custom system to control the lights in my house. I have it working using the example light platform, but it is inefficient. I send back the status of all lights in response to a request, but it looks like the framework sends status updates request for each light. Is there anyway to handle this in my custom platform so that I can update all the lights with one request? Similarly I could trigger multiple lights at once rather than individually if I had notice at the platform level of all lights being triggered for a group.

You should be abl to put the lights into a group and then issue the command to the group.

Sure I can group stuff (I have my lights grouped and working), but where in the platform do I handle a turn_off/on for group vs. at the light device level?

  action:
    service: homeassistant.turn_on
    entity_id: group.living_room

I can configure it just fine, I’m not asking how to do that. homeassistant.turn_on is going to send SEPARATE requests to every single individual entity, and I’d like to only send one request from my platform to my custom hub. hass also periodically polls the states of lights, but it does this individually and I’d like to only send one request to my hub.

Looking through other components, I’m guessing I need to emulate what the hue light platform does in storing up commands and only sending stuff to the hub in a throttled handler. Can anyone confirm this is the proper approach?

My current (development, not robust code) is as follows. The response to every query is a json dictionary of the current state of all the lights, hence my desire to only send it once when the framework polls, rather than once for every light:

def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup the Awesome Light platform."""

# Assign configuration variables. The configuration check takes care they are
# present. 
host = config.get(CONF_HOST)
response = urlopen('http://' + host)
data = json.load(response)
response.close()
# Setup connection with devices/cloud
# Connect to service on beaglebone

# Add devices
add_devices(TouchplateLight(idx+1, name, data[str(idx+1)], host) for idx, name in enumerate(LIGHTS))

class TouchplateLight(Light):
“”“Representation of an Touchplate Light.”""

def __init__(self, idx, name, state, host):
    """Initialize an TouchplateLight."""
    self._name = name
    self._idx = idx
    self._host = host
    self._state = state == 0
    
@property
def name(self):
    """Return the display name of this light."""
    return self._name


@property
def is_on(self):
    """Return true if light is on."""
    return self._state;

def turn_on(self, **kwargs):
    """Instruct the light to turn on."""
    # Send message to trigger relay
    response = urlopen('http://%s?Switch%d=on' %(self._host, self._idx))
    response.close()

def turn_off(self, **kwargs):
    """Instruct the light to turn off."""
    # Send message to trigger relay
    response = urlopen('http://%s?Switch%d=off' %(self._host, self._idx))
    response.close()

def update(self):
    """Fetch new state data for this light.

    This is the only method that should fetch new data for Home Assistant.
    """
    # Send message to query current state
    response = urlopen('http://' + self._host)
    data = json.load(response)
    self._state = data[str(self._idx)] == 0
    response.close()