'Set the state of the switch.
This sets the state of the switch. If send_code is set to True, then
it will call the pilight.send service to actually send the codes
to the pilight daemon.'

def set_state(self, turn_on, send_code=True):

    if send_code:
        if turn_on:
            self._hass.services.call(pilight.DOMAIN, pilight.SERVICE_NAME, self._code_on, blocking=True)
        else:
            self._hass.services.call(pilight.DOMAIN, pilight.SERVICE_NAME, self._code_off, blocking=True)
    self._state = turn_on
    self.schedule_update_ha_state()
