-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
Add Smart Meter B Route integration #123446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
It is my first time working with serial communication. I am wondering if:
Which road should I follow ? Asked in: https://discord.com/channels/330944238910963714/1271130001995071561 |
I am making an integration to be able to access Smart Meter data using a USB dongle to communicate via Echonet Lite over Wisun (I think it is only for the Japanese market). The library I am using is https://github.com/nbtk/momonga?tab=readme-ov-file#ログを有効にした例 It basically exposes 3 loggers for which I can set up the logging level and formater. Should I just suppress the logs or is there a way to align the log level of the integration with the library ? Log samples
Asked in https://discord.com/channels/330944238910963714/1271127972103065695 |
@joostlek Thanks for the review ! Oh, I have also a question about the brand to use, it is not a brand per see but a standard. Do I need to create a brand in the core project and add a logo (which logo) in the brand project ? |
A brand is only used for grouping integrations for a brand (like with switchbot switchbot cloud). In this case it could be like |
Hum... the device, id and password are actually at the HA device level, not at the HA integration level, I need to change the config flow |
I fixed the previous issues:
The current issue is that in the dev container, |
You probably need to expose the USB port to the devcontainer |
It is exposed, I updated the Dockerfile.dev to add:
.devcontainer/devcontainer.json to add
And in the terminal in the dev container, I can see:
ttyUSB0 is present and I can use it in Home Assistant to do running tests but the discovery does not work after I deleted the integration from the UI, even after a HA reboot. |
And the logs of the used library are still noisy :D
|
Failing tests are outside my scope:
|
The maintainer of Momonga added CI for releases. |
Note: Tests are failing in unrelated code |
Fixed issues |
def is_duplicate( | ||
hass: HomeAssistant, | ||
entry: ConfigEntry, | ||
) -> bool: | ||
"""Filter duplicate entries.""" | ||
existing_entries = hass.config_entries.async_entries( | ||
DOMAIN, include_disabled=False, include_ignore=False | ||
) | ||
entry_bid = entry.data[CONF_ID] | ||
for existing_entry in existing_entries: | ||
existing_entry_bid = existing_entry.data[CONF_ID] | ||
if ( | ||
existing_entry_bid == entry_bid | ||
and existing_entry.unique_id != entry.unique_id | ||
): | ||
_LOGGER.warning( | ||
"Duplicate entry found (Skipping): existing_entry.unique_id=%s, entry.unique_id=%s, entry.runtime_data.bid=%s", | ||
existing_entry.unique_id, | ||
entry.unique_id, | ||
entry_bid, | ||
) | ||
return True | ||
return False | ||
|
||
|
||
async def async_setup_entry(hass: HomeAssistant, entry: BRouteConfigEntry) -> bool: | ||
"""Set up Smart Meter B Route from a config entry.""" | ||
if is_duplicate(hass, entry): | ||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we do this here? If we check this during the config flow then there's no problem right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config flow does not check if the user input for bid is duplicated or not.
This was implemented following this comment: #123446 (comment)
if not self.context.get("unique_id"): | ||
await self.async_set_unique_id( | ||
_generate_unique_id(device), raise_on_progress=False | ||
) | ||
self._abort_if_unique_id_configured() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in theory the unique id wouldnt be set right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, not sure I understand the comment :D
It is set just above
homeassistant/components/smart_meter_b_route/quality_scale.yaml
Outdated
Show resolved
Hide resolved
], | ||
"quality_scale": "bronze", | ||
"requirements": ["pyserial==3.5", "momonga==0.1.4"], | ||
"usb": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The USB discovery is pretty broad, it will match any USB-serial chip produced by FTDI. Does the device have any USB descriptors populated? What does it look like with lsusb
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the result of lsusb
:
Bus 003 Device 002: ID 0403:6015 Future Technology Devices International, Ltd Bridge(I2C/SPI/UART/FIFO)
I am not knowledgeable about USB serials, if it can be more precise, I would be glad to restrict it.
They have multiple models: https://www.ratocsystems.com/products/wisun/usb-wisun/rs-wsuha/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked with @puddly and that means we can't discover this with too many false positives
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Contacted the USB device maker, maybe a suggestion will be made.
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
], | ||
"quality_scale": "bronze", | ||
"requirements": ["pyserial==3.5", "momonga==0.1.4"], | ||
"usb": [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked with @puddly and that means we can't discover this with too many false positives
Proposed change
This PR adds a new integration to use Bルートサービス (B Route Service) which uses Echonet Lite over Wi-Sun to provide readings from standard Smart Meters in Japan using a compatible serial device.
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: