Skip to content

Commit

Permalink
Merge pull request #270 from Snuffy2/Support-nonstandard-install-loca…
Browse files Browse the repository at this point in the history
…tions

Support nonstandard install locations
  • Loading branch information
Snuffy2 authored Apr 13, 2024
2 parents 4952b24 + 2c7cc17 commit f0027df
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions custom_components/places/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,7 @@
THROTTLE_INTERVAL = timedelta(seconds=600)
MIN_THROTTLE_INTERVAL = timedelta(seconds=10)
SCAN_INTERVAL = timedelta(seconds=30)
PLACES_JSON_FOLDER = os.path.join("custom_components", DOMAIN, "json_sensors")
try:
os.makedirs(PLACES_JSON_FOLDER, exist_ok=True)
except OSError as e:
_LOGGER.warning(f"OSError creating folder for JSON sensor files: {e}")
except Exception as e:
_LOGGER.warning(f"Unknown Exception creating folder for JSON sensor files: {e}")
PLACES_JSON_FOLDER = ""


async def async_setup_entry(
Expand All @@ -164,6 +158,15 @@ async def async_setup_entry(
async_add_entities,
) -> None:
"""Setup the sensor platform with a config_entry (config_flow)."""
global PLACES_JSON_FOLDER
PLACES_JSON_FOLDER = hass.config.path("custom_components", DOMAIN, "json_sensors")
_LOGGER.debug(f"json_sensors Location: {PLACES_JSON_FOLDER}")
try:
os.makedirs(PLACES_JSON_FOLDER, exist_ok=True)
except OSError as e:
_LOGGER.warning(f"OSError creating folder for JSON sensor files: {e}")
except Exception as e:
_LOGGER.warning(f"Unknown Exception creating folder for JSON sensor files: {e}")

# _LOGGER.debug(f"[aync_setup_entity] all entities: {hass.data.get(DOMAIN)}")

Expand All @@ -187,10 +190,8 @@ def __init__(self, hass, config, config_entry, name, unique_id):
self._attr_should_poll = True
_LOGGER.info(f"({name}) [Init] Places sensor: {name}")
_LOGGER.debug(f"({name}) [Init] System Locale: {locale.getlocale()}")
_LOGGER.debug(
f"({name}) [Init] System Locale Date Format: {
str(locale.nl_langinfo(locale.D_FMT))}"
)
_LOGGER.debug(f"({name}) [Init] System Locale Date Format: {
str(locale.nl_langinfo(locale.D_FMT))}")
_LOGGER.debug(f"({name}) [Init] HASS TimeZone: {hass.config.time_zone}")

self._warn_if_device_tracker_prob = False
Expand Down Expand Up @@ -257,10 +258,8 @@ def __init__(self, hass, config, config_entry, name, unique_id):
f"{DOMAIN}-{slugify(str(self.get_attr(CONF_UNIQUE_ID)))}.json",
)
self.set_attr(ATTR_DISPLAY_OPTIONS, self.get_attr(CONF_DISPLAY_OPTIONS))
_LOGGER.debug(
f"({self.get_attr(CONF_NAME)}) [Init] JSON Filename: {
self.get_attr(ATTR_JSON_FILENAME)}"
)
_LOGGER.debug(f"({self.get_attr(CONF_NAME)}) [Init] JSON Filename: {
self.get_attr(ATTR_JSON_FILENAME)}")

self._attr_native_value = None # Represents the state in SensorEntity
self.clear_attr(ATTR_NATIVE_VALUE)
Expand Down

0 comments on commit f0027df

Please sign in to comment.