Skip to content

Commit

Permalink
Update sensor.py
Browse files Browse the repository at this point in the history
Fix Block Loop Detected warning in HA log
  • Loading branch information
rt400 authored Jul 5, 2024
1 parent 57cb6b9 commit f2a4106
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions custom_components/school_holidays/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Document will come soon...
"""
import logging
import codecs
import aiofiles
import datetime
import json
import pathlib
Expand All @@ -17,7 +17,7 @@
from homeassistant.helpers.entity import async_generate_entity_id
from homeassistant.components.sensor import ENTITY_ID_FORMAT

__version__ = '2.0.3'
__version__ = '2.1.0'

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -120,9 +120,10 @@ async def create_db_file(self):
html = await fetch(session,
'https://raw.githubusercontent.com/rt400/School-Vacation/master/data.json')
data = json.loads(html)
with codecs.open(self.config_path + 'school_data.json', 'w', encoding='utf-8') as outfile:
json.dump(data, outfile, skipkeys=False, ensure_ascii=False,
indent=4, separators=None, default=None, sort_keys=True)
async with aiofiles.open(self.config_path + 'school_data.json', 'w', encoding='utf-8') as outfile:
temp_data = json.dumps(data, skipkeys=False, ensure_ascii=False, indent=4, separators=None,
default=None, sort_keys=True)
await outfile.write(temp_data)
self.school_db = data
except Exception as e:
_LOGGER.error(e)
Expand Down

0 comments on commit f2a4106

Please sign in to comment.