Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Dec 25, 2018
1 parent 9297ba5 commit 6d7e849
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions detective/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
from . import config, functions


# Entities who'se existence we should ignore
ignore_entities = set([
# Ignore because it looks numeric but it is actually the icon to show
'sensor.yr_symbol',
])


def db_from_hass_config(path=None, **kwargs):
"""Initialize a database from HASS config."""
if path is None:
Expand Down Expand Up @@ -95,6 +102,9 @@ def fetch_entities(self):
domains = set()

for [entity] in response:
if entity in ignore_entities:
continue

domain = entity.split('.')[0]
domains.add(domain)
entities.setdefault(domain, []).append(entity)
Expand Down Expand Up @@ -126,12 +136,12 @@ def fetch_data_by_list(self, entities: List[str], limit=50000):
"""
SELECT entity_id, state, last_changed
FROM states
WHERE entity_id in {}
WHERE entity_id in ({})
AND NOT state='unknown'
ORDER BY last_changed DESC
LIMIT {}
""".format(
tuple(entities), limit
",".join(entities), limit
)
)

Expand All @@ -154,17 +164,20 @@ def fetch_data_by_list(self, entities: List[str], limit=50000):

def fetch_all_data(self, limit=50000):
"""
Fetch data for all enetites.
Fetch data for all entities.
"""
# Query text
query = text(
"""
SELECT domain, entity_id, state, last_changed
FROM states
WHERE NOT state='unknown'
WHERE
state NOT IN ('unknown', 'unavailable')
AND entity_ID not in ({})
ORDER BY last_changed DESC
LIMIT {}
""".format(
",".join(ignore_entities),
limit
)
)
Expand Down

0 comments on commit 6d7e849

Please sign in to comment.