def fetch_entities(self):
        """Fetch entities for which we have data."""
        query = text(
            """
            SELECT entity_id
            FROM states
            GROUP BY entity_id
            """
        )
        response = self.perform_query(query)

        # Parse the domains from the entities.
        entities = {}
        domains = set()

        for [entity] in response:
            domain = entity.split(".")[0]
            domains.add(domain)
            entities.setdefault(domain, []).append(entity)

        self._domains = list(domains)
        self._entities = entities
        print("There are {} entities with data".format(len(entities)))
Fetch entities for which we have data.