Skip to content
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

Add Starlink Integration #77091

Merged
merged 36 commits into from Jan 7, 2023

Conversation

boswelja
Copy link
Contributor

@boswelja boswelja commented Aug 21, 2022

Proposed change

Add support for loading data from a Starlink terminal. I have tested the integration with my square Dishy & new terminal, and the underlying python library starlink-grpc-core has been used for both (new) square Dishy and (old) round Dishy.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

@project-bot project-bot bot added this to Needs review in Dev Aug 21, 2022
@homeassistant
Copy link
Contributor

Hi @boswelja,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

@boswelja
Copy link
Contributor Author

I am working on tests now, I'd appreciate review on the code that's there in case there's something significant I've missed :)

frenck
frenck previously requested changes Aug 21, 2022
Copy link
Member

@frenck frenck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there @boswelja 👋

Some initial comments to help on getting this PR moving 👍

../Frenck

homeassistant/components/starlink/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/starlink/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/starlink/__init__.py Outdated Show resolved Hide resolved
homeassistant/components/starlink/binary_sensor.py Outdated Show resolved Hide resolved
homeassistant/components/starlink/config_flow.py Outdated Show resolved Hide resolved
homeassistant/components/starlink/coordinator.py Outdated Show resolved Hide resolved
homeassistant/components/starlink/dish_status.py Outdated Show resolved Hide resolved
homeassistant/components/starlink/strings.json Outdated Show resolved Hide resolved
homeassistant/components/starlink/strings.json Outdated Show resolved Hide resolved
Dev automation moved this from Needs review to Review in progress Aug 21, 2022
homeassistant/components/starlink/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/starlink/sensor.py Outdated Show resolved Hide resolved
homeassistant/components/starlink/sensor.py Outdated Show resolved Hide resolved
@boswelja boswelja force-pushed the feature/starlink-integration branch from aa5a80a to c45cebb Compare August 25, 2022 12:16
@boswelja boswelja requested review from frenck and avee87 and removed request for frenck August 25, 2022 13:17
@boswelja boswelja requested review from frenck and avee87 and removed request for frenck August 26, 2022 11:02
@boswelja
Copy link
Contributor Author

If we're happy with the state of the config flow and sensors, I will begin writing some tests

Copy link
Contributor

@avee87 avee87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sensors look good to me - see some comments though.
Not sure about config flow, I don't know much about it.

homeassistant/components/starlink/entity.py Show resolved Hide resolved
homeassistant/components/starlink/entity.py Outdated Show resolved Hide resolved
homeassistant/components/starlink/coordinator.py Outdated Show resolved Hide resolved
homeassistant/components/starlink/coordinator.py Outdated Show resolved Hide resolved
@bdraco
Copy link
Member

bdraco commented Jan 6, 2023

Looks like there is a test failure otherwise this looks good

I'll factory reset mine this weekend and try it out when I can afford to have it offline

@boswelja
Copy link
Contributor Author

boswelja commented Jan 6, 2023

Thanks for your time! I have fixed the tests locally, CI should run fine now
Edit: and of course checks fail because I said that

@bdraco bdraco dismissed frenck’s stale review January 7, 2023 19:49

Dismissing stale review as it appears all comments have been addressed

@bdraco
Copy link
Member

bdraco commented Jan 7, 2023

Factory reset was a bit of a PITA but it works great!

2023-01-07 19:42:08.642 INFO (SyncWorker_6) [homeassistant.loader] Loaded starlink from homeassistant.components.starlink
2023-01-07 20:10:35.887 INFO (MainThread) [homeassistant.setup] Setting up starlink
2023-01-07 20:10:35.888 INFO (MainThread) [homeassistant.setup] Setup of domain starlink took 0.0 seconds
2023-01-07 20:10:35.907 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.starlink
2023-01-07 20:10:35.908 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.starlink entity: sensor.starlink_ping
2023-01-07 20:10:35.909 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.starlink entity: sensor.starlink_azimuth
2023-01-07 20:10:35.909 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.starlink entity: sensor.starlink_elevation
2023-01-07 20:10:35.910 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.starlink entity: sensor.starlink_uplink_throughput
2023-01-07 20:10:35.910 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.starlink entity: sensor.starlink_downlink_throughput
2023-01-07 20:10:35.911 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new sensor.starlink entity: sensor.starlink_last_boot_time

Screenshot 2023-01-07 at 10 10 53 AM

Dev automation moved this from Review in progress to Reviewer approved Jan 7, 2023
@bdraco bdraco merged commit 3ad4caa into home-assistant:dev Jan 7, 2023
Dev automation moved this from Reviewer approved to Done Jan 7, 2023
@bdraco
Copy link
Member

bdraco commented Jan 7, 2023

Thanks @boswelja

@boswelja boswelja deleted the feature/starlink-integration branch January 7, 2023 23:13
@lyricnz
Copy link
Contributor

lyricnz commented Jan 8, 2023

Works for me (old dishy, no router). Glad polling is 5s and not 1s. Is bits/sec a good choice? Most people will think in mbit/sec

image

@rossfisherkc
Copy link

rossfisherkc commented Jan 8, 2023

There's quite a few sensors that could be added, imo:
Screenshot 2023-01-07 at 8 17 30 PM
(from the other integration)

I rely on the location, for example, to set my HA home location.
image

Having access to, and tracking all of the metrics is pretty swank. Maybe some can be added to this integration?

@lyricnz
Copy link
Contributor

lyricnz commented Jan 8, 2023

Agree. I assume this merge is just the first step towards parity with the third-party repo https://github.com/archerne/hastarlink

https://community.home-assistant.io/t/starlink-dish-and-network-stats/297155

@rossfisherkc
Copy link

Agree. I assume this merge is just the first step towards parity with the third-party repo https://github.com/archerne/hastarlink

Right! Getting things merged into mainline is hard enough, not complaining ;)

Great work getting this merged!

@boswelja
Copy link
Contributor Author

boswelja commented Jan 8, 2023

Most people will think in mbit/sec

That's what I had it at, but we're not supposed to be modifying data from the Py library/API

There's quite a few sensors that could be added

Guidelines say we can only add one platform at a time. You are showing binary sensors and buttons. I have a PR up for binary sensors now: #85409
I'll need to poke around in the response data to find fields for the remaining sensors (ping drop rate, lat/long etc), but again one thing at a time, I'd like to get binary sensors and buttons going first 🙂

@lyricnz
Copy link
Contributor

lyricnz commented Jan 8, 2023

Is scaling/unit conversion really modifying?

@boswelja
Copy link
Contributor Author

boswelja commented Jan 8, 2023

Considering I was asked to stop doing that, yes

Edit: You're welcome to read the PR review comments, it's all covered there

@github-actions github-actions bot locked and limited conversation to collaborators Jan 9, 2023
Copy link
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address the comments in a new PR. Thanks!

icon="mdi:clock",
device_class=SensorDeviceClass.TIMESTAMP,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda data: datetime.now().astimezone()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use our dt utils as far as possible.

def now(time_zone: dt.tzinfo | None = None) -> dt.datetime:
"""Get now in specified time zone."""

device_class=SensorDeviceClass.TIMESTAMP,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda data: datetime.now().astimezone()
- timedelta(seconds=data["uptime"]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this calculation stable so that the timestamp state doesn't update spammily?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't noticed any issues, but I also haven't run this for longer than maybe a minute at a time. I can leave it polling for a while and see if you suspect there might be an issue?

@home-assistant home-assistant unlocked this conversation Jan 16, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jan 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Dev
  
Done
Development

Successfully merging this pull request may close these issues.

None yet