def _add_gateway_to_schema(xiaomi, schema):
    'Extend a voluptuous schema with a gateway validator.'

    def gateway(sid):
        'Convert sid to a gateway.'
        sid = str(sid).replace(':', '').lower()
        for gateway in xiaomi.gateways.values():
            if (gateway.sid == sid):
                return gateway
        raise vol.Invalid('Unknown gateway sid {}'.format(sid))
    gateways = list(xiaomi.gateways.values())
    kwargs = {}
    if (len(gateways) == 1):
        kwargs['default'] = gateways[0]
    return schema.extend({vol.Required(ATTR_GW_MAC, **kwargs): gateway})
Extend a voluptuous schema with a gateway validator.
def _add_gateway_to_schema(xiaomi, schema):
    

    def gateway(sid):
        'Convert sid to a gateway.'
        sid = str(sid).replace(':', ).lower()
        for gateway in xiaomi.gateways.values():
            if (gateway.sid == sid):
                return gateway
        raise vol.Invalid('Unknown gateway sid {}'.format(sid))
    gateways = list(xiaomi.gateways.values())
    kwargs = {}
    if (len(gateways) == 1):
        kwargs['default'] = gateways[0]
    return schema.extend({vol.Required(ATTR_GW_MAC, **kwargs): gateway})