text: """Support for binary (door/window/smoke/leak) sensors."""
  from datetime import timedelta
  import logging
  import async_timeout
  
  import voluptuous as vol
  from homeassistant.components.binary_sensor import PLATFORM_SCHEMA, BinarySensorEntity
  
  from homeassistant.const import (
      CONF_HOST,
      CONF_TOKEN
  )
  
  import homeassistant.helpers.config_validation as cv
  from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
  
  from .const import DOMAIN
  
  _LOGGER = logging.getLogger(__name__)
  
  PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
      {
          vol.Required(CONF_HOST): cv.string,
          vol.Required(CONF_TOKEN): cv.string,
      }
  )
  
  
  async def async_setup_entry(hass, config_entry, async_add_entities):
      """Set up Salus binary sensors from a config entry."""
  
      gateway = hass.data[DOMAIN][config_entry.entry_id]
  
      async def async_update_data():
          """Fetch data from API endpoint.
  
          This is the place to pre-process the data to lookup tables
          so entities can quickly look up their data.
          """
          async with async_timeout.timeout(10):
              await gateway.poll_status()
              return gateway.get_binary_sensor_devices()
  
      coordinator = DataUpdateCoordinator(
          hass,
          _LOGGER,
          # Name of the data. For logging purposes.
          name="sensor",
          update_method=async_update_data,
          # Polling interval. Will only be polled if there are subscribers.
          update_interval=timedelta(seconds=30),
      )
  
      # Fetch initial data so we have data when entities subscribe
      await coordinator.async_refresh()
  
      async_add_entities(SalusBinarySensor(coordinator, idx, gateway) for idx
                         in coordinator.data)
  
  
  async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
      """Set up the binary_sensor platform."""
      pass
  
  
  class SalusBinarySensor(BinarySensorEntity):
      """Representation of a binary sensor."""
  
      def __init__(self, coordinator, idx, gateway):
          """Initialize the sensor."""
          self._coordinator = coordinator
          self._idx = idx
          self._gateway = gateway
  
      async def async_update(self):
          """Update the entity.
          Only used by the generic entity update service.
          """
          await self._coordinator.async_request_refresh()
  
      async def async_added_to_hass(self):
          """When entity is added to hass."""
          self.async_on_remove(
              self._coordinator.async_add_listener(self.async_write_ha_state)
          )
  
      @property
      def available(self):
          """Return if entity is available."""
          return self._coordinator.data.get(self._idx).available
  
      @property
      def device_info(self):
          """Return the device info."""
          return {
              "name": self._coordinator.data.get(self._idx).name,
              "identifiers": {("salus", self._coordinator.data.get(self._idx).unique_id)},
              "manufacturer": self._coordinator.data.get(self._idx).manufacturer,
              "model": self._coordinator.data.get(self._idx).model,
              "sw_version": self._coordinator.data.get(self._idx).sw_version
          }
  
      @property
      def unique_id(self):
          """Return the unique id."""
          return self._coordinator.data.get(self._idx).unique_id
  
      @property
      def should_poll(self):
          """No need to poll. Coordinator notifies entity of updates."""
          return False
  
      @property
      def name(self):
          """Return the name of the sensor."""
          return self._coordinator.data.get(self._idx).name
  
      @property
      def is_on(self):
          """Return the state of the sensor."""
          return self._coordinator.data.get(self._idx).is_on
  
      @property
      def device_class(self):
          """Return the device class of the sensor."""
          return self._coordinator.data.get(self._idx).device_class
  