Help with adding services to Vera lock

I am trying to add services to Vera lock to add and Delete door codes,
I have the code untill this

How I register the service


async def async_setup_entry(
    hass: HomeAssistant,
    entry: ConfigEntry,
    async_add_entities: AddEntitiesCallback,
) -> None:
    """Set up the sensor config entry."""
    controller_data = get_controller_data(hass, entry)
    async_add_entities(
        [
            VeraLock(device, controller_data)
            for device in controller_data.devices.get(PLATFORM_DOMAIN)
        ],
        True,
    )
    platform = async_get_current_platform()
    platform.async_register_entity_service(
        "setpin",
        SET_PIN_SCHEMA,
        set_new_pin
    )
    platform.async_register_entity_service(
        "clearpin",
        CLEAR_PIN_SCHEMA,
        clear_slot_pin
    )

functions tied to the service

class VeraLock(VeraDevice[veraApi.VeraLock], LockEntity):
    """Representation of a Vera lock."""

    def __init__(
        self, vera_device: veraApi.VeraLock, controller_data: ControllerData
    ) -> None:
        """Initialize the Vera device."""
        self._state = None
        self._cmd_status = None
        VeraDevice.__init__(self, vera_device, controller_data)
        self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)

    def lock(self, **kwargs: Any) -> None:
        """Lock the device."""
        self.vera_device.lock()
        self._state = STATE_LOCKED

    def unlock(self, **kwargs: Any) -> None:
        """Unlock the device."""
        self.vera_device.unlock()
        self._state = STATE_UNLOCKED
    
    def set_new_pin(self, **kwargs: Any) -> None:
        """Set pin on the device."""
        _LOGGER.warning("calling veralock.set_new_pin to add %s with pin %s", kwargs[CONF_NAME], kwargs[CONF_PIN])
        result = self.vera_device.set_new_pin(name = kwargs[CONF_NAME], pin = kwargs[CONF_PIN])
        if result.status_code == HTTP_OK:
            self._cmd_status = "Removed"
        else:
            self._cmd_status = result.text
            _LOGGER.error("Failed to call %s: %s", "veralock.set_new_pin", result.text)
            raise ValueError(result.text)
    
    def clear_slot_pin(self, **kwargs: Any) -> None:
        """Clear pin on the device."""
        _LOGGER.warning("calling veralock.clearpin to clear_slot_pin %s", kwargs["slot"])
        result = self.vera_device.clear_slot_pin(slot = kwargs["slot"])
        if result.status_code == HTTP_OK:
            self._cmd_status = "Removed"
        else:
            self._cmd_status = result.text
            _LOGGER.error("Failed to call %s: %s", "veralock.clear_slot_pin", result.text)
            raise ValueError(result.text)

Am able to get the service registered and I can see home assistant firing the event

2021-10-08 17:24:40 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=vera, service=clearpin, service_data=slot=244>

The function in the lock.py (set_new_pin/clear_slot_pin) file is not getting executed

Can somebody help me please

Merged pull request to support this feature under pyvera, released as version 0.3.14

I tried moving my registration into the init function still no go

class VeraLock(VeraDevice[veraApi.VeraLock], LockEntity):
    """Representation of a Vera lock."""

    def __init__(
        self, vera_device: veraApi.VeraLock, controller_data: ControllerData
    ) -> None:
        """Initialize the Vera device."""
        self._state = None
        self._cmd_status = None
        VeraDevice.__init__(self, vera_device, controller_data)
        self.entity_id = ENTITY_ID_FORMAT.format(self.vera_id)
        platform = async_get_current_platform()
        platform.async_register_entity_service(
            name = "setpin",
            schema = SET_PIN_SCHEMA,
            func = self.set_new_pin
        )
        platform.async_register_entity_service(
            name = "clearpin",
            schema = CLEAR_PIN_SCHEMA,
            func = self.clear_slot_pin
        )


    def lock(self, **kwargs: Any) -> None:
        """Lock the device."""
        self.vera_device.lock()
        self._state = STATE_LOCKED

    def unlock(self, **kwargs: Any) -> None:
        """Unlock the device."""
        self.vera_device.unlock()
        self._state = STATE_UNLOCKED
    
    def set_new_pin(self, **kwargs: Any) -> None:
        """Set pin on the device."""
        _LOGGER.warning("calling veralock.set_new_pin to add %s with pin %s", kwargs[CONF_NAME], kwargs[CONF_PIN])
        result = self.vera_device.set_new_pin(name = kwargs[CONF_NAME], pin = kwargs[CONF_PIN])
        if result.status_code == HTTP_OK:
            self._cmd_status = "Removed"
        else:
            self._cmd_status = result.text
            _LOGGER.error("Failed to call %s: %s", "veralock.set_new_pin", result.text)
            raise ValueError(result.text)
    
    def clear_slot_pin(self, **kwargs: Any) -> None:
        """Clear pin on the device."""
        _LOGGER.warning("calling veralock.clearpin to clear_slot_pin %s", kwargs["slot"])
        result = self.vera_device.clear_slot_pin(slot = kwargs["slot"])
        if result.status_code == HTTP_OK:
            self._cmd_status = "Removed"
        else:
            self._cmd_status = result.text
            _LOGGER.error("Failed to call %s: %s", "veralock.clear_slot_pin", result.text)
            raise ValueError(result.text)

If anyone can point what I am doing wrong will be very helpful

Hey @sresam89, thanks for looking into this: it’s something that I’d find useful too! I found https://github.com/home-assistant/core/pull/60310 and wanted to see if everything is working in your testing or if you still needed any other help! If everything is working I’d be happy to clean up that Pull Request to help get this functionality into an upcoming HA release.