Skip to content

Commit

Permalink
choose better method names
Browse files Browse the repository at this point in the history
  • Loading branch information
mtyszkiewicz committed Oct 26, 2024
1 parent 5350b18 commit cbade90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions onkyo-api/internal/pkg/eiscp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ func NewEISCPClient(host, port string) (*EISCPClient, error) {
Conn: conn,
responseQueue: make(chan string, 100),
}
go client.readResponses()
go client.listen()
return client, nil
}

// Constatnly puts incoming data into responseQueue
func (c *EISCPClient) readResponses() {
func (c *EISCPClient) listen() {
buf := make([]byte, 1024)
for {
n, err := c.Conn.Read(buf)
Expand Down Expand Up @@ -128,7 +128,7 @@ func (c *EISCPClient) SetInputSelector(input string) error {
return c.sendCommand("SLI" + code)
}

func (c *EISCPClient) QueryCurrentInput() (string, error) {
func (c *EISCPClient) QueryInputSelector() (string, error) {
response, err := c.sendReceiveCommand("SLIQSTN")
if err != nil {
return "", err
Expand All @@ -144,7 +144,7 @@ func (c *EISCPClient) QueryCurrentInput() (string, error) {
return name, nil
}

func (c *EISCPClient) QueryCurrentVolume() (int, error) {
func (c *EISCPClient) QueryVolume() (int, error) {
response, err := c.sendReceiveCommand("MVLQSTN")
if err != nil {
return 0, err
Expand All @@ -160,7 +160,7 @@ func (c *EISCPClient) QueryCurrentVolume() (int, error) {
return int(result), nil
}

func (c *EISCPClient) QueryCurrentSubwooferLevel() (int, error) {
func (c *EISCPClient) QuerySubwooferLevel() (int, error) {
response, err := c.sendReceiveCommand("SWLQSTN")
if err != nil {
return 0, err
Expand Down
12 changes: 6 additions & 6 deletions onkyo-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (s *Server) powerOff(w http.ResponseWriter, r *http.Request) {

// Volume handlers
func (s *Server) getVolume(w http.ResponseWriter, r *http.Request) {
volume, err := s.client.QueryCurrentVolume()
volume, err := s.client.QueryVolume()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down Expand Up @@ -161,7 +161,7 @@ func (s *Server) setVolume(w http.ResponseWriter, r *http.Request) {

// Subwoofer handlers
func (s *Server) getSubwoofer(w http.ResponseWriter, r *http.Request) {
subwoofer, err := s.client.QueryCurrentSubwooferLevel()
subwoofer, err := s.client.QuerySubwooferLevel()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down Expand Up @@ -189,7 +189,7 @@ func (s *Server) setSubwoofer(w http.ResponseWriter, r *http.Request) {

// Input handlers
func (s *Server) getInput(w http.ResponseWriter, r *http.Request) {
input, err := s.client.QueryCurrentInput()
input, err := s.client.QueryInputSelector()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -212,17 +212,17 @@ func (s *Server) setInput(w http.ResponseWriter, r *http.Request) {

// Profile handlers
func (s *Server) getProfile(w http.ResponseWriter, r *http.Request) {
currentInput, err := s.client.QueryCurrentInput()
currentInput, err := s.client.QueryInputSelector()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
currentVolume, err := s.client.QueryCurrentVolume()
currentVolume, err := s.client.QueryVolume()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
currentSubwoofer, err := s.client.QueryCurrentSubwooferLevel()
currentSubwoofer, err := s.client.QuerySubwooferLevel()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down

0 comments on commit cbade90

Please sign in to comment.