Hi all.
I have a rpi running HA with these SW versions:
Core 2024.1.3
Supervisor 2024.01.1
Operating System 11.4
Frontend 20240104.0
I’m developing a firebase cloud messaging service custom component, and have successfully tested it with the devcontainer and core repository, as described here:
The core repository has a /components folder which includes notify.
On my rpi install that /components folder isn’t present. I have /custom_components folder for my HAC installed integrations.
My custom component is trying to import nofify like this:
from homeassistant.components.notify import (
ATTR_DATA,
ATTR_TITLE,
ATTR_TITLE_DEFAULT,
BaseNotificationService,
)
but because I don’t have the components path on my rpi it fails, where is worked on the devcontainer. I don’t understand why the 2 installs are different. Can anyone advise please, and is there a way to fix it?
Thanks @msp1974 and @nickrout for your help and comments. I’ve actually determined that the reason for the error was misleading and actually because I was trying to access a JSON file from one of my python files within the custom component. I know I’m in danger of changing the thread here but, how do you access a file within a custom component? I was doing this:
There are a number of ways to do this. As HA uses async, your are best using something like aiofiles. Example below from an api for the Wiser integration i help maintain. However, depending on the purpose of this file, you maybe better storing in config.yaml (as part of tour integrarion config) or store in config flow. If you are creating the file as a place to hold info as your integration runs, put it in config/.storage with all the others.
async def async_load_config(self):
if exists(self._config_file):
async with aiofiles.open(self._config_file, mode="r") as config_file:
try:
contents = await config_file.read()
if contents:
self._config = json.loads(contents)
except (
OSError,
EOFError,
TypeError,
AttributeError,
json.JSONDecodeError,
) as ex:
raise WiserExtraConfigError("Error loading extra config file") from ex
else:
await self.async_update_config("Info", "Version", "1.0.0")
return